Skip to content

Commit

Permalink
bug #19267 [Validator] UuidValidator must accept a Uuid constraint. (…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
fabpot committed Jul 4, 2016
2 parents ff9ac70 + ff8bb4b commit 0259bed
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 0259bed

Please sign in to comment.