|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
8
|
|
|
use Doctrine\ORM\Annotation as ORM; |
|
9
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase; |
|
10
|
|
|
use Exception; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Functional tests for the Single Table Inheritance mapping strategy. |
|
14
|
|
|
*/ |
|
15
|
|
|
class Ticket69 extends OrmFunctionalTestCase |
|
16
|
|
|
{ |
|
17
|
|
|
protected function setUp() : void |
|
18
|
|
|
{ |
|
19
|
|
|
parent::setUp(); |
|
20
|
|
|
try { |
|
21
|
|
|
$this->schemaTool->createSchema( |
|
22
|
|
|
[ |
|
23
|
|
|
$this->em->getClassMetadata(Lemma::class), |
|
24
|
|
|
$this->em->getClassMetadata(Relation::class), |
|
25
|
|
|
$this->em->getClassMetadata(RelationType::class), |
|
26
|
|
|
] |
|
27
|
|
|
); |
|
28
|
|
|
} catch (Exception $e) { |
|
29
|
|
|
// Swallow all exceptions. We do not test the schema tool here. |
|
30
|
|
|
} |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function testIssue() : void |
|
34
|
|
|
{ |
|
35
|
|
|
//setup |
|
36
|
|
|
$lemma1 = new Lemma(); |
|
37
|
|
|
$lemma1->setLemma('foo'); |
|
38
|
|
|
|
|
39
|
|
|
$lemma2 = new Lemma(); |
|
40
|
|
|
$lemma2->setLemma('bar'); |
|
41
|
|
|
|
|
42
|
|
|
$lemma3 = new Lemma(); |
|
43
|
|
|
$lemma3->setLemma('batz'); |
|
44
|
|
|
|
|
45
|
|
|
$lemma4 = new Lemma(); |
|
46
|
|
|
$lemma4->setLemma('bla'); |
|
47
|
|
|
|
|
48
|
|
|
$type1 = new RelationType(); |
|
49
|
|
|
$type1->setType('nonsense'); |
|
50
|
|
|
$type1->setAbbreviation('non'); |
|
51
|
|
|
|
|
52
|
|
|
$type2 = new RelationType(); |
|
53
|
|
|
$type2->setType('quatsch'); |
|
54
|
|
|
$type2->setAbbreviation('qu'); |
|
55
|
|
|
|
|
56
|
|
|
$relation1 = new Relation(); |
|
57
|
|
|
$relation1->setParent($lemma1); |
|
58
|
|
|
$relation1->setChild($lemma2); |
|
59
|
|
|
$relation1->setType($type1); |
|
60
|
|
|
|
|
61
|
|
|
$relation2 = new Relation(); |
|
62
|
|
|
$relation2->setParent($lemma1); |
|
63
|
|
|
$relation2->setChild($lemma3); |
|
64
|
|
|
$relation2->setType($type1); |
|
65
|
|
|
|
|
66
|
|
|
$relation3 = new Relation(); |
|
67
|
|
|
$relation3->setParent($lemma1); |
|
68
|
|
|
$relation3->setChild($lemma4); |
|
69
|
|
|
$relation3->setType($type2); |
|
70
|
|
|
|
|
71
|
|
|
$lemma1->addRelation($relation1); |
|
72
|
|
|
$lemma1->addRelation($relation2); |
|
73
|
|
|
$lemma1->addRelation($relation3); |
|
74
|
|
|
|
|
75
|
|
|
$this->em->persist($type1); |
|
76
|
|
|
$this->em->persist($type2); |
|
77
|
|
|
$this->em->persist($lemma1); |
|
78
|
|
|
$this->em->persist($lemma2); |
|
79
|
|
|
$this->em->persist($lemma3); |
|
80
|
|
|
$this->em->persist($lemma4); |
|
81
|
|
|
|
|
82
|
|
|
$this->em->flush(); |
|
83
|
|
|
$this->em->clear(); |
|
84
|
|
|
//end setup |
|
85
|
|
|
|
|
86
|
|
|
// test One To Many |
|
87
|
|
|
$query = $this->em->createQuery("SELECT l FROM Doctrine\Tests\ORM\Functional\Ticket\Lemma l Where l.lemma = 'foo'"); |
|
88
|
|
|
$res = $query->getResult(); |
|
89
|
|
|
$lemma = $res[0]; |
|
90
|
|
|
|
|
91
|
|
|
self::assertEquals('foo', $lemma->getLemma()); |
|
92
|
|
|
self::assertInstanceOf(Lemma::class, $lemma); |
|
93
|
|
|
$relations = $lemma->getRelations(); |
|
94
|
|
|
|
|
95
|
|
|
foreach ($relations as $relation) { |
|
96
|
|
|
self::assertInstanceOf(Relation::class, $relation); |
|
97
|
|
|
self::assertTrue($relation->getType()->getType() !== ''); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
$this->em->clear(); |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @ORM\Entity |
|
106
|
|
|
* @ORM\Table(name="lemma") |
|
107
|
|
|
*/ |
|
108
|
|
|
class Lemma |
|
109
|
|
|
{ |
|
110
|
|
|
public const CLASS_NAME = self::class; |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @ORM\Id |
|
114
|
|
|
* @ORM\Column(type="integer", name="lemma_id") |
|
115
|
|
|
* @ORM\GeneratedValue(strategy="AUTO") |
|
116
|
|
|
* |
|
117
|
|
|
* @var int |
|
118
|
|
|
*/ |
|
119
|
|
|
private $id; |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* @ORM\Column(type="string", name="lemma_name", unique=true, length=255) |
|
123
|
|
|
* |
|
124
|
|
|
* @var string |
|
125
|
|
|
*/ |
|
126
|
|
|
private $lemma; |
|
127
|
|
|
|
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* @ORM\OneToMany(targetEntity=Relation::class, mappedBy="parent", cascade={"persist"}) |
|
131
|
|
|
* |
|
132
|
|
|
* @var kateglo\application\utilities\collections\ArrayCollection |
|
|
|
|
|
|
133
|
|
|
*/ |
|
134
|
|
|
private $relations; |
|
135
|
|
|
|
|
136
|
|
|
public function __construct() |
|
137
|
|
|
{ |
|
138
|
|
|
$this->types = new ArrayCollection(); |
|
|
|
|
|
|
139
|
|
|
$this->relations = new ArrayCollection(); |
|
|
|
|
|
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* @return int |
|
144
|
|
|
*/ |
|
145
|
|
|
public function getId() |
|
146
|
|
|
{ |
|
147
|
|
|
return $this->id; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* @param string $lemma |
|
152
|
|
|
*/ |
|
153
|
|
|
public function setLemma($lemma) |
|
154
|
|
|
{ |
|
155
|
|
|
$this->lemma = $lemma; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* @return string |
|
160
|
|
|
*/ |
|
161
|
|
|
public function getLemma() |
|
162
|
|
|
{ |
|
163
|
|
|
return $this->lemma; |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
public function addRelation(Relation $relation) |
|
167
|
|
|
{ |
|
168
|
|
|
$this->relations[] = $relation; |
|
169
|
|
|
$relation->setParent($this); |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
public function removeRelation(Relation $relation) |
|
173
|
|
|
{ |
|
174
|
|
|
/** @var Relation $removed */ |
|
175
|
|
|
$removed = $this->relations->removeElement($relation); |
|
176
|
|
|
if ($removed !== null) { |
|
177
|
|
|
$removed->removeParent(); |
|
178
|
|
|
} |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
/** |
|
182
|
|
|
* @return kateglo\application\utilities\collections\ArrayCollection |
|
183
|
|
|
*/ |
|
184
|
|
|
public function getRelations() |
|
185
|
|
|
{ |
|
186
|
|
|
return $this->relations; |
|
187
|
|
|
} |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
/** |
|
191
|
|
|
* @ORM\Entity |
|
192
|
|
|
* @ORM\Table(name="relation") |
|
193
|
|
|
*/ |
|
194
|
|
|
class Relation |
|
195
|
|
|
{ |
|
196
|
|
|
public const CLASS_NAME = self::class; |
|
197
|
|
|
|
|
198
|
|
|
/** |
|
199
|
|
|
* @ORM\Id |
|
200
|
|
|
* @ORM\Column(type="integer", name="relation_id") |
|
201
|
|
|
* @ORM\GeneratedValue(strategy="AUTO") |
|
202
|
|
|
* |
|
203
|
|
|
* @var int |
|
204
|
|
|
*/ |
|
205
|
|
|
private $id; |
|
206
|
|
|
|
|
207
|
|
|
/** |
|
208
|
|
|
* @ORM\ManyToOne(targetEntity=Lemma::class, inversedBy="relations") |
|
209
|
|
|
* @ORM\JoinColumn(name="relation_parent_id", referencedColumnName="lemma_id") |
|
210
|
|
|
* |
|
211
|
|
|
* @var Lemma |
|
212
|
|
|
*/ |
|
213
|
|
|
private $parent; |
|
214
|
|
|
|
|
215
|
|
|
/** |
|
216
|
|
|
* @ORM\OneToOne(targetEntity=Lemma::class) |
|
217
|
|
|
* @ORM\JoinColumn(name="relation_child_id", referencedColumnName="lemma_id") |
|
218
|
|
|
* |
|
219
|
|
|
* @var Lemma |
|
220
|
|
|
*/ |
|
221
|
|
|
private $child; |
|
222
|
|
|
|
|
223
|
|
|
/** |
|
224
|
|
|
* @ORM\ManyToOne(targetEntity=RelationType::class, inversedBy="relations") |
|
225
|
|
|
* @ORM\JoinColumn(name="relation_type_id", referencedColumnName="relation_type_id") |
|
226
|
|
|
* |
|
227
|
|
|
* @var RelationType |
|
228
|
|
|
*/ |
|
229
|
|
|
private $type; |
|
230
|
|
|
|
|
231
|
|
|
public function setParent(Lemma $parent) |
|
232
|
|
|
{ |
|
233
|
|
|
$this->parent = $parent; |
|
234
|
|
|
} |
|
235
|
|
|
|
|
236
|
|
|
/** |
|
237
|
|
|
* @return Phrase |
|
|
|
|
|
|
238
|
|
|
*/ |
|
239
|
|
|
public function getParent() |
|
240
|
|
|
{ |
|
241
|
|
|
return $this->parent; |
|
|
|
|
|
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
public function removeParent() |
|
245
|
|
|
{ |
|
246
|
|
|
if ($this->lemma !== null) { |
|
|
|
|
|
|
247
|
|
|
/** @var Lemma $phrase */ |
|
248
|
|
|
$lemma = $this->parent; |
|
249
|
|
|
$this->parent = null; |
|
250
|
|
|
$lemma->removeRelation($this); |
|
251
|
|
|
} |
|
252
|
|
|
} |
|
253
|
|
|
|
|
254
|
|
|
public function setChild(Lemma $child) |
|
255
|
|
|
{ |
|
256
|
|
|
$this->child = $child; |
|
257
|
|
|
} |
|
258
|
|
|
|
|
259
|
|
|
/** |
|
260
|
|
|
* @return Lemma |
|
261
|
|
|
*/ |
|
262
|
|
|
public function getChild() |
|
263
|
|
|
{ |
|
264
|
|
|
return $this->child; |
|
265
|
|
|
} |
|
266
|
|
|
|
|
267
|
|
|
public function setType(RelationType $type) |
|
268
|
|
|
{ |
|
269
|
|
|
$this->type = $type; |
|
270
|
|
|
} |
|
271
|
|
|
|
|
272
|
|
|
/** |
|
273
|
|
|
* @return RelationType |
|
274
|
|
|
*/ |
|
275
|
|
|
public function getType() |
|
276
|
|
|
{ |
|
277
|
|
|
return $this->type; |
|
278
|
|
|
} |
|
279
|
|
|
|
|
280
|
|
|
public function removeType() |
|
281
|
|
|
{ |
|
282
|
|
|
if ($this->type !== null) { |
|
283
|
|
|
/** @var RelationType $phrase */ |
|
284
|
|
|
$type = $this->type; |
|
285
|
|
|
$this->type = null; |
|
286
|
|
|
$type->removeRelation($this); |
|
287
|
|
|
} |
|
288
|
|
|
} |
|
289
|
|
|
} |
|
290
|
|
|
|
|
291
|
|
|
/** |
|
292
|
|
|
* @ORM\Entity |
|
293
|
|
|
* @ORM\Table(name="relation_type") |
|
294
|
|
|
*/ |
|
295
|
|
|
class RelationType |
|
296
|
|
|
{ |
|
297
|
|
|
public const CLASS_NAME = self::class; |
|
298
|
|
|
|
|
299
|
|
|
/** |
|
300
|
|
|
* @ORM\Id |
|
301
|
|
|
* @ORM\Column(type="integer", name="relation_type_id") |
|
302
|
|
|
* @ORM\GeneratedValue(strategy="AUTO") |
|
303
|
|
|
* |
|
304
|
|
|
* @var int |
|
305
|
|
|
*/ |
|
306
|
|
|
private $id; |
|
307
|
|
|
|
|
308
|
|
|
/** |
|
309
|
|
|
* @ORM\Column(type="string", name="relation_type_name", unique=true, length=255) |
|
310
|
|
|
* |
|
311
|
|
|
* @var string |
|
312
|
|
|
*/ |
|
313
|
|
|
private $type; |
|
314
|
|
|
|
|
315
|
|
|
/** |
|
316
|
|
|
* @ORM\Column(type="string", name="relation_type_abbreviation", unique=true, length=255) |
|
317
|
|
|
* |
|
318
|
|
|
* @var string |
|
319
|
|
|
*/ |
|
320
|
|
|
private $abbreviation; |
|
321
|
|
|
|
|
322
|
|
|
/** |
|
323
|
|
|
* @ORM\OneToMany(targetEntity=Relation::class, mappedBy="type", cascade={"persist"}) |
|
324
|
|
|
* |
|
325
|
|
|
* @var kateglo\application\utilities\collections\ArrayCollection |
|
326
|
|
|
*/ |
|
327
|
|
|
private $relations; |
|
328
|
|
|
|
|
329
|
|
|
public function __construct() |
|
330
|
|
|
{ |
|
331
|
|
|
$relations = new ArrayCollection(); |
|
|
|
|
|
|
332
|
|
|
} |
|
333
|
|
|
|
|
334
|
|
|
/** |
|
335
|
|
|
* @return int |
|
336
|
|
|
*/ |
|
337
|
|
|
public function getId() |
|
338
|
|
|
{ |
|
339
|
|
|
return $this->id; |
|
340
|
|
|
} |
|
341
|
|
|
|
|
342
|
|
|
/** |
|
343
|
|
|
* @param string $type |
|
344
|
|
|
*/ |
|
345
|
|
|
public function setType($type) |
|
346
|
|
|
{ |
|
347
|
|
|
$this->type = $type; |
|
348
|
|
|
} |
|
349
|
|
|
|
|
350
|
|
|
/** |
|
351
|
|
|
* @return string |
|
352
|
|
|
*/ |
|
353
|
|
|
public function getType() |
|
354
|
|
|
{ |
|
355
|
|
|
return $this->type; |
|
356
|
|
|
} |
|
357
|
|
|
|
|
358
|
|
|
/** |
|
359
|
|
|
* @param string $abbreviation |
|
360
|
|
|
*/ |
|
361
|
|
|
public function setAbbreviation($abbreviation) |
|
362
|
|
|
{ |
|
363
|
|
|
$this->abbreviation = $abbreviation; |
|
364
|
|
|
} |
|
365
|
|
|
|
|
366
|
|
|
/** |
|
367
|
|
|
* @return string |
|
368
|
|
|
*/ |
|
369
|
|
|
public function getAbbreviation() |
|
370
|
|
|
{ |
|
371
|
|
|
return $this->abbreviation; |
|
372
|
|
|
} |
|
373
|
|
|
|
|
374
|
|
|
public function addRelation(Relation $relation) |
|
375
|
|
|
{ |
|
376
|
|
|
$this->relations[] = $relation; |
|
377
|
|
|
$relation->setType($this); |
|
378
|
|
|
} |
|
379
|
|
|
|
|
380
|
|
|
public function removeRelation(Relation $relation) |
|
381
|
|
|
{ |
|
382
|
|
|
/** @var Relation $removed */ |
|
383
|
|
|
$removed = $this->relations->removeElement($relation); |
|
384
|
|
|
if ($removed !== null) { |
|
385
|
|
|
$removed->removeLemma(); |
|
|
|
|
|
|
386
|
|
|
} |
|
387
|
|
|
} |
|
388
|
|
|
|
|
389
|
|
|
/** |
|
390
|
|
|
* @return kateglo\application\utilities\collections\ArrayCollection |
|
391
|
|
|
*/ |
|
392
|
|
|
public function getRelations() |
|
393
|
|
|
{ |
|
394
|
|
|
return $this->relations; |
|
395
|
|
|
} |
|
396
|
|
|
} |
|
397
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths