From 886db16fdfd1617d6481a410f3fce56fc54e59d0 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Thu, 12 Nov 2020 23:51:07 +0100 Subject: [PATCH] [Validator] Resolve IsinValidator's dependency on the validator. --- Constraints/IsinValidator.php | 13 +------------ Tests/Constraints/IsinValidatorTest.php | 8 ++++---- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/Constraints/IsinValidator.php b/Constraints/IsinValidator.php index 9ae31acb1..d5e4d9dbc 100644 --- a/Constraints/IsinValidator.php +++ b/Constraints/IsinValidator.php @@ -15,7 +15,6 @@ use Symfony\Component\Validator\ConstraintValidator; use Symfony\Component\Validator\Exception\UnexpectedTypeException; use Symfony\Component\Validator\Exception\UnexpectedValueException; -use Symfony\Component\Validator\Validator\ValidatorInterface; /** * @author Laurent Masforné @@ -24,16 +23,6 @@ */ class IsinValidator extends ConstraintValidator { - /** - * @var ValidatorInterface - */ - private $validator; - - public function __construct(ValidatorInterface $validator) - { - $this->validator = $validator; - } - /** * {@inheritdoc} */ @@ -87,6 +76,6 @@ private function isCorrectChecksum(string $input): bool } $number = implode('', $characters); - return 0 === $this->validator->validate($number, new Luhn())->count(); + return 0 === $this->context->getValidator()->validate($number, new Luhn())->count(); } } diff --git a/Tests/Constraints/IsinValidatorTest.php b/Tests/Constraints/IsinValidatorTest.php index 0822fb5ad..0a219401b 100644 --- a/Tests/Constraints/IsinValidatorTest.php +++ b/Tests/Constraints/IsinValidatorTest.php @@ -4,16 +4,14 @@ use Symfony\Component\Validator\Constraints\Isin; use Symfony\Component\Validator\Constraints\IsinValidator; +use Symfony\Component\Validator\Constraints\Luhn; use Symfony\Component\Validator\Test\ConstraintValidatorTestCase; -use Symfony\Component\Validator\ValidatorBuilder; class IsinValidatorTest extends ConstraintValidatorTestCase { protected function createValidator() { - $validatorBuilder = new ValidatorBuilder(); - - return new IsinValidator($validatorBuilder->getValidator()); + return new IsinValidator(); } public function testNullIsValid() @@ -36,6 +34,7 @@ public function testEmptyStringIsValid() public function testValidIsin($isin) { $this->validator->validate($isin, new Isin()); + $this->expectViolationsAt(0, $isin, new Luhn()); $this->assertNoViolation(); } @@ -103,6 +102,7 @@ public function getIsinWithInvalidPattern() */ public function testIsinWithValidFormatButIncorrectChecksum($isin) { + $this->expectViolationsAt(0, $isin, new Luhn()); $this->assertViolationRaised($isin, Isin::INVALID_CHECKSUM_ERROR); }