1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket; |
|
|
|
|
5
|
|
|
use Doctrine\ORM\Annotation as ORM; |
|
|
|
|
6
|
|
|
use Doctrine\DBAL\LockMode; |
|
|
|
|
7
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @group GH-5998 |
11
|
|
|
*/ |
12
|
|
|
class GH5998Test extends OrmFunctionalTestCase |
13
|
|
|
{ |
14
|
|
|
protected function setUp(): void |
|
|
|
|
15
|
|
|
{ |
16
|
|
|
parent::setUp(); |
17
|
|
|
$this->schemaTool->createSchema( |
18
|
|
|
[ |
19
|
|
|
$this->em->getClassMetadata(GH5998JTI::class), |
|
|
|
|
20
|
|
|
$this->em->getClassMetadata(GH5998JTIChild::class), |
|
|
|
|
21
|
|
|
$this->em->getClassMetadata(GH5998STI::class), |
|
|
|
|
22
|
|
|
] |
23
|
|
|
); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Verifies that MappedSuperclasses work within an inheritance hierarchy. |
28
|
|
|
*/ |
29
|
|
|
public function testIssue() |
30
|
|
|
{ |
31
|
|
|
// Test JTI |
32
|
|
|
$this->testClass(GH5998JTIChild::class); |
33
|
|
|
// Test STI |
34
|
|
|
$this->testClass(GH5998STIChild::class); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
private function testClass($className) { |
38
|
|
|
// Test insert |
39
|
|
|
$child = new $className('Sam', 0, 1); |
40
|
|
|
$this->em->persist($child); |
41
|
|
|
$this->em->flush(); |
42
|
|
|
$this->em->clear(); |
43
|
|
|
|
44
|
|
|
// Test find |
45
|
|
|
$child = $this->em->getRepository($className)->find(1); |
46
|
|
|
self::assertNotNull($child); |
47
|
|
|
|
48
|
|
|
// Test lock and update |
49
|
|
|
$this->em->transactional(function($em) use ($child) { |
|
|
|
|
50
|
|
|
$em->lock($child, LockMode::NONE); |
51
|
|
|
$child->firstName = 'Bob'; |
52
|
|
|
$child->status = 0; |
|
|
|
|
53
|
|
|
}); |
54
|
|
|
$this->em->clear(); |
55
|
|
|
$child = $this->em->getRepository($className)->find(1); |
56
|
|
|
self::assertEquals($child->firstName, 'Bob'); |
57
|
|
|
self::assertEquals($child->status, 0); |
58
|
|
|
|
59
|
|
|
// Test delete |
60
|
|
|
$this->em->remove($child); |
61
|
|
|
$this->em->flush(); |
62
|
|
|
$child = $this->em->getRepository($className)->find(1); |
63
|
|
|
self::assertNull($child); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @ORM\MappedSuperclass |
69
|
|
|
*/ |
70
|
|
|
class GH5998Common |
71
|
|
|
{ |
72
|
|
|
/** |
73
|
|
|
* @ORM\Id |
74
|
|
|
* @ORM\Column(type="integer") |
75
|
|
|
* @ORM\GeneratedValue |
76
|
|
|
*/ |
77
|
|
|
public $id; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @ORM\Entity |
82
|
|
|
* @ORM\InheritanceType("JOINED") |
83
|
|
|
* @ORM\DiscriminatorMap({"child" = "Doctrine\Tests\ORM\Functional\Ticket\GH5998JTIChild"}) |
84
|
|
|
*/ |
85
|
|
|
abstract class GH5998JTI extends GH5998Common |
86
|
|
|
{ |
87
|
|
|
/** |
|
|
|
|
88
|
|
|
* @ORM\Column(type="string", length=255); |
89
|
|
|
*/ |
90
|
|
|
public $firstName; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @ORM\MappedSuperclass |
95
|
|
|
*/ |
96
|
|
|
class GH5998JTICommon extends GH5998JTI |
97
|
|
|
{ |
98
|
|
|
/** |
|
|
|
|
99
|
|
|
* @ORM\Column(type="integer"); |
100
|
|
|
*/ |
101
|
|
|
public $status; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @ORM\Entity |
106
|
|
|
*/ |
107
|
|
|
class GH5998JTIChild extends GH5998JTICommon |
108
|
|
|
{ |
109
|
|
|
/** |
|
|
|
|
110
|
|
|
* @ORM\Column(type="integer") |
111
|
|
|
*/ |
112
|
|
|
public $type; |
113
|
|
|
function __construct(string $firstName, int $type, int $status) |
|
|
|
|
114
|
|
|
{ |
115
|
|
|
$this->firstName = $firstName; |
116
|
|
|
$this->type = $type; |
|
|
|
|
117
|
|
|
$this->status = $status; |
|
|
|
|
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @ORM\Entity |
123
|
|
|
* @ORM\InheritanceType("SINGLE_TABLE") |
124
|
|
|
* @ORM\DiscriminatorMap({"child" = "Doctrine\Tests\ORM\Functional\Ticket\GH5998STIChild"}) |
125
|
|
|
*/ |
126
|
|
|
abstract class GH5998STI extends GH5998Common |
127
|
|
|
{ |
128
|
|
|
/** |
|
|
|
|
129
|
|
|
* @ORM\Column(type="string", length=255); |
130
|
|
|
*/ |
131
|
|
|
public $firstName; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @ORM\MappedSuperclass |
136
|
|
|
*/ |
137
|
|
|
class GH5998STICommon extends GH5998STI |
138
|
|
|
{ |
139
|
|
|
/** |
|
|
|
|
140
|
|
|
* @ORM\Column(type="integer"); |
141
|
|
|
*/ |
142
|
|
|
public $status; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @ORM\Entity |
147
|
|
|
*/ |
148
|
|
|
class GH5998STIChild extends GH5998STICommon |
149
|
|
|
{ |
150
|
|
|
/** |
|
|
|
|
151
|
|
|
* @ORM\Column(type="integer") |
152
|
|
|
*/ |
153
|
|
|
public $type; |
154
|
|
|
function __construct(string $firstName, int $type, int $status) |
|
|
|
|
155
|
|
|
{ |
156
|
|
|
$this->firstName = $firstName; |
157
|
|
|
$this->type = $type; |
|
|
|
|
158
|
|
|
$this->status = $status; |
|
|
|
|
159
|
|
|
} |
160
|
|
|
} |
161
|
|
|
|