[Validator] UuidValidator must accept a Uuid constraint.

This commit is contained in:
Hugo Hamon 2016-07-01 21:10:03 +02:00
parent e262ef046b
commit ff8bb4b5f2
2 changed files with 14 additions and 0 deletions

View File

@ -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');
}

View File

@ -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
*/