2222
2323use DarkWebDesign \SymfonyAddon \Constraint \Bsn ;
2424use DarkWebDesign \SymfonyAddon \Constraint \BsnValidator ;
25- use DarkWebDesign \SymfonyAddon \Constraint \Tests \AbstractValidatorTestCase ;
2625use DarkWebDesign \SymfonyAddon \Constraint \Tests \Models \ToStringObject ;
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 BsnValidatorTest extends AbstractValidatorTestCase
31+ class BsnValidatorTest extends AbstractConstraintValidatorTest
3132{
32- /** @var \Symfony\Component\Validator\ExecutionContext */
33- private $ context ;
34-
35- /** @var \DarkWebDesign\SymfonyAddon\Constraint\BsnValidator */
36- private $ validator ;
37-
38- /** @var \DarkWebDesign\SymfonyAddon\Constraint\Bsn */
39- private $ constraint ;
33+ /**
34+ * @return int
35+ */
36+ protected function getApiVersion ()
37+ {
38+ return Validation::API_VERSION_2_5 ;
39+ }
4040
41- protected function setUp ()
41+ /**
42+ * @return \DarkWebDesign\SymfonyAddon\Constraint\BsnValidator
43+ */
44+ protected function createValidator ()
4245 {
43- $ this ->context = $ this ->createContext ();
44- $ this ->validator = new BsnValidator ();
45- $ this ->validator ->initialize ($ this ->context );
46- $ this ->constraint = new Bsn ();
46+ return new BsnValidator ();
4747 }
4848
4949 /**
@@ -53,9 +53,9 @@ protected function setUp()
5353 */
5454 public function testValidate ($ bsn )
5555 {
56- $ this ->validator ->validate ($ bsn , $ this -> constraint );
56+ $ this ->validator ->validate ($ bsn , new Bsn () );
5757
58- $ this ->assertCount ( 0 , $ this -> context -> getViolations () );
58+ $ this ->assertNoViolation ( );
5959 }
6060
6161 /**
@@ -65,21 +65,21 @@ public function testValidateInvalidConstraint()
6565 {
6666 $ this ->validator ->validate (array (), new Assert \NotNull ());
6767
68- $ this ->assertCount ( 0 , $ this -> context -> getViolations () );
68+ $ this ->assertNoViolation ( );
6969 }
7070
7171 public function testValidateNull ()
7272 {
73- $ this ->validator ->validate (null , $ this -> constraint );
73+ $ this ->validator ->validate (null , new Bsn () );
7474
75- $ this ->assertCount ( 0 , $ this -> context -> getViolations () );
75+ $ this ->assertNoViolation ( );
7676 }
7777
7878 public function testValidateEmptyString ()
7979 {
80- $ this ->validator ->validate ('' , $ this -> constraint );
80+ $ this ->validator ->validate ('' , new Bsn () );
8181
82- $ this ->assertCount ( 0 , $ this -> context -> getViolations () );
82+ $ this ->assertNoViolation ( );
8383 }
8484
8585 /**
@@ -91,9 +91,9 @@ public function testValidateEmptyString()
9191 */
9292 public function testValidateNoScalar ($ bsn )
9393 {
94- $ this ->validator ->validate ($ bsn , $ this -> constraint );
94+ $ this ->validator ->validate ($ bsn , new Bsn () );
9595
96- $ this ->assertCount ( 0 , $ this -> context -> getViolations () );
96+ $ this ->assertNoViolation ( );
9797 }
9898
9999 /**
@@ -103,12 +103,13 @@ public function testValidateNoScalar($bsn)
103103 */
104104 public function testValidateViolation ($ bsn )
105105 {
106- $ this -> validator -> validate ( $ bsn , $ this -> constraint );
106+ $ constraint = new Bsn ( );
107107
108- $ violation = $ this ->createViolation ( $ this -> constraint -> message , array ( ' {{ value }} ' => ' " ' . $ bsn . ' " ' ) );
108+ $ this ->validator -> validate ( $ bsn, $ constraint );
109109
110- $ this ->assertCount (1 , $ this ->context ->getViolations ());
111- $ this ->assertEquals ($ violation , $ this ->context ->getViolations ()->get (0 ));
110+ $ this ->buildViolation ($ constraint ->message )
111+ ->setParameter ('{{ value }} ' , '" ' . $ bsn . '" ' )
112+ ->assertRaised ();
112113 }
113114
114115 /**
0 commit comments