Skip to content

Commit

Permalink
bug #39070 [Validator] Remove IsinValidator's validator dependency (d…
Browse files Browse the repository at this point in the history
…errabus)

This PR was merged into the 5.2 branch.

Discussion
----------

[Validator] Remove IsinValidator's validator dependency

| Q             | A
| ------------- | ---
| Branch?       | 5.2
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #39069
| License       | MIT
| Doc PR        | N/A

Commits
-------

4cb7dec347 [Validator] Resolve IsinValidator's dependency on the validator.
  • Loading branch information
derrabus committed Nov 13, 2020
2 parents 93b9edc + 886db16 commit 9919be5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 16 deletions.
13 changes: 1 addition & 12 deletions Constraints/IsinValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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é <[email protected]>
Expand All @@ -24,16 +23,6 @@
*/
class IsinValidator extends ConstraintValidator
{
/**
* @var ValidatorInterface
*/
private $validator;

public function __construct(ValidatorInterface $validator)
{
$this->validator = $validator;
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -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();
}
}
8 changes: 4 additions & 4 deletions Tests/Constraints/IsinValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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();
}

Expand Down Expand Up @@ -103,6 +102,7 @@ public function getIsinWithInvalidPattern()
*/
public function testIsinWithValidFormatButIncorrectChecksum($isin)
{
$this->expectViolationsAt(0, $isin, new Luhn());
$this->assertViolationRaised($isin, Isin::INVALID_CHECKSUM_ERROR);
}

Expand Down

0 comments on commit 9919be5

Please sign in to comment.