diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3300Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3300Test.php new file mode 100644 index 000000000..422b3d78f --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3300Test.php @@ -0,0 +1,82 @@ +_em + ->getEventManager() + ->addEventListener( + Events::loadClassMetadata, + new ResolveDiscriminatorMapListener(array( + 'Doctrine\Tests\ORM\Functional\Ticket\DDC3300BossInterface' => 'Doctrine\Tests\ORM\Functional\Ticket\DDC3300Boss', + 'Doctrine\Tests\ORM\Functional\Ticket\DDC3300EmployeeInterface' => 'Doctrine\Tests\ORM\Functional\Ticket\DDC3300Employee', + )) + ); + + $this->_schemaTool->createSchema(array( + $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC3300Person'), + )); + + $boss = new DDC3300Boss(); + $this->_em->persist($boss); + + $employee = new DDC3300Employee(); + $this->_em->persist($employee); + + $this->_em->flush(); + } +} + +/** + * @Entity + * @InheritanceType("SINGLE_TABLE") + * @DdiscriminatorColumn(name="discr", type="string") + * @DiscriminatorMap({ + * "boss" = "Doctrine\Tests\ORM\Functional\Ticket\DDC3300BossInterface", + * "employee" = "Doctrine\Tests\ORM\Functional\Ticket\DDC3300EmployeeInterface" + * }) + */ +abstract class DDC3300Person +{ + /** + * @Id + * @Column(type="integer") + * @GeneratedValue(strategy="AUTO") + */ + public $id; +} + +interface DDC3300BossInterface +{ + +} + +/** + * @Entity + */ +class DDC3300Boss extends DDC3300Person implements DDC3300BossInterface +{ +} + +interface DDC3300EmployeeInterface +{ + +} + +/** + * @Entity + */ +class DDC3300Employee extends DDC3300Person implements DDC3300EmployeeInterface +{ +} + \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Tools/ResolveDiscriminatorMapListenerTest.php b/tests/Doctrine/Tests/ORM/Tools/ResolveDiscriminatorMapListenerTest.php new file mode 100644 index 000000000..ed6a0aaa7 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Tools/ResolveDiscriminatorMapListenerTest.php @@ -0,0 +1,112 @@ +createAnnotationDriver(); + + $this->em = $this->_getTestEntityManager(); + $this->em->getConfiguration()->setMetadataDriverImpl($annotationDriver); + $this->factory = new ClassMetadataFactory; + $this->factory->setEntityManager($this->em); + } + + /** + * @group DDC-3300 + */ + public function testResolveDiscriminatorMapListenerTestCanResolveDiscriminatorMap() + { + $evm = $this->em->getEventManager(); + $listener = new ResolveDiscriminatorMapListener(array( + 'Doctrine\Tests\ORM\Tools\BossInterface' => 'Doctrine\Tests\ORM\Tools\Boss', + 'Doctrine\Tests\ORM\Tools\EmployeeInterface' => 'Doctrine\Tests\ORM\Tools\Employee', + )); + + $evm->addEventListener(Events::loadClassMetadata, $listener); + $cm = $this->factory->getMetadataFor('Doctrine\Tests\ORM\Tools\Person'); + $meta = $cm->discriminatorMap; + $this->assertSame('Doctrine\Tests\ORM\Tools\Boss', $meta['boss']); + $this->assertSame('Doctrine\Tests\ORM\Tools\Employee', $meta['employee']); + } + + /** + * @group DDC-3300 + */ + public function testResolveDiscriminatorMapListenerTestCannotResolveWrongDiscriminatorMap() + { + $evm = $this->em->getEventManager(); + $listener = new ResolveDiscriminatorMapListener(array( + 'Doctrine\Tests\ORM\Tools\EmployeeInterface' => 'Doctrine\Tests\ORM\Tools\Employee', + )); + + $evm->addEventListener(Events::loadClassMetadata, $listener); + $cm = $this->factory->getMetadataFor('Doctrine\Tests\ORM\Tools\Person'); + $meta = $cm->discriminatorMap; + $this->assertSame('Doctrine\Tests\ORM\Tools\BossInterface', $meta['boss']); + $this->assertSame('Doctrine\Tests\ORM\Tools\Employee', $meta['employee']); + } +} + +/** + * @Entity + * @InheritanceType("SINGLE_TABLE") + * @DiscriminatorColumn(name="discr", type="string") + * @DiscriminatorMap({ + * "boss" = "\Doctrine\Tests\ORM\Tools\BossInterface", + * "employee" = "\Doctrine\Tests\ORM\Tools\EmployeeInterface" + * }) + */ +abstract class Person +{ + /** + * @Id + * @Column(type="integer") + * @GeneratedValue(strategy="AUTO") + */ + private $id; +} + +interface BossInterface +{ + +} + +class Boss extends Person implements BossInterface +{ + /** + * @Column(type="integer") + */ + private $earnedMoneyInEuros; +} + +interface EmployeeInterface +{ + +} + +class Employee extends Person implements EmployeeInterface +{ + /** + * @Column(type="integer") + */ + private $daysOfLifeReducedInDays; +}