2222
2323use DarkWebDesign \SymfonyAddon \Constraint \Collection ;
2424use DarkWebDesign \SymfonyAddon \Constraint \CollectionValidator ;
25- use DarkWebDesign \SymfonyAddon \Constraint \Tests \AbstractValidatorTestCase ;
2625use DarkWebDesign \SymfonyAddon \Constraint \Tests \Models \TraversableObject ;
2726use stdClass ;
2827use Symfony \Component \Validator \Constraints as Assert ;
28+ use Symfony \Component \Validator \Tests \Constraints \AbstractConstraintValidatorTest ;
29+ use Symfony \Component \Validator \Validation ;
2930
30- class CollectionValidatorTest extends AbstractValidatorTestCase
31+ class CollectionValidatorTest extends AbstractConstraintValidatorTest
3132{
32- /** @var \Symfony\Component\Validator\ExecutionContext */
33- private $ context ;
34-
35- /** @var \DarkWebDesign\SymfonyAddon\Constraint\CollectionValidator */
36- private $ validator ;
33+ /**
34+ * @return int
35+ */
36+ protected function getApiVersion ()
37+ {
38+ return Validation::API_VERSION_2_5 ;
39+ }
3740
38- protected function setUp ()
41+ /**
42+ * @return \DarkWebDesign\SymfonyAddon\Constraint\CollectionValidator
43+ */
44+ protected function createValidator ()
3945 {
40- $ this ->context = $ this ->createContext ();
41- $ this ->validator = new CollectionValidator ();
42- $ this ->validator ->initialize ($ this ->context );
46+ return new CollectionValidator ();
4347 }
4448
4549 /**
@@ -56,22 +60,15 @@ public function testValidate($value)
5660
5761 $ i = 0 ;
5862
59- $ contextualValidator = $ this ->context ->getValidator ()->inContext ($ this ->context );
60-
6163 foreach ($ value as $ field => $ fieldValue ) {
6264 foreach ($ constraints as $ constraint ) {
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 );
65+ $ this ->expectValidateValueAt ($ i ++, '[ ' . $ field . '] ' , $ fieldValue , $ constraint );
7166 }
7267 }
7368
7469 $ this ->validator ->validate ($ value , new Collection ($ constraints ));
70+
71+ $ this ->assertNoViolation ();
7572 }
7673
7774 /**
@@ -81,7 +78,7 @@ public function testValidateInvalidConstraint()
8178 {
8279 $ this ->validator ->validate (array (), new Assert \NotNull ());
8380
84- $ this ->assertCount ( 0 , $ this -> context -> getViolations () );
81+ $ this ->assertNoViolation ( );
8582 }
8683
8784 public function testValidateNull ()
@@ -90,7 +87,7 @@ public function testValidateNull()
9087 new Assert \NotBlank (),
9188 )));
9289
93- $ this ->assertCount ( 0 , $ this -> context -> getViolations () );
90+ $ this ->assertNoViolation ( );
9491 }
9592
9693 /**
@@ -106,7 +103,7 @@ public function testValidateNoArray($value)
106103 new Assert \NotBlank (),
107104 )));
108105
109- $ this ->assertCount ( 0 , $ this -> context -> getViolations () );
106+ $ this ->assertNoViolation ( );
110107 }
111108
112109 /**
0 commit comments