From ff8bb4b5f27c5af85dba6ac2d26223490e8191c7 Mon Sep 17 00:00:00 2001 From: Hugo Hamon Date: Fri, 1 Jul 2016 21:10:03 +0200 Subject: [PATCH] [Validator] UuidValidator must accept a Uuid constraint. --- .../Component/Validator/Constraints/UuidValidator.php | 4 ++++ .../Validator/Tests/Constraints/UuidValidatorTest.php | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/Symfony/Component/Validator/Constraints/UuidValidator.php b/src/Symfony/Component/Validator/Constraints/UuidValidator.php index 08f9e27b73..6ef9178f7e 100644 --- a/src/Symfony/Component/Validator/Constraints/UuidValidator.php +++ b/src/Symfony/Component/Validator/Constraints/UuidValidator.php @@ -81,6 +81,10 @@ class UuidValidator extends ConstraintValidator return; } + if (!$constraint instanceof Uuid) { + throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Uuid'); + } + if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) { throw new UnexpectedTypeException($value, 'string'); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/UuidValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/UuidValidatorTest.php index 0abda39f02..05a60684c2 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/UuidValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/UuidValidatorTest.php @@ -44,6 +44,16 @@ class UuidValidatorTest extends AbstractConstraintValidatorTest $this->assertNoViolation(); } + /** + * @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException + */ + public function testExpectsUuidConstraintCompatibleType() + { + $constraint = $this->getMockForAbstractClass('Symfony\\Component\\Validator\\Constraint'); + + $this->validator->validate('216fff40-98d9-11e3-a5e2-0800200c9a66', $constraint); + } + /** * @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException */