@@ -336,6 +336,50 @@ public function testMatchesNested(array $data, bool $expected): void
336336 $ this ->assertSame ($ expected , $ this ->validation ->run ($ data ));
337337 }
338338
339+ public function testMatchesWithDotArrayPass (): void
340+ {
341+ $ rules = [
342+ 'name ' => 'permit_empty ' ,
343+ 'emailAddress ' => 'permit_empty|valid_email ' ,
344+ 'alias.* ' => 'permit_empty|matches[name] ' ,
345+ ];
346+ $ this ->validation ->setRules ($ rules );
347+
348+ $ data = [
349+ 'name ' => 'Princess Peach ' ,
350+ 'emailAddress ' => 'valid@example.com ' ,
351+ 'alias ' => [
352+ 'Princess Peach ' ,
353+ 'Princess Peach ' ,
354+ ],
355+ ];
356+ $ this ->assertTrue ($ this ->validation ->run ($ data ));
357+ }
358+
359+ public function testMatchesWithDotArrayFail (): void
360+ {
361+ $ rules = [
362+ 'name ' => 'permit_empty ' ,
363+ 'emailAddress ' => 'permit_empty|valid_email ' ,
364+ 'alias.* ' => 'permit_empty|matches[name] ' ,
365+ ];
366+ $ this ->validation ->setRules ($ rules );
367+
368+ $ data = [
369+ 'name ' => 'Princess Peach ' ,
370+ 'emailAddress ' => 'valid@example.com ' ,
371+ 'alias ' => [
372+ 'Princess ' ,
373+ 'Princess Peach ' ,
374+ ],
375+ ];
376+ $ this ->assertFalse ($ this ->validation ->run ($ data ));
377+ $ this ->assertSame (
378+ ['alias.0 ' => 'The alias.* field does not match the name field. ' ],
379+ $ this ->validation ->getErrors ()
380+ );
381+ }
382+
339383 public static function provideMatchesNestedCases (): iterable
340384 {
341385 yield from [
@@ -373,6 +417,50 @@ public function testDiffersNested(array $data, bool $expected): void
373417 $ this ->assertSame (! $ expected , $ this ->validation ->run ($ data ));
374418 }
375419
420+ public function testDiffersWithDotArrayPass (): void
421+ {
422+ $ rules = [
423+ 'name ' => 'permit_empty ' ,
424+ 'emailAddress ' => 'permit_empty|valid_email ' ,
425+ 'alias.* ' => 'permit_empty|differs[name] ' ,
426+ ];
427+ $ this ->validation ->setRules ($ rules );
428+
429+ $ data = [
430+ 'name ' => 'Princess Peach ' ,
431+ 'emailAddress ' => 'valid@example.com ' ,
432+ 'alias ' => [
433+ 'Princess Toadstool ' ,
434+ 'Peach ' ,
435+ ],
436+ ];
437+ $ this ->assertTrue ($ this ->validation ->run ($ data ));
438+ }
439+
440+ public function testDiffersWithDotArrayFail (): void
441+ {
442+ $ rules = [
443+ 'name ' => 'permit_empty ' ,
444+ 'emailAddress ' => 'permit_empty|valid_email ' ,
445+ 'alias.* ' => 'permit_empty|differs[name] ' ,
446+ ];
447+ $ this ->validation ->setRules ($ rules );
448+
449+ $ data = [
450+ 'name ' => 'Princess Peach ' ,
451+ 'emailAddress ' => 'valid@example.com ' ,
452+ 'alias ' => [
453+ 'Princess Toadstool ' ,
454+ 'Princess Peach ' ,
455+ ],
456+ ];
457+ $ this ->assertFalse ($ this ->validation ->run ($ data ));
458+ $ this ->assertSame (
459+ ['alias.1 ' => 'The alias.* field must differ from the name field. ' ],
460+ $ this ->validation ->getErrors ()
461+ );
462+ }
463+
376464 #[DataProvider('provideEquals ' )]
377465 public function testEquals (array $ data , string $ param , bool $ expected ): void
378466 {
0 commit comments