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.
This commit is contained in:
commit
0259bedec1
@ -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');
|
||||
}
|
||||
|
@ -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
|
||||
*/
|
||||
|
Reference in New Issue
Block a user