Skip to content

Commit

Permalink
[Validator] UuidValidator must accept a Uuid constraint.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugo Hamon committed Jul 1, 2016
1 parent e262ef0 commit ff8bb4b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Symfony/Component/Validator/Constraints/UuidValidator.php
Expand Up @@ -81,6 +81,10 @@ public function validate($value, Constraint $constraint)
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');
}
Expand Down
Expand Up @@ -44,6 +44,16 @@ public function testEmptyStringIsValid()
$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
*/
Expand Down

0 comments on commit ff8bb4b

Please sign in to comment.