8000 [Validator] UuidValidator must accept a Uuid constraint. · symfony/symfony@ff8bb4b · GitHub
[go: up one dir, main page]

Skip to content

Commit ff8bb4b

Browse files
author
Hugo Hamon
committed
[Validator] UuidValidator must accept a Uuid constraint.
1 parent e262ef0 commit ff8bb4b

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/Symfony/Component/Validator/Constraints/UuidValidator.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ public function validate($value, Constraint $constraint)
8181
return;
8282
}
8383

84+
if (!$constraint instanceof Uuid) {
85+
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Uuid');
86+
}
87+
8488
if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
8589
throw new UnexpectedTypeException($value, 'string');
8690
}

src/Symfony/Component/Validator/Tests/Constraints/UuidValidatorTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ public function testEmptyStringIsValid()
4444
$this->assertNoViolation();
4545
}
4646

47+
/**
48+
* @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
49+
*/
50+
public function testExpectsUuidConstraintCompatibleType()
51+
{
52+
$constraint = $this->getMockForAbstractClass('Symfony\\Component\\Validator\\Constraint');
53+
54+
$this->validator->validate('216fff40-98d9-11e3-a5e2-0800200c9a66', $constraint);
55+
}
56+
4757
/**
4858
* @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
4959
*/

0 commit comments

Comments
 (0)
0