|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Doctrine\Tests\ORM\Mapping; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\ORM\Annotation as ORM; |
|
8
|
|
|
use Doctrine\ORM\EntityRepository; |
|
9
|
|
|
use Doctrine\ORM\Mapping\GeneratorType; |
|
10
|
|
|
use Doctrine\ORM\Mapping\TransientMetadata; |
|
11
|
|
|
use Doctrine\ORM\Mapping\ClassMetadataFactory; |
|
12
|
|
|
use Doctrine\ORM\Mapping\ClassMetadata; |
|
13
|
|
|
use Doctrine\ORM\Mapping\MappingException; |
|
14
|
|
|
use Doctrine\ORM\Sequencing\SequenceGenerator; |
|
15
|
|
|
use Doctrine\Tests\Models\DDC869\DDC869ChequePayment; |
|
16
|
|
|
use Doctrine\Tests\Models\DDC869\DDC869CreditCardPayment; |
|
17
|
|
|
use Doctrine\Tests\Models\DDC869\DDC869Payment; |
|
18
|
|
|
use Doctrine\Tests\Models\DDC869\DDC869PaymentRepository; |
|
19
|
|
|
use Doctrine\Tests\OrmTestCase; |
|
20
|
|
|
|
|
21
|
|
|
class BasicInheritanceMappingTest extends OrmTestCase |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @var ClassMetadataFactory |
|
25
|
|
|
*/ |
|
26
|
|
|
private $cmf; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* {@inheritDoc} |
|
30
|
|
|
*/ |
|
31
|
|
|
protected function setUp() { |
|
32
|
|
|
$this->cmf = new ClassMetadataFactory(); |
|
33
|
|
|
|
|
34
|
|
|
$this->cmf->setEntityManager($this->getTestEntityManager()); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function testGetMetadataForTransientClassThrowsException() |
|
38
|
|
|
{ |
|
39
|
|
|
$this->expectException(\Doctrine\ORM\Mapping\MappingException::class); |
|
40
|
|
|
|
|
41
|
|
|
$this->cmf->getMetadataFor(TransientBaseClass::class); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function testGetMetadataForSubclassWithTransientBaseClass() |
|
45
|
|
|
{ |
|
46
|
|
|
$class = $this->cmf->getMetadataFor(EntitySubClass::class); |
|
47
|
|
|
|
|
48
|
|
|
self::assertEmpty($class->getSubClasses()); |
|
49
|
|
|
self::assertCount(0, $class->getAncestorsIterator()); |
|
50
|
|
|
|
|
51
|
|
|
self::assertNotNull($class->getProperty('id')); |
|
52
|
|
|
self::assertNotNull($class->getProperty('name')); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function testGetMetadataForSubclassWithMappedSuperclass() |
|
56
|
|
|
{ |
|
57
|
|
|
$class = $this->cmf->getMetadataFor(EntitySubClass2::class); |
|
58
|
|
|
|
|
59
|
|
|
self::assertEmpty($class->getSubClasses()); |
|
60
|
|
|
self::assertCount(0, $class->getAncestorsIterator()); |
|
61
|
|
|
|
|
62
|
|
|
self::assertNotNull($class->getProperty('id')); |
|
63
|
|
|
self::assertNotNull($class->getProperty('name')); |
|
64
|
|
|
self::assertNotNull($class->getProperty('mapped1')); |
|
65
|
|
|
self::assertNotNull($class->getProperty('mapped2')); |
|
66
|
|
|
|
|
67
|
|
|
self::assertTrue($class->isInheritedProperty('mapped1')); |
|
68
|
|
|
self::assertTrue($class->isInheritedProperty('mapped2')); |
|
69
|
|
|
|
|
70
|
|
|
self::assertNotNull($class->getProperty('transient')); |
|
71
|
|
|
self::assertInstanceOf(TransientMetadata::class, $class->getProperty('transient')); |
|
72
|
|
|
|
|
73
|
|
|
self::assertArrayHasKey('mappedRelated1', $class->getDeclaredPropertiesIterator()); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @group DDC-869 |
|
78
|
|
|
*/ |
|
79
|
|
|
public function testGetMetadataForSubclassWithMappedSuperclassWithRepository() |
|
80
|
|
|
{ |
|
81
|
|
|
$class = $this->cmf->getMetadataFor(DDC869CreditCardPayment::class); |
|
82
|
|
|
|
|
83
|
|
|
self::assertEquals($class->getCustomRepositoryClassName(), DDC869PaymentRepository::class); |
|
84
|
|
|
|
|
85
|
|
|
self::assertNotNull($class->getProperty('id')); |
|
86
|
|
|
self::assertNotNull($class->getProperty('value')); |
|
87
|
|
|
self::assertNotNull($class->getProperty('creditCardNumber')); |
|
88
|
|
|
|
|
89
|
|
|
|
|
90
|
|
|
$class = $this->cmf->getMetadataFor(DDC869ChequePayment::class); |
|
91
|
|
|
|
|
92
|
|
|
self::assertEquals($class->getCustomRepositoryClassName(), DDC869PaymentRepository::class); |
|
93
|
|
|
|
|
94
|
|
|
self::assertNotNull($class->getProperty('id')); |
|
95
|
|
|
self::assertNotNull($class->getProperty('value')); |
|
96
|
|
|
self::assertNotNull($class->getProperty('serialNumber')); |
|
97
|
|
|
|
|
98
|
|
|
// override repositoryClass |
|
99
|
|
|
$class = $this->cmf->getMetadataFor(SubclassWithRepository::class); |
|
100
|
|
|
|
|
101
|
|
|
self::assertEquals($class->getCustomRepositoryClassName(), EntityRepository::class); |
|
102
|
|
|
|
|
103
|
|
|
self::assertNotNull($class->getProperty('id')); |
|
104
|
|
|
self::assertNotNull($class->getProperty('value')); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* @group DDC-1203 |
|
109
|
|
|
*/ |
|
110
|
|
|
public function testUnmappedSuperclassInHierarchy() |
|
111
|
|
|
{ |
|
112
|
|
|
$class = $this->cmf->getMetadataFor(HierarchyD::class); |
|
113
|
|
|
|
|
114
|
|
|
self::assertNotNull($class->getProperty('id')); |
|
115
|
|
|
self::assertNotNull($class->getProperty('a')); |
|
116
|
|
|
self::assertNotNull($class->getProperty('d')); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* @group DDC-1204 |
|
121
|
|
|
*/ |
|
122
|
|
|
public function testUnmappedEntityInHierarchy() |
|
123
|
|
|
{ |
|
124
|
|
|
$this->expectException(MappingException::class); |
|
125
|
|
|
$this->expectExceptionMessage( |
|
126
|
|
|
'Entity \'Doctrine\Tests\ORM\Mapping\HierarchyBEntity\' has to be part of the discriminator map' |
|
127
|
|
|
. ' of \'Doctrine\Tests\ORM\Mapping\HierarchyBase\' to be properly mapped in the inheritance hierarchy.' |
|
128
|
|
|
. ' Alternatively you can make \'Doctrine\Tests\ORM\Mapping\HierarchyBEntity\' an abstract class to' |
|
129
|
|
|
. ' avoid this exception from occurring.' |
|
130
|
|
|
); |
|
131
|
|
|
|
|
132
|
|
|
$this->cmf->getMetadataFor(HierarchyE::class); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* @group DDC-1204 |
|
137
|
|
|
* @group DDC-1203 |
|
138
|
|
|
*/ |
|
139
|
|
|
public function testMappedSuperclassWithId() |
|
140
|
|
|
{ |
|
141
|
|
|
$class = $this->cmf->getMetadataFor(SuperclassEntity::class); |
|
142
|
|
|
|
|
143
|
|
|
self::assertNotNull($class->getProperty('id')); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* @group DDC-1156 |
|
148
|
|
|
* @group DDC-1218 |
|
149
|
|
|
*/ |
|
150
|
|
View Code Duplication |
public function testGeneratedValueFromMappedSuperclass() |
|
151
|
|
|
{ |
|
152
|
|
|
/* @var ClassMetadata $class */ |
|
153
|
|
|
$class = $this->cmf->getMetadataFor(SuperclassEntity::class); |
|
154
|
|
|
|
|
155
|
|
|
self::assertSame(GeneratorType::SEQUENCE, $class->getProperty('id')->getValueGenerator()->getType()); |
|
|
|
|
|
|
156
|
|
|
self::assertEquals( |
|
157
|
|
|
['allocationSize' => 1, 'sequenceName' => 'foo'], |
|
158
|
|
|
$class->getProperty('id')->getValueGenerator()->getDefinition() |
|
|
|
|
|
|
159
|
|
|
); |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* @group DDC-1156 |
|
164
|
|
|
* @group DDC-1218 |
|
165
|
|
|
*/ |
|
166
|
|
View Code Duplication |
public function testSequenceDefinitionInHierarchyWithSandwichMappedSuperclass() |
|
167
|
|
|
{ |
|
168
|
|
|
/* @var ClassMetadata $class */ |
|
169
|
|
|
$class = $this->cmf->getMetadataFor(HierarchyD::class); |
|
170
|
|
|
|
|
171
|
|
|
self::assertSame(GeneratorType::SEQUENCE, $class->getProperty('id')->getValueGenerator()->getType()); |
|
|
|
|
|
|
172
|
|
|
self::assertEquals( |
|
173
|
|
|
['allocationSize' => 1, 'sequenceName' => 'foo'], |
|
174
|
|
|
$class->getProperty('id')->getValueGenerator()->getDefinition() |
|
|
|
|
|
|
175
|
|
|
); |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
/** |
|
179
|
|
|
* @group DDC-1156 |
|
180
|
|
|
* @group DDC-1218 |
|
181
|
|
|
*/ |
|
182
|
|
View Code Duplication |
public function testMultipleMappedSuperclasses() |
|
183
|
|
|
{ |
|
184
|
|
|
/* @var ClassMetadata $class */ |
|
185
|
|
|
$class = $this->cmf->getMetadataFor(MediumSuperclassEntity::class); |
|
186
|
|
|
|
|
187
|
|
|
self::assertSame(GeneratorType::SEQUENCE, $class->getProperty('id')->getValueGenerator()->getType()); |
|
|
|
|
|
|
188
|
|
|
self::assertEquals( |
|
189
|
|
|
['allocationSize' => 1, 'sequenceName' => 'foo'], |
|
190
|
|
|
$class->getProperty('id')->getValueGenerator()->getDefinition() |
|
|
|
|
|
|
191
|
|
|
); |
|
192
|
|
|
} |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
class TransientBaseClass { |
|
196
|
|
|
private $transient1; |
|
|
|
|
|
|
197
|
|
|
private $transient2; |
|
|
|
|
|
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
/** @ORM\Entity */ |
|
201
|
|
|
class EntitySubClass extends TransientBaseClass |
|
202
|
|
|
{ |
|
203
|
|
|
/** @ORM\Id @ORM\Column(type="integer") */ |
|
204
|
|
|
private $id; |
|
|
|
|
|
|
205
|
|
|
/** @ORM\Column(type="string") */ |
|
206
|
|
|
private $name; |
|
|
|
|
|
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
/** @ORM\MappedSuperclass */ |
|
210
|
|
|
class MappedSuperclassBase { |
|
211
|
|
|
/** @ORM\Column(type="integer") */ |
|
212
|
|
|
private $mapped1; |
|
|
|
|
|
|
213
|
|
|
/** @ORM\Column(type="string") */ |
|
214
|
|
|
private $mapped2; |
|
|
|
|
|
|
215
|
|
|
/** |
|
216
|
|
|
* @ORM\OneToOne(targetEntity="MappedSuperclassRelated1") |
|
217
|
|
|
* @ORM\JoinColumn(name="related1_id", referencedColumnName="id") |
|
218
|
|
|
*/ |
|
219
|
|
|
private $mappedRelated1; |
|
|
|
|
|
|
220
|
|
|
private $transient; |
|
|
|
|
|
|
221
|
|
|
} |
|
222
|
|
|
class MappedSuperclassRelated1 {} |
|
223
|
|
|
|
|
224
|
|
|
/** @ORM\Entity */ |
|
225
|
|
|
class EntitySubClass2 extends MappedSuperclassBase { |
|
226
|
|
|
/** @ORM\Id @ORM\Column(type="integer") */ |
|
227
|
|
|
private $id; |
|
|
|
|
|
|
228
|
|
|
/** @ORM\Column(type="string") */ |
|
229
|
|
|
private $name; |
|
|
|
|
|
|
230
|
|
|
} |
|
231
|
|
|
|
|
232
|
|
|
/** |
|
233
|
|
|
* @ORM\MappedSuperclass |
|
234
|
|
|
*/ |
|
235
|
|
|
class MappedSuperclassBaseIndex { |
|
236
|
|
|
/** @ORM\Column(type="string") */ |
|
237
|
|
|
private $mapped1; |
|
|
|
|
|
|
238
|
|
|
/** @ORM\Column(type="string") */ |
|
239
|
|
|
private $mapped2; |
|
|
|
|
|
|
240
|
|
|
} |
|
241
|
|
|
|
|
242
|
|
|
/** @ORM\Entity @ORM\Table(uniqueConstraints={@ORM\UniqueConstraint(name="IDX_NAME_INDEX",columns={"name"})}) */ |
|
243
|
|
|
class EntityIndexSubClass extends MappedSuperclassBaseIndex |
|
244
|
|
|
{ |
|
245
|
|
|
/** @ORM\Id @ORM\Column(type="integer") */ |
|
246
|
|
|
private $id; |
|
|
|
|
|
|
247
|
|
|
/** @ORM\Column(type="string") */ |
|
248
|
|
|
private $name; |
|
|
|
|
|
|
249
|
|
|
} |
|
250
|
|
|
|
|
251
|
|
|
/** |
|
252
|
|
|
* @ORM\Entity |
|
253
|
|
|
* @ORM\InheritanceType("SINGLE_TABLE") |
|
254
|
|
|
* @ORM\DiscriminatorColumn(name="type", type="string", length=20) |
|
255
|
|
|
* @ORM\DiscriminatorMap({ |
|
256
|
|
|
* "c" = "HierarchyC", |
|
257
|
|
|
* "d" = "HierarchyD", |
|
258
|
|
|
* "e" = "HierarchyE" |
|
259
|
|
|
* }) |
|
260
|
|
|
*/ |
|
261
|
|
|
abstract class HierarchyBase |
|
262
|
|
|
{ |
|
263
|
|
|
/** |
|
264
|
|
|
* @ORM\Column(type="integer") @ORM\Id @ORM\GeneratedValue(strategy="SEQUENCE") |
|
265
|
|
|
* @ORM\SequenceGenerator(sequenceName="foo") |
|
266
|
|
|
* @var int |
|
267
|
|
|
*/ |
|
268
|
|
|
public $id; |
|
269
|
|
|
} |
|
270
|
|
|
|
|
271
|
|
|
/** @ORM\MappedSuperclass */ |
|
272
|
|
|
abstract class HierarchyASuperclass extends HierarchyBase |
|
273
|
|
|
{ |
|
274
|
|
|
/** @ORM\Column(type="string") */ |
|
275
|
|
|
public $a; |
|
276
|
|
|
} |
|
277
|
|
|
|
|
278
|
|
|
/** @ORM\Entity */ |
|
279
|
|
|
class HierarchyBEntity extends HierarchyBase |
|
280
|
|
|
{ |
|
281
|
|
|
/** @ORM\Column(type="string") */ |
|
282
|
|
|
public $b; |
|
283
|
|
|
} |
|
284
|
|
|
|
|
285
|
|
|
/** @ORM\Entity */ |
|
286
|
|
|
class HierarchyC extends HierarchyBase |
|
287
|
|
|
{ |
|
288
|
|
|
/** @ORM\Column(type="string") */ |
|
289
|
|
|
public $c; |
|
290
|
|
|
} |
|
291
|
|
|
|
|
292
|
|
|
/** @ORM\Entity */ |
|
293
|
|
|
class HierarchyD extends HierarchyASuperclass |
|
294
|
|
|
{ |
|
295
|
|
|
/** @ORM\Column(type="string") */ |
|
296
|
|
|
public $d; |
|
297
|
|
|
} |
|
298
|
|
|
|
|
299
|
|
|
/** @ORM\Entity */ |
|
300
|
|
|
class HierarchyE extends HierarchyBEntity |
|
301
|
|
|
{ |
|
302
|
|
|
/** @ORM\Column(type="string") */ |
|
303
|
|
|
public $e; |
|
304
|
|
|
} |
|
305
|
|
|
|
|
306
|
|
|
/** @ORM\Entity */ |
|
307
|
|
|
class SuperclassEntity extends SuperclassBase |
|
308
|
|
|
{ |
|
309
|
|
|
} |
|
310
|
|
|
|
|
311
|
|
|
/** @ORM\MappedSuperclass */ |
|
312
|
|
|
abstract class SuperclassBase |
|
313
|
|
|
{ |
|
314
|
|
|
/** |
|
315
|
|
|
* @ORM\Column(type="integer") @ORM\Id @ORM\GeneratedValue(strategy="SEQUENCE") |
|
316
|
|
|
* @ORM\SequenceGenerator(sequenceName="foo") |
|
317
|
|
|
*/ |
|
318
|
|
|
public $id; |
|
319
|
|
|
} |
|
320
|
|
|
|
|
321
|
|
|
/** @ORM\MappedSuperclass */ |
|
322
|
|
|
abstract class MediumSuperclassBase extends SuperclassBase |
|
323
|
|
|
{ |
|
324
|
|
|
} |
|
325
|
|
|
|
|
326
|
|
|
/** @ORM\Entity */ |
|
327
|
|
|
class MediumSuperclassEntity extends MediumSuperclassBase |
|
328
|
|
|
{ |
|
329
|
|
|
} |
|
330
|
|
|
|
|
331
|
|
|
/** @ORM\Entity(repositoryClass = "Doctrine\ORM\EntityRepository") */ |
|
332
|
|
|
class SubclassWithRepository extends DDC869Payment |
|
333
|
|
|
{ |
|
334
|
|
|
} |
|
335
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.