2222
2323use DarkWebDesign \SymfonyAddon \Constraint \Collection ;
2424use DarkWebDesign \SymfonyAddon \Constraint \CollectionValidator ;
25- use DarkWebDesign \SymfonyAddon \Constraint \Tests \Models \ ToStringObject ;
25+ use DarkWebDesign \SymfonyAddon \Constraint \Tests \AbstractValidatorTestCase ;
2626use DarkWebDesign \SymfonyAddon \Constraint \Tests \Models \TraversableObject ;
27- use PHPUnit_Framework_TestCase ;
2827use stdClass ;
2928use Symfony \Component \Validator \Constraints as Assert ;
3029
31- class CollectionValidatorTest extends PHPUnit_Framework_TestCase
30+ class CollectionValidatorTest extends AbstractValidatorTestCase
3231{
3332 /** @var \Symfony\Component\Validator\ExecutionContext */
3433 private $ context ;
@@ -38,7 +37,7 @@ class CollectionValidatorTest extends PHPUnit_Framework_TestCase
3837
3938 protected function setUp ()
4039 {
41- $ this ->context = $ this ->getMock ( ' Symfony\Component\Validator\ExecutionContext ' , array (), array (), '' , false );
40+ $ this ->context = $ this ->createContext ( );
4241 $ this ->validator = new CollectionValidator ();
4342 $ this ->validator ->initialize ($ this ->context );
4443 }
@@ -57,11 +56,18 @@ public function testValidate($value)
5756
5857 $ i = 0 ;
5958
59+ $ contextualValidator = $ this ->context ->getValidator ()->inContext ($ this ->context );
60+
6061 foreach ($ value as $ field => $ fieldValue ) {
6162 foreach ($ constraints as $ constraint ) {
62- $ this ->context ->expects ($ this ->at ($ i ++))
63- ->method ('validateValue ' )
64- ->with ($ fieldValue , $ constraint , '[ ' . $ field . '] ' );
63+ $ contextualValidator ->expects ($ this ->at ($ i ++))
64+ ->method ('atPath ' )
65+ ->with ('[ ' . $ field . '] ' )
66+ ->will ($ this ->returnValue ($ contextualValidator ));
67+
68+ $ contextualValidator ->expects ($ this ->at ($ i ++))
69+ ->method ('validate ' )
70+ ->with ($ fieldValue , $ constraint );
6571 }
6672 }
6773
@@ -73,22 +79,18 @@ public function testValidate($value)
7379 */
7480 public function testValidateNoCollectionConstraint ()
7581 {
76- $ this ->context
77- ->expects ($ this ->never ())
78- ->method ('validateValue ' );
79-
8082 $ this ->validator ->validate (array (), new Assert \NotNull ());
83+
84+ $ this ->assertCount (0 , $ this ->context ->getViolations ());
8185 }
8286
8387 public function testValidateNull ()
8488 {
85- $ this ->context
86- ->expects ($ this ->never ())
87- ->method ('validateValue ' );
88-
8989 $ this ->validator ->validate (null , new Collection (array (
9090 new Assert \NotBlank (),
9191 )));
92+
93+ $ this ->assertCount (0 , $ this ->context ->getViolations ());
9294 }
9395
9496 /**
@@ -100,13 +102,11 @@ public function testValidateNull()
100102 */
101103 public function testValidateNoArray ($ value )
102104 {
103- $ this ->context
104- ->expects ($ this ->never ())
105- ->method ('validateValue ' );
106-
107105 $ this ->validator ->validate ($ value , new Collection (array (
108106 new Assert \NotBlank (),
109107 )));
108+
109+ $ this ->assertCount (0 , $ this ->context ->getViolations ());
110110 }
111111
112112 /**
0 commit comments