[Validator] UuidValidator must accept a Uuid constraint.
This commit is contained in:
parent
e262ef046b
commit
ff8bb4b5f2
@ -81,6 +81,10 @@ class UuidValidator extends ConstraintValidator
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!$constraint instanceof Uuid) {
|
||||||
|
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Uuid');
|
||||||
|
}
|
||||||
|
|
||||||
if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
|
if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
|
||||||
throw new UnexpectedTypeException($value, 'string');
|
throw new UnexpectedTypeException($value, 'string');
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,16 @@ class UuidValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
$this->assertNoViolation();
|
$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
|
* @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user