[DoctrineBridge] support __toString as documented for UniqueEntityValidator

This commit is contained in:
David Maicher 2018-08-23 21:04:06 +02:00 committed by Nicolas Grekas
parent 817e7cdfaa
commit 2ac883a99b
2 changed files with 5 additions and 1 deletions

View File

@ -482,7 +482,7 @@ class UniqueEntityValidatorTest extends ConstraintValidatorTestCase
$this->buildViolation('myMessage')
->atPath('property.path.single')
->setParameter('{{ value }}', 'object("Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity") identified by (id => 1)')
->setParameter('{{ value }}', 'foo')
->setInvalidValue($entity1)
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
->setCause(array($associated, $associated2))

View File

@ -186,6 +186,10 @@ class UniqueEntityValidator extends ConstraintValidator
return $this->formatValue($value, self::PRETTY_DATE);
}
if (\method_exists($value, '__toString')) {
return (string) $value;
}
if ($class->getName() !== $idClass = \get_class($value)) {
// non unique value might be a composite PK that consists of other entity objects
if ($em->getMetadataFactory()->hasMetadataFor($idClass)) {