|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket; |
|
5
|
|
|
|
|
6
|
|
|
use Doctrine\ORM\Tools\ToolsException; |
|
7
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* @group #6303 |
|
11
|
|
|
*/ |
|
12
|
|
|
class DDC6303Test extends OrmFunctionalTestCase |
|
13
|
|
|
{ |
|
14
|
|
View Code Duplication |
public function setUp() : void |
|
15
|
|
|
{ |
|
16
|
|
|
parent::setUp(); |
|
17
|
|
|
|
|
18
|
|
|
try { |
|
19
|
|
|
$this->_schemaTool->createSchema([ |
|
20
|
|
|
$this->_em->getClassMetadata(DDC6303BaseClass::class), |
|
21
|
|
|
$this->_em->getClassMetadata(DDC6303ChildA::class), |
|
22
|
|
|
$this->_em->getClassMetadata(DDC6303ChildB::class), |
|
23
|
|
|
]); |
|
24
|
|
|
} catch (ToolsException $ignored) { |
|
|
|
|
|
|
25
|
|
|
} |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function testMixedTypeHydratedCorrectlyInJoinedInheritance() : void |
|
29
|
|
|
{ |
|
30
|
|
|
// DDC6303ChildA and DDC6303ChildB have an inheritance from DDC6303BaseClass, |
|
31
|
|
|
// but one has a string originalData and the second has an array, since the fields |
|
32
|
|
|
// are mapped differently |
|
33
|
|
|
$this->assertHydratedEntitiesSameToPersistedOnes([ |
|
34
|
|
|
'a' => new DDC6303ChildA('a', 'authorized'), |
|
35
|
|
|
'b' => new DDC6303ChildB('b', ['accepted', 'authorized']), |
|
36
|
|
|
]); |
|
37
|
|
|
|
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function testEmptyValuesInJoinedInheritance() : void |
|
41
|
|
|
{ |
|
42
|
|
|
$this->assertHydratedEntitiesSameToPersistedOnes([ |
|
43
|
|
|
'stringEmpty' => new DDC6303ChildA('stringEmpty', ''), |
|
44
|
|
|
'stringZero' => new DDC6303ChildA('stringZero', 0), |
|
45
|
|
|
'arrayEmpty' => new DDC6303ChildB('arrayEmpty', []), |
|
46
|
|
|
]); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @param DDC6303BaseClass[] $persistedEntities indexed by identifier |
|
51
|
|
|
* |
|
52
|
|
|
* @throws \Doctrine\Common\Persistence\Mapping\MappingException |
|
53
|
|
|
* @throws \Doctrine\ORM\ORMException |
|
54
|
|
|
* @throws \Doctrine\ORM\OptimisticLockException |
|
55
|
|
|
*/ |
|
56
|
|
|
private function assertHydratedEntitiesSameToPersistedOnes(array $persistedEntities) : void |
|
57
|
|
|
{ |
|
58
|
|
|
array_walk($persistedEntities, [$this->_em, 'persist']); |
|
59
|
|
|
$this->_em->flush(); |
|
60
|
|
|
$this->_em->clear(); |
|
61
|
|
|
|
|
62
|
|
|
/* @var $entities DDC6303BaseClass[] */ |
|
63
|
|
|
$entities = $this |
|
64
|
|
|
->_em |
|
65
|
|
|
->getRepository(DDC6303BaseClass::class) |
|
66
|
|
|
->createQueryBuilder('p') |
|
67
|
|
|
->where('p.id IN(:ids)') |
|
68
|
|
|
->setParameter('ids', array_keys($persistedEntities)) |
|
69
|
|
|
->getQuery()->getResult(); |
|
70
|
|
|
|
|
71
|
|
|
self::assertCount(count($persistedEntities), $entities); |
|
72
|
|
|
|
|
73
|
|
|
foreach ($entities as $entity) { |
|
74
|
|
|
self::assertEquals($entity, $persistedEntities[$entity->id]); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @Entity |
|
81
|
|
|
* @Table |
|
82
|
|
|
* @InheritanceType("JOINED") |
|
83
|
|
|
* @DiscriminatorColumn(name="discr", type="string") |
|
84
|
|
|
* @DiscriminatorMap({ |
|
85
|
|
|
* DDC6303ChildB::class = DDC6303ChildB::class, |
|
86
|
|
|
* DDC6303ChildA::class = DDC6303ChildA::class, |
|
87
|
|
|
* }) |
|
88
|
|
|
* |
|
89
|
|
|
* Note: discriminator map order *IS IMPORTANT* for this test |
|
90
|
|
|
*/ |
|
91
|
|
|
abstract class DDC6303BaseClass |
|
92
|
|
|
{ |
|
93
|
|
|
/** @Id @Column(type="string") @GeneratedValue(strategy="NONE") */ |
|
94
|
|
|
public $id; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** @Entity @Table */ |
|
98
|
|
|
class DDC6303ChildA extends DDC6303BaseClass |
|
99
|
|
|
{ |
|
100
|
|
|
/** @Column(type="string") */ |
|
101
|
|
|
private $originalData; |
|
102
|
|
|
|
|
103
|
|
|
public function __construct(string $id, $originalData) |
|
104
|
|
|
{ |
|
105
|
|
|
$this->id = $id; |
|
106
|
|
|
$this->originalData = $originalData; |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** @Entity @Table */ |
|
111
|
|
|
class DDC6303ChildB extends DDC6303BaseClass |
|
112
|
|
|
{ |
|
113
|
|
|
/** @Column(type="simple_array", nullable=true) */ |
|
114
|
|
|
private $originalData; |
|
115
|
|
|
|
|
116
|
|
|
public function __construct(string $id, array $originalData) |
|
117
|
|
|
{ |
|
118
|
|
|
$this->id = $id; |
|
119
|
|
|
$this->originalData = $originalData; |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|