[DoctrineBridge] support __toString as documented for UniqueEntityValidator
This commit is contained in:
parent
817e7cdfaa
commit
2ac883a99b
@ -482,7 +482,7 @@ class UniqueEntityValidatorTest extends ConstraintValidatorTestCase
|
|||||||
|
|
||||||
$this->buildViolation('myMessage')
|
$this->buildViolation('myMessage')
|
||||||
->atPath('property.path.single')
|
->atPath('property.path.single')
|
||||||
->setParameter('{{ value }}', 'object("Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity") identified by (id => 1)')
|
->setParameter('{{ value }}', 'foo')
|
||||||
->setInvalidValue($entity1)
|
->setInvalidValue($entity1)
|
||||||
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
|
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
|
||||||
->setCause(array($associated, $associated2))
|
->setCause(array($associated, $associated2))
|
||||||
|
@ -186,6 +186,10 @@ class UniqueEntityValidator extends ConstraintValidator
|
|||||||
return $this->formatValue($value, self::PRETTY_DATE);
|
return $this->formatValue($value, self::PRETTY_DATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (\method_exists($value, '__toString')) {
|
||||||
|
return (string) $value;
|
||||||
|
}
|
||||||
|
|
||||||
if ($class->getName() !== $idClass = \get_class($value)) {
|
if ($class->getName() !== $idClass = \get_class($value)) {
|
||||||
// non unique value might be a composite PK that consists of other entity objects
|
// non unique value might be a composite PK that consists of other entity objects
|
||||||
if ($em->getMetadataFactory()->hasMetadataFor($idClass)) {
|
if ($em->getMetadataFactory()->hasMetadataFor($idClass)) {
|
||||||
|
Reference in New Issue
Block a user