8000 bug #28252 [DoctrineBridge] support __toString as documented for Uniq… · symfony/symfony@d446b6a · GitHub
[go: up one dir, main page]

Skip to content

Commit d446b6a

Browse files
bug #28252 [DoctrineBridge] support __toString as documented for UniqueEntityValidator (dmaicher)
This PR was squashed before being merged into the 3.4 branch (closes #28252). Discussion ---------- [DoctrineBridge] support __toString as documented for UniqueEntityValidator | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #28245 | License | MIT | Doc PR | - This fixes #28245. It brings back handling `__toString` as documented for invalid values. Commits ------- 2ac883a [DoctrineBridge] support __toString as documented for UniqueEntityValidator
2 parents a682051 + 2ac883a commit d446b6a

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ public function testAssociatedEntity()
482482

483483
$this->buildViolation('myMessage')
484484
->atPath('property.path.single')
485-
->setParameter('{{ value }}', 'object("Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity") identified by (id => 1)')
485+
->setParameter('{{ value }}', 'foo')
486486
->setInvalidValue($entity1)
487487
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
488488
->setCause(array($associated, $associated2))

src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ private function formatWithIdentifiers(ObjectManager $em, ClassMetadata $class,
186186
return $this->formatValue($value, self::PRETTY_DATE);
187187
}
188188

189+
if (\method_exists($value, '__toString')) {
190+
return (string) $value;
191+
}
192+
189193
if ($class->getName() !== $idClass = \get_class($value)) {
190194
// non unique value might be a composite PK that consists of other entity objects
191195
if ($em->getMetadataFactory()->hasMetadataFor($idClass)) {

0 commit comments

Comments
 (0)
0