Skip to content

Commit 0259bed

Browse files
committed
bug #19267 [Validator] UuidValidator must accept a Uuid constraint. (hhamon)
This PR was merged into the 2.7 branch. Discussion ---------- [Validator] UuidValidator must accept a Uuid constraint. | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | ~ | License | MIT | Doc PR | ~ Commits ------- ff8bb4b [Validator] UuidValidator must accept a Uuid constraint.
2 parents ff9ac70 + ff8bb4b commit 0259bed

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)