Tested DDC-3300
This commit is contained in:
parent
93b6eeca54
commit
5a1a32297b
82
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3300Test.php
Normal file
82
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3300Test.php
Normal file
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||
|
||||
use Doctrine\ORM\Events;
|
||||
use Doctrine\ORM\Tools\ResolveDiscriminatorMapListener;
|
||||
|
||||
/**
|
||||
* @group DDC-3300
|
||||
*/
|
||||
class DDC3300Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
{
|
||||
public function testIssue()
|
||||
{
|
||||
$this
|
||||
->_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
|
||||
{
|
||||
}
|
||||
|
@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Tools;
|
||||
|
||||
use Doctrine\ORM\Events;
|
||||
use Doctrine\ORM\Mapping\ClassMetadataFactory;
|
||||
use Doctrine\ORM\Mapping\Column;
|
||||
use Doctrine\ORM\Mapping\MappedSuperclass;
|
||||
use Doctrine\ORM\Tools\ResolveDiscriminatorMapListener;
|
||||
|
||||
class ResolveDiscriminatorMapListenerTest extends \Doctrine\Tests\OrmTestCase
|
||||
{
|
||||
/**
|
||||
* @var EntityManager
|
||||
*/
|
||||
private $em = null;
|
||||
|
||||
/**
|
||||
* @var ClassMetadataFactory
|
||||
*/
|
||||
private $factory = null;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$annotationDriver = $this->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;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user