|
16 | 16 | use Doctrine\Common\Persistence\ObjectManager;
|
17 | 17 | use Doctrine\Common\Persistence\ObjectRepository;
|
18 | 18 | use Symfony\Bridge\Doctrine\Test\DoctrineTestHelper;
|
| 19 | +use Symfony\Bridge\Doctrine\Tests\Fixtures\Employee; |
| 20 | +use Symfony\Bridge\Doctrine\Tests\Fixtures\Person; |
19 | 21 | use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity;
|
20 | 22 | use Symfony\Bridge\Doctrine\Tests\Fixtures\DoubleNameEntity;
|
21 | 23 | use Symfony\Bridge\Doctrine\Tests\Fixtures\AssociationEntity;
|
@@ -134,6 +136,8 @@ private function createSchema(ObjectManager $em)
|
134 | 136 | $em->getClassMetadata('Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeIntIdEntity'),
|
135 | 137 | $em->getClassMetadata('Symfony\Bridge\Doctrine\Tests\Fixtures\AssociationEntity'),
|
136 | 138 | $em->getClassMetadata('Symfony\Bridge\Doctrine\Tests\Fixtures\AssociationEntity2'),
|
| 139 | + $em->getClassMetadata('Symfony\Bridge\Doctrine\Tests\Fixtures\Person'), |
| 140 | + $em->getClassMetadata('Symfony\Bridge\Doctrine\Tests\Fixtures\Employee'), |
137 | 141 | ));
|
138 | 142 | }
|
139 | 143 |
|
@@ -517,4 +521,54 @@ public function testEntityManagerNullObject()
|
517 | 521 |
|
518 | 522 | $this->validator->validate($entity, $constraint);
|
519 | 523 | }
|
| 524 | + |
| 525 | + public function testValidateInheritanceUniqueness() |
| 526 | + { |
| 527 | + $constraint = new UniqueEntity(array( |
| 528 | + 'message' => 'myMessage', |
| 529 | + 'fields' => array('name'), |
| 530 | + 'em' => self::EM_NAME, |
| 531 | + 'entityClass' => 'Symfony\Bridge\Doctrine\Tests\Fixtures\Person', |
| 532 | + )); |
| 533 | + |
| 534 | + $entity1 = new Person(1, 'Foo'); |
| 535 | + $entity2 = new Employee(2, 'Foo'); |
| 536 | + |
| 537 | + $this->validator->validate($entity1, $constraint); |
| 538 | + |
| 539 | + $this->assertNoViolation(); |
| 540 | + |
| 541 | + $this->em->persist($entity1); |
| 542 | + $this->em->flush(); |
| 543 | + |
| 544 | + $this->validator->validate($entity1, $constraint); |
| 545 | + |
| 546 | + $this->assertNoViolation(); |
| 547 | + |
| 548 | + $this->validator->validate($entity2, $constraint); |
| 549 | + |
| 550 | + $this->buildViolation('myMessage') |
| 551 | + ->atPath('property.path.name') |
| 552 | + ->setInvalidValue('Foo') |
| 553 | + ->setCode('23bd9dbf-6b9b-41cd-a99e-4844bcf3077f') |
| 554 | + ->setParameters(array('{{ value }}' => 'Foo')) |
| 555 | + ->assertRaised(); |
| 556 | + } |
| 557 | + |
| 558 | + /** |
| 559 | + * @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException |
| 560 | + * @expectedExceptionMessage The "Symfony\Bridge\Doctrine\Tests\Fixtures\SingleStringIdEntity" entity repository does not support the "Symfony\Bridge\Doctrine\Tests\Fixtures\Person" entity. The entity should be an instance of or extend "Symfony\Bridge\Doctrine\Tests\Fixtures\SingleStringIdEntity". |
| 561 | + */ |
| 562 | + public function testInvalidateRepositoryForInheritance() |
| 563 | + { |
| 564 | + $constraint = new UniqueEntity(array( |
| 565 | + 'message' => 'myMessage', |
| 566 | + 'fields' => array('name'), |
| 567 | + 'em' => self::EM_NAME, |
| 568 | + 'entityClass' => 'Symfony\Bridge\Doctrine\Tests\Fixtures\SingleStringIdEntity', |
| 569 | + )); |
| 570 | + |
| 571 | + $entity = new Person(1, 'Foo'); |
| 572 | + $this->validator->validate($entity, $constraint); |
| 573 | + } |
520 | 574 | }
|
0 commit comments