1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
<?php
declare(strict_types=1);
namespace Doctrine\Tests\ORM\Functional\Ticket;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\DiscriminatorColumn;
use Doctrine\ORM\Mapping\DiscriminatorMap;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\InheritanceType;
use Doctrine\ORM\Tools\ResolveTargetEntityListener;
use Doctrine\Tests\OrmFunctionalTestCase;
use PHPUnit\Framework\Attributes\Group;
#[Group('DDC-3300')]
class DDC3300Test extends OrmFunctionalTestCase
{
public function testResolveTargetEntitiesChangesDiscriminatorMapValues(): void
{
$resolveTargetEntity = new ResolveTargetEntityListener();
$resolveTargetEntity->addResolveTargetEntity(
DDC3300Boss::class,
DDC3300HumanBoss::class,
[],
);
$resolveTargetEntity->addResolveTargetEntity(
DDC3300Employee::class,
DDC3300HumanEmployee::class,
[],
);
$this->_em->getEventManager()->addEventSubscriber($resolveTargetEntity);
$this->createSchemaForModels(DDC3300Person::class);
$boss = new DDC3300HumanBoss('boss');
$employee = new DDC3300HumanEmployee('employee');
$this->_em->persist($boss);
$this->_em->persist($employee);
$this->_em->flush();
$this->_em->clear();
self::assertEquals($boss, $this->_em->find(DDC3300Boss::class, $boss->id));
self::assertEquals($employee, $this->_em->find(DDC3300Employee::class, $employee->id));
}
}
#[Entity]
#[InheritanceType('SINGLE_TABLE')]
#[DiscriminatorColumn(name: 'discr', type: 'string')]
#[DiscriminatorMap(['boss' => 'Doctrine\Tests\ORM\Functional\Ticket\DDC3300Boss', 'employee' => 'Doctrine\Tests\ORM\Functional\Ticket\DDC3300Employee'])]
abstract class DDC3300Person
{
/** @var int */
#[Id]
#[Column(type: 'integer')]
#[GeneratedValue(strategy: 'AUTO')]
public $id;
}
interface DDC3300Boss
{
}
#[Entity]
class DDC3300HumanBoss extends DDC3300Person implements DDC3300Boss
{
public function __construct(
#[Column(type: 'string', length: 255)]
public string $bossCol,
) {
}
}
interface DDC3300Employee
{
}
#[Entity]
class DDC3300HumanEmployee extends DDC3300Person implements DDC3300Employee
{
public function __construct(
#[Column(type: 'string', length: 255)]
public string $employeeCol,
) {
}
}
|