1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket; |
6
|
|
|
|
7
|
|
|
use Doctrine\DBAL\LockMode; |
8
|
|
|
use Doctrine\ORM\Annotation as ORM; |
9
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @group GH-5998 |
13
|
|
|
*/ |
14
|
|
|
class GH5998Test extends OrmFunctionalTestCase |
15
|
|
|
{ |
16
|
|
|
protected function setUp() : void |
17
|
|
|
{ |
18
|
|
|
parent::setUp(); |
19
|
|
|
$this->schemaTool->createSchema([ |
20
|
|
|
$this->em->getClassMetadata(GH5998JTI::class), |
21
|
|
|
$this->em->getClassMetadata(GH5998JTIChild::class), |
22
|
|
|
$this->em->getClassMetadata(GH5998STI::class), |
23
|
|
|
$this->em->getClassMetadata(GH5998Basic::class), |
24
|
|
|
$this->em->getClassMetadata(GH5998Related::class), |
25
|
|
|
]); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Verifies that MappedSuperclasses work within an inheritance hierarchy. |
30
|
|
|
*/ |
31
|
|
|
public function testIssue() |
32
|
|
|
{ |
33
|
|
|
// Test JTI |
34
|
|
|
$this->classTests(GH5998JTIChild::class); |
35
|
|
|
// Test STI |
36
|
|
|
$this->classTests(GH5998STIChild::class); |
37
|
|
|
// Test Basic |
38
|
|
|
$this->classTests(GH5998Basic::class); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
private function classTests($className) |
42
|
|
|
{ |
43
|
|
|
// Test insert |
44
|
|
|
$child = new $className('Sam', 0, 1); |
|
|
|
|
45
|
|
|
$child->rel = new GH5998Related(); |
46
|
|
|
$this->em->persist($child); |
47
|
|
|
$this->em->persist($child->rel); |
48
|
|
|
$this->em->flush(); |
49
|
|
|
$this->em->clear(); |
50
|
|
|
|
51
|
|
|
// Test find by rel |
52
|
|
|
$child = $this->em->getRepository($className)->findOneBy(['rel'=>$child->rel]); |
|
|
|
|
53
|
|
|
self::assertNotNull($child); |
54
|
|
|
$this->em->clear(); |
55
|
|
|
|
56
|
|
|
// Test query by id with fetch join |
57
|
|
|
$child = $this->em->createQuery("SELECT t, r FROM $className t JOIN t.rel r WHERE t.id = 1")->getOneOrNullResult(); |
|
|
|
|
58
|
|
|
self::assertNotNull($child); |
59
|
|
|
|
60
|
|
|
// Test lock and update |
61
|
|
|
$this->em->transactional(static function ($em) use ($child) { |
62
|
|
|
$em->lock($child, LockMode::NONE); |
63
|
|
|
$child->firstName = 'Bob'; |
64
|
|
|
$child->status = 0; |
65
|
|
|
}); |
66
|
|
|
$this->em->clear(); |
67
|
|
|
$child = $this->em->getRepository($className)->find(1); |
68
|
|
|
self::assertEquals($child->firstName, 'Bob'); |
69
|
|
|
self::assertEquals($child->status, 0); |
70
|
|
|
|
71
|
|
|
// Test delete |
72
|
|
|
$this->em->remove($child); |
73
|
|
|
$this->em->flush(); |
74
|
|
|
$child = $this->em->getRepository($className)->find(1); |
75
|
|
|
self::assertNull($child); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @ORM\MappedSuperclass |
81
|
|
|
*/ |
82
|
|
|
class GH5998Common |
83
|
|
|
{ |
84
|
|
|
/** |
85
|
|
|
* @ORM\Id |
86
|
|
|
* @ORM\Column(type="integer") |
87
|
|
|
* @ORM\GeneratedValue |
88
|
|
|
*/ |
89
|
|
|
public $id; |
90
|
|
|
/** |
91
|
|
|
* @ORM\ManyToOne(targetEntity=GH5998Related::class) |
92
|
|
|
* @ORM\JoinColumn(name="related_id", referencedColumnName="id") |
93
|
|
|
*/ |
94
|
|
|
public $rel; |
95
|
|
|
/** |
96
|
|
|
* @ORM\Version |
97
|
|
|
* @ORM\Column(type="integer") |
98
|
|
|
*/ |
99
|
|
|
public $version; |
100
|
|
|
|
101
|
|
|
public $other; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @ORM\Entity |
106
|
|
|
* @ORM\InheritanceType("JOINED") |
107
|
|
|
* @ORM\DiscriminatorMap({"child" = GH5998JTIChild::class}) |
108
|
|
|
*/ |
109
|
|
|
abstract class GH5998JTI extends GH5998Common |
110
|
|
|
{ |
111
|
|
|
/** @ORM\Column(type="string", length=255) */ |
112
|
|
|
public $firstName; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @ORM\MappedSuperclass |
117
|
|
|
*/ |
118
|
|
|
class GH5998JTICommon extends GH5998JTI |
119
|
|
|
{ |
120
|
|
|
/** @ORM\Column(type="integer") */ |
121
|
|
|
public $status; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @ORM\Entity |
126
|
|
|
*/ |
127
|
|
|
class GH5998JTIChild extends GH5998JTICommon |
128
|
|
|
{ |
129
|
|
|
/** @ORM\Column(type="integer") */ |
130
|
|
|
public $type; |
131
|
|
|
|
132
|
|
|
public function __construct(string $firstName, int $type, int $status) |
133
|
|
|
{ |
134
|
|
|
$this->firstName = $firstName; |
135
|
|
|
$this->type = $type; |
136
|
|
|
$this->status = $status; |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @ORM\Entity |
142
|
|
|
* @ORM\InheritanceType("SINGLE_TABLE") |
143
|
|
|
* @ORM\DiscriminatorMap({"child" = GH5998STIChild::class}) |
144
|
|
|
*/ |
145
|
|
|
abstract class GH5998STI extends GH5998Common |
146
|
|
|
{ |
147
|
|
|
/** @ORM\Column(type="string", length=255) */ |
148
|
|
|
public $firstName; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @ORM\MappedSuperclass |
153
|
|
|
*/ |
154
|
|
|
class GH5998STICommon extends GH5998STI |
155
|
|
|
{ |
156
|
|
|
/** @ORM\Column(type="integer") */ |
157
|
|
|
public $status; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @ORM\Entity |
162
|
|
|
*/ |
163
|
|
|
class GH5998STIChild extends GH5998STICommon |
164
|
|
|
{ |
165
|
|
|
/** @ORM\Column(type="integer") */ |
166
|
|
|
public $type; |
167
|
|
|
|
168
|
|
|
public function __construct(string $firstName, int $type, int $status) |
169
|
|
|
{ |
170
|
|
|
$this->firstName = $firstName; |
171
|
|
|
$this->type = $type; |
172
|
|
|
$this->status = $status; |
173
|
|
|
} |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* @ORM\Entity |
178
|
|
|
*/ |
179
|
|
|
class GH5998Basic extends GH5998Common |
180
|
|
|
{ |
181
|
|
|
/** @ORM\Column(type="string", length=255) */ |
182
|
|
|
public $firstName; |
183
|
|
|
/** @ORM\Column(type="integer") */ |
184
|
|
|
public $status; |
185
|
|
|
/** @ORM\Column(type="integer") */ |
186
|
|
|
public $type; |
187
|
|
|
|
188
|
|
|
public function __construct(string $firstName, int $type, int $status) |
189
|
|
|
{ |
190
|
|
|
$this->firstName = $firstName; |
191
|
|
|
$this->type = $type; |
192
|
|
|
$this->status = $status; |
193
|
|
|
} |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* @ORM\Entity |
198
|
|
|
*/ |
199
|
|
|
class GH5998Related |
200
|
|
|
{ |
201
|
|
|
/** |
202
|
|
|
* @ORM\Id |
203
|
|
|
* @ORM\Column(type="integer") |
204
|
|
|
* @ORM\GeneratedValue |
205
|
|
|
*/ |
206
|
|
|
public $id; |
207
|
|
|
} |
208
|
|
|
|
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.