-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9103 from kenjis/fix-validation-differs-matches
fix: Validation rule `differs`/`matches` with dot array
- Loading branch information
Showing
2 changed files
with
100 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -336,6 +336,50 @@ public function testMatchesNested(array $data, bool $expected): void | |
$this->assertSame($expected, $this->validation->run($data)); | ||
} | ||
|
||
public function testMatchesWithDotArrayPass(): void | ||
{ | ||
$rules = [ | ||
'name' => 'permit_empty', | ||
'emailAddress' => 'permit_empty|valid_email', | ||
'alias.*' => 'permit_empty|matches[name]', | ||
]; | ||
$this->validation->setRules($rules); | ||
|
||
$data = [ | ||
'name' => 'Princess Peach', | ||
'emailAddress' => '[email protected]', | ||
'alias' => [ | ||
'Princess Peach', | ||
'Princess Peach', | ||
], | ||
]; | ||
$this->assertTrue($this->validation->run($data)); | ||
} | ||
|
||
public function testMatchesWithDotArrayFail(): void | ||
{ | ||
$rules = [ | ||
'name' => 'permit_empty', | ||
'emailAddress' => 'permit_empty|valid_email', | ||
'alias.*' => 'permit_empty|matches[name]', | ||
]; | ||
$this->validation->setRules($rules); | ||
|
||
$data = [ | ||
'name' => 'Princess Peach', | ||
'emailAddress' => '[email protected]', | ||
'alias' => [ | ||
'Princess ', | ||
'Princess Peach', | ||
], | ||
]; | ||
$this->assertFalse($this->validation->run($data)); | ||
$this->assertSame( | ||
['alias.0' => 'The alias.* field does not match the name field.'], | ||
$this->validation->getErrors() | ||
); | ||
} | ||
|
||
public static function provideMatchesNestedCases(): iterable | ||
{ | ||
yield from [ | ||
|
@@ -373,6 +417,50 @@ public function testDiffersNested(array $data, bool $expected): void | |
$this->assertSame(! $expected, $this->validation->run($data)); | ||
} | ||
|
||
public function testDiffersWithDotArrayPass(): void | ||
{ | ||
$rules = [ | ||
'name' => 'permit_empty', | ||
'emailAddress' => 'permit_empty|valid_email', | ||
'alias.*' => 'permit_empty|differs[name]', | ||
]; | ||
$this->validation->setRules($rules); | ||
|
||
$data = [ | ||
'name' => 'Princess Peach', | ||
'emailAddress' => '[email protected]', | ||
'alias' => [ | ||
'Princess Toadstool', | ||
'Peach', | ||
], | ||
]; | ||
$this->assertTrue($this->validation->run($data)); | ||
} | ||
|
||
public function testDiffersWithDotArrayFail(): void | ||
{ | ||
$rules = [ | ||
'name' => 'permit_empty', | ||
'emailAddress' => 'permit_empty|valid_email', | ||
'alias.*' => 'permit_empty|differs[name]', | ||
]; | ||
$this->validation->setRules($rules); | ||
|
||
$data = [ | ||
'name' => 'Princess Peach', | ||
'emailAddress' => '[email protected]', | ||
'alias' => [ | ||
'Princess Toadstool', | ||
'Princess Peach', | ||
], | ||
]; | ||
$this->assertFalse($this->validation->run($data)); | ||
$this->assertSame( | ||
['alias.1' => 'The alias.* field must differ from the name field.'], | ||
$this->validation->getErrors() | ||
); | ||
} | ||
|
||
#[DataProvider('provideEquals')] | ||
public function testEquals(array $data, string $param, bool $expected): void | ||
{ | ||
|