File tree Expand file tree Collapse file tree 2 files changed +5
-16
lines changed
src/Symfony/Component/Validator Expand file tree Collapse file tree 2 files changed +5
-16
lines changed Original file line number Diff line number Diff line change 15
15
use Symfony \Component \Validator \ConstraintValidator ;
16
16
use Symfony \Component \Validator \Exception \UnexpectedTypeException ;
17
17
use Symfony \Component \Validator \Exception \UnexpectedValueException ;
18
- use Symfony \Component \Validator \Validator \ValidatorInterface ;
19
18
20
19
/**
21
20
* @author Laurent Masforné <l.masforne@gmail.com>
24
23
*/
25
24
class IsinValidator extends ConstraintValidator
26
25
{
27
- /**
28
- * @var ValidatorInterface
29
- */
30
- private $ validator ;
31
-
32
- public function __construct (ValidatorInterface $ validator )
33
- {
34
- $ this ->validator = $ validator ;
35
- }
36
-
37
26
/**
38
27
* {@inheritdoc}
39
28
*/
@@ -87,6 +76,6 @@ private function isCorrectChecksum(string $input): bool
87
76
}
88
77
$ number = implode ('' , $ characters );
89
78
90
- return 0 === $ this ->validator ->validate ($ number , new Luhn ())->count ();
79
+ return 0 === $ this ->context -> getValidator () ->validate ($ number , new Luhn ())->count ();
91
80
}
92
81
}
Original file line number Diff line number Diff line change 4
4
5
5
use Symfony \Component \Validator \Constraints \Isin ;
6
6
use Symfony \Component \Validator \Constraints \IsinValidator ;
7
+ use Symfony \Component \Validator \Constraints \Luhn ;
7
8
use Symfony \Component \Validator \Test \ConstraintValidatorTestCase ;
8
- use Symfony \Component \Validator \ValidatorBuilder ;
9
9
10
10
class IsinValidatorTest extends ConstraintValidatorTestCase
11
11
{
12
12
protected function createValidator ()
13
13
{
14
- $ validatorBuilder = new ValidatorBuilder ();
15
-
16
- return new IsinValidator ($ validatorBuilder ->getValidator ());
14
+ return new IsinValidator ();
17
15
}
18
16
19
17
public function testNullIsValid ()
@@ -36,6 +34,7 @@ public function testEmptyStringIsValid()
36
34
public function testValidIsin ($ isin )
37
35
{
38
36
$ this ->validator ->validate ($ isin , new Isin ());
37
+ $ this ->expectViolationsAt (0 , $ isin , new Luhn ());
39
38
$ this ->assertNoViolation ();
40
39
}
41
40
@@ -103,6 +102,7 @@ public function getIsinWithInvalidPattern()
103
102
*/
104
103
public function testIsinWithValidFormatButIncorrectChecksum ($ isin )
105
104
{
105
+ $ this ->expectViolationsAt (0 , $ isin , new Luhn ());
106
106
$ this ->assertViolationRaised ($ isin , Isin::INVALID_CHECKSUM_ERROR );
107
107
}
108
108
You can’t perform that action at this time.
0 commit comments