-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide context for NestedRules (#51160)
- Loading branch information
Showing
3 changed files
with
14 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -179,15 +179,16 @@ public function testExplodeGeneratesNestedRules() | |
{ | ||
$parser = (new ValidationRuleParser([ | ||
'users' => [ | ||
['name' => 'Taylor Otwell'], | ||
['name' => 'Taylor Otwell', 'email' => '[email protected]'], | ||
], | ||
])); | ||
|
||
$results = $parser->explode([ | ||
'users.*.name' => Rule::forEach(function ($value, $attribute, $data) { | ||
'users.*.name' => Rule::forEach(function ($value, $attribute, $data, $context) { | ||
$this->assertSame('Taylor Otwell', $value); | ||
$this->assertSame('users.0.name', $attribute); | ||
$this->assertEquals($data['users.0.name'], 'Taylor Otwell'); | ||
$this->assertEquals(['name' => 'Taylor Otwell', 'email' => '[email protected]'], $context); | ||
|
||
return [Rule::requiredIf(true)]; | ||
}), | ||
|
@@ -201,13 +202,15 @@ public function testExplodeGeneratesNestedRulesForNonNestedData() | |
{ | ||
$parser = (new ValidationRuleParser([ | ||
'name' => 'Taylor Otwell', | ||
'email' => '[email protected]', | ||
])); | ||
|
||
$results = $parser->explode([ | ||
'name' => Rule::forEach(function ($value, $attribute, $data = null) { | ||
'name' => Rule::forEach(function ($value, $attribute, $data = null, $context) { | ||
$this->assertSame('Taylor Otwell', $value); | ||
$this->assertSame('name', $attribute); | ||
$this->assertEquals(['name' => 'Taylor Otwell'], $data); | ||
$this->assertEquals(['name' => 'Taylor Otwell', 'email' => '[email protected]'], $data); | ||
$this->assertEquals(['name' => 'Taylor Otwell', 'email' => '[email protected]'], $context); | ||
|
||
return 'required'; | ||
}), | ||
|