|
19 | 19 | use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity; |
20 | 20 | use Symfony\Bridge\Doctrine\Tests\Fixtures\DoubleNameEntity; |
21 | 21 | use Symfony\Bridge\Doctrine\Tests\Fixtures\AssociationEntity; |
| 22 | +use Symfony\Bridge\Doctrine\Tests\Fixtures\AssociationEntity2; |
| 23 | +use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdNoToStringEntity; |
22 | 24 | use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; |
23 | 25 | use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntityValidator; |
24 | 26 | use Symfony\Component\Validator\Tests\Constraints\AbstractConstraintValidatorTest; |
@@ -125,9 +127,11 @@ private function createSchema(ObjectManager $em) |
125 | 127 | $schemaTool = new SchemaTool($em); |
126 | 128 | $schemaTool->createSchema(array( |
127 | 129 | $em->getClassMetadata('Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity'), |
| 130 | + $em->getClassMetadata('Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdNoToStringEntity'), |
128 | 131 | $em->getClassMetadata('Symfony\Bridge\Doctrine\Tests\Fixtures\DoubleNameEntity'), |
129 | 132 | $em->getClassMetadata('Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeIntIdEntity'), |
130 | 133 | $em->getClassMetadata('Symfony\Bridge\Doctrine\Tests\Fixtures\AssociationEntity'), |
| 134 | + $em->getClassMetadata('Symfony\Bridge\Doctrine\Tests\Fixtures\AssociationEntity2'), |
131 | 135 | )); |
132 | 136 | } |
133 | 137 |
|
@@ -406,6 +410,42 @@ public function testAssociatedEntity() |
406 | 410 | ->assertRaised(); |
407 | 411 | } |
408 | 412 |
|
| 413 | + public function testValidateUniquenessNotToStringEntityWithAssociatedEntity() |
| 414 | + { |
| 415 | + $constraint = new UniqueEntity(array( |
| 416 | + 'message' => 'myMessage', |
| 417 | + 'fields' => array('single'), |
| 418 | + 'em' => self::EM_NAME, |
| 419 | + )); |
| 420 | + |
| 421 | + $entity1 = new SingleIntIdNoToStringEntity(1, 'foo'); |
| 422 | + $associated = new AssociationEntity2(); |
| 423 | + $associated->single = $entity1; |
| 424 | + $associated2 = new AssociationEntity2(); |
| 425 | + $associated2->single = $entity1; |
| 426 | + |
| 427 | + $this->em->persist($entity1); |
| 428 | + $this->em->persist($associated); |
| 429 | + $this->em->flush(); |
| 430 | + |
| 431 | + $this->validator->validate($associated, $constraint); |
| 432 | + |
| 433 | + $this->assertNoViolation(); |
| 434 | + |
| 435 | + $this->em->persist($associated2); |
| 436 | + $this->em->flush(); |
| 437 | + |
| 438 | + $this->validator->validate($associated2, $constraint); |
| 439 | + |
| 440 | + $expectedValue = 'Object of class "Symfony\Bridge\Doctrine\Tests\Fixtures\AssociationEntity2" identified by "2"'; |
| 441 | + |
| 442 | + $this->buildViolation('myMessage') |
| 443 | + ->atPath('property.path.single') |
| 444 | + ->setParameter('{{ value }}', $expectedValue) |
| 445 | + ->setInvalidValue($expectedValue) |
| 446 | + ->assertRaised(); |
| 447 | + } |
| 448 | + |
409 | 449 | public function testAssociatedEntityWithNull() |
410 | 450 | { |
411 | 451 | $constraint = new UniqueEntity(array( |
|
0 commit comments