|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Doctrine\Tests\ORM\Mapping; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\DBAL\Types\Type; |
|
8
|
|
|
use Doctrine\ORM\Events; |
|
9
|
|
|
use Doctrine\ORM\Mapping; |
|
10
|
|
|
use Doctrine\ORM\Mapping\ClassMetadata; |
|
11
|
|
|
use Doctrine\ORM\Mapping\DiscriminatorColumnMetadata; |
|
12
|
|
|
use Doctrine\ORM\Mapping\Factory\DefaultNamingStrategy; |
|
13
|
|
|
use Doctrine\ORM\Mapping\JoinColumnMetadata; |
|
14
|
|
|
use Doctrine\ORM\Mapping\MappingException; |
|
15
|
|
|
use Doctrine\ORM\Reflection\RuntimeReflectionService; |
|
16
|
|
|
use Doctrine\ORM\Reflection\StaticReflectionService; |
|
17
|
|
|
use Doctrine\Tests\Models\CMS; |
|
18
|
|
|
use Doctrine\Tests\Models\Company\CompanyContract; |
|
19
|
|
|
use Doctrine\Tests\Models\Company\CompanyContractListener; |
|
20
|
|
|
use Doctrine\Tests\Models\CustomType\CustomTypeParent; |
|
21
|
|
|
use Doctrine\Tests\Models\DDC117\DDC117Article; |
|
22
|
|
|
use Doctrine\Tests\Models\DDC117\DDC117ArticleDetails; |
|
23
|
|
|
use Doctrine\Tests\Models\DDC6412\DDC6412File; |
|
24
|
|
|
use Doctrine\Tests\Models\DDC964\DDC964Address; |
|
25
|
|
|
use Doctrine\Tests\Models\DDC964\DDC964Admin; |
|
26
|
|
|
use Doctrine\Tests\Models\DDC964\DDC964Guest; |
|
27
|
|
|
use Doctrine\Tests\OrmTestCase; |
|
28
|
|
|
use DoctrineGlobalArticle; |
|
29
|
|
|
use ReflectionClass; |
|
30
|
|
|
use stdClass; |
|
31
|
|
|
use function reset; |
|
32
|
|
|
use function serialize; |
|
33
|
|
|
use function str_replace; |
|
34
|
|
|
use function strpos; |
|
35
|
|
|
use function strtolower; |
|
36
|
|
|
use function strtoupper; |
|
37
|
|
|
use function unserialize; |
|
38
|
|
|
|
|
39
|
|
|
require_once __DIR__ . '/../../Models/Global/GlobalNamespaceModel.php'; |
|
40
|
|
|
|
|
41
|
|
|
class ClassMetadataTest extends OrmTestCase |
|
42
|
|
|
{ |
|
43
|
|
|
public function testClassMetadataInstanceSimpleState() : void |
|
44
|
|
|
{ |
|
45
|
|
|
$cm = new ClassMetadata(CMS\CmsUser::class, null); |
|
46
|
|
|
$cm->setTable(new Mapping\TableMetadata('cms_users')); |
|
47
|
|
|
|
|
48
|
|
|
self::assertEquals(CMS\CmsUser::class, $cm->getClassName()); |
|
49
|
|
|
self::assertEquals(CMS\CmsUser::class, $cm->getRootClassName()); |
|
50
|
|
|
self::assertEquals([], $cm->getSubClasses()); |
|
51
|
|
|
self::assertCount(0, $cm->getAncestorsIterator()); |
|
52
|
|
|
self::assertEquals(Mapping\InheritanceType::NONE, $cm->inheritanceType); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function testClassMetadataInstanceSerialization() : void |
|
56
|
|
|
{ |
|
57
|
|
|
$parent = new ClassMetadata(CMS\CmsEmployee::class, null); |
|
58
|
|
|
$parent->setTable(new Mapping\TableMetadata('cms_employee')); |
|
59
|
|
|
|
|
60
|
|
|
$cm = new ClassMetadata(CMS\CmsUser::class, $parent); |
|
61
|
|
|
$cm->setTable($parent->table); |
|
62
|
|
|
$cm->setParent($parent); |
|
63
|
|
|
|
|
64
|
|
|
$discrColumn = new DiscriminatorColumnMetadata(); |
|
65
|
|
|
|
|
66
|
|
|
$discrColumn->setColumnName('disc'); |
|
67
|
|
|
$discrColumn->setType(Type::getType('integer')); |
|
68
|
|
|
|
|
69
|
|
|
$cm->setInheritanceType(Mapping\InheritanceType::SINGLE_TABLE); |
|
|
|
|
|
|
70
|
|
|
$cm->setSubclasses([ |
|
71
|
|
|
'Doctrine\Tests\Models\CMS\One', |
|
72
|
|
|
'Doctrine\Tests\Models\CMS\Two', |
|
73
|
|
|
'Doctrine\Tests\Models\CMS\Three', |
|
74
|
|
|
]); |
|
75
|
|
|
$cm->setCustomRepositoryClassName('Doctrine\Tests\Models\CMS\UserRepository'); |
|
76
|
|
|
$cm->setDiscriminatorColumn($discrColumn); |
|
77
|
|
|
$cm->asReadOnly(); |
|
78
|
|
|
|
|
79
|
|
|
$association = new Mapping\OneToOneAssociationMetadata('phonenumbers'); |
|
80
|
|
|
|
|
81
|
|
|
$association->setTargetEntity(CMS\CmsAddress::class); |
|
82
|
|
|
$association->setMappedBy('foo'); |
|
83
|
|
|
|
|
84
|
|
|
$cm->addProperty($association); |
|
85
|
|
|
|
|
86
|
|
|
self::assertCount(1, $cm->getPropertiesIterator()); |
|
87
|
|
|
|
|
88
|
|
|
$serialized = serialize($cm); |
|
89
|
|
|
$cm = unserialize($serialized); |
|
90
|
|
|
|
|
91
|
|
|
$cm->wakeupReflection(new RuntimeReflectionService()); |
|
92
|
|
|
|
|
93
|
|
|
// Check state |
|
94
|
|
|
self::assertInstanceOf(ReflectionClass::class, $cm->getReflectionClass()); |
|
95
|
|
|
self::assertEquals(CMS\CmsUser::class, $cm->getClassName()); |
|
96
|
|
|
self::assertEquals(CMS\CmsEmployee::class, $cm->getRootClassName()); |
|
97
|
|
|
self::assertEquals('Doctrine\Tests\Models\CMS\UserRepository', $cm->getCustomRepositoryClassName()); |
|
98
|
|
|
self::assertEquals( |
|
99
|
|
|
[ |
|
100
|
|
|
'Doctrine\Tests\Models\CMS\One', |
|
101
|
|
|
'Doctrine\Tests\Models\CMS\Two', |
|
102
|
|
|
'Doctrine\Tests\Models\CMS\Three', |
|
103
|
|
|
], |
|
104
|
|
|
$cm->getSubClasses() |
|
105
|
|
|
); |
|
106
|
|
|
self::assertCount(1, $cm->getAncestorsIterator()); |
|
107
|
|
|
self::assertEquals(CMS\CmsEmployee::class, $cm->getAncestorsIterator()->current()->getClassName()); |
|
108
|
|
|
self::assertEquals($discrColumn, $cm->discriminatorColumn); |
|
109
|
|
|
self::assertTrue($cm->isReadOnly()); |
|
110
|
|
|
self::assertCount(1, $cm->getPropertiesIterator()); |
|
111
|
|
|
self::assertInstanceOf(Mapping\OneToOneAssociationMetadata::class, $cm->getProperty('phonenumbers')); |
|
112
|
|
|
|
|
113
|
|
|
$oneOneMapping = $cm->getProperty('phonenumbers'); |
|
114
|
|
|
|
|
115
|
|
|
self::assertEquals(Mapping\FetchMode::LAZY, $oneOneMapping->getFetchMode()); |
|
116
|
|
|
self::assertEquals(CMS\CmsAddress::class, $oneOneMapping->getTargetEntity()); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
public function testFieldIsNullable() : void |
|
120
|
|
|
{ |
|
121
|
|
|
$metadata = new ClassMetadata(CMS\CmsUser::class, null); |
|
122
|
|
|
$metadata->setTable(new Mapping\TableMetadata('cms_users')); |
|
123
|
|
|
|
|
124
|
|
|
// Explicit Nullable |
|
125
|
|
|
$fieldMetadata = new Mapping\FieldMetadata('status'); |
|
126
|
|
|
|
|
127
|
|
|
$fieldMetadata->setType(Type::getType('string')); |
|
128
|
|
|
$fieldMetadata->setLength(50); |
|
129
|
|
|
$fieldMetadata->setNullable(true); |
|
130
|
|
|
|
|
131
|
|
|
$metadata->addProperty($fieldMetadata); |
|
132
|
|
|
|
|
133
|
|
|
$property = $metadata->getProperty('status'); |
|
134
|
|
|
|
|
135
|
|
|
self::assertTrue($property->isNullable()); |
|
|
|
|
|
|
136
|
|
|
|
|
137
|
|
|
// Explicit Not Nullable |
|
138
|
|
|
$fieldMetadata = new Mapping\FieldMetadata('username'); |
|
139
|
|
|
|
|
140
|
|
|
$fieldMetadata->setType(Type::getType('string')); |
|
141
|
|
|
$fieldMetadata->setLength(50); |
|
142
|
|
|
$fieldMetadata->setNullable(false); |
|
143
|
|
|
|
|
144
|
|
|
$metadata->addProperty($fieldMetadata); |
|
145
|
|
|
|
|
146
|
|
|
$property = $metadata->getProperty('username'); |
|
147
|
|
|
|
|
148
|
|
|
self::assertFalse($property->isNullable()); |
|
149
|
|
|
|
|
150
|
|
|
// Implicit Not Nullable |
|
151
|
|
|
$fieldMetadata = new Mapping\FieldMetadata('name'); |
|
152
|
|
|
|
|
153
|
|
|
$fieldMetadata->setType(Type::getType('string')); |
|
154
|
|
|
$fieldMetadata->setLength(50); |
|
155
|
|
|
|
|
156
|
|
|
$metadata->addProperty($fieldMetadata); |
|
157
|
|
|
|
|
158
|
|
|
$property = $metadata->getProperty('name'); |
|
159
|
|
|
|
|
160
|
|
|
self::assertFalse($property->isNullable(), 'By default a field should not be nullable.'); |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* @group DDC-115 |
|
165
|
|
|
*/ |
|
166
|
|
|
public function testMapAssociationInGlobalNamespace() : void |
|
167
|
|
|
{ |
|
168
|
|
|
require_once __DIR__ . '/../../Models/Global/GlobalNamespaceModel.php'; |
|
169
|
|
|
|
|
170
|
|
|
$cm = new ClassMetadata(DoctrineGlobalArticle::class, null); |
|
171
|
|
|
$cm->setTable(new Mapping\TableMetadata('doctrine_global_article')); |
|
172
|
|
|
|
|
173
|
|
|
$joinTable = new Mapping\JoinTableMetadata(); |
|
174
|
|
|
$joinTable->setName('bar'); |
|
175
|
|
|
|
|
176
|
|
|
$joinColumn = new Mapping\JoinColumnMetadata(); |
|
177
|
|
|
$joinColumn->setColumnName('bar_id'); |
|
178
|
|
|
$joinColumn->setReferencedColumnName('id'); |
|
179
|
|
|
|
|
180
|
|
|
$joinTable->addJoinColumn($joinColumn); |
|
181
|
|
|
|
|
182
|
|
|
$joinColumn = new Mapping\JoinColumnMetadata(); |
|
183
|
|
|
$joinColumn->setColumnName('baz_id'); |
|
184
|
|
|
$joinColumn->setReferencedColumnName('id'); |
|
185
|
|
|
|
|
186
|
|
|
$joinTable->addInverseJoinColumn($joinColumn); |
|
187
|
|
|
|
|
188
|
|
|
$association = new Mapping\ManyToManyAssociationMetadata('author'); |
|
189
|
|
|
|
|
190
|
|
|
$association->setJoinTable($joinTable); |
|
191
|
|
|
$association->setTargetEntity('DoctrineGlobalUser'); |
|
192
|
|
|
|
|
193
|
|
|
$cm->addProperty($association); |
|
194
|
|
|
|
|
195
|
|
|
self::assertEquals('DoctrineGlobalUser', $cm->getProperty('author')->getTargetEntity()); |
|
|
|
|
|
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
public function testMapManyToManyJoinTableDefaults() : void |
|
199
|
|
|
{ |
|
200
|
|
|
$this->markTestIncomplete('This test needs to be moved to JoinTableMetadataBuilderTest'); |
|
201
|
|
|
|
|
202
|
|
|
$cm = new ClassMetadata(CMS\CmsUser::class, null); |
|
203
|
|
|
$cm->setTable(new Mapping\TableMetadata('cms_users')); |
|
204
|
|
|
|
|
205
|
|
|
$association = new Mapping\ManyToManyAssociationMetadata('groups'); |
|
206
|
|
|
|
|
207
|
|
|
$association->setTargetEntity(CMS\CmsGroup::class); |
|
208
|
|
|
|
|
209
|
|
|
$cm->addProperty($association); |
|
210
|
|
|
|
|
211
|
|
|
$association = $cm->getProperty('groups'); |
|
212
|
|
|
|
|
213
|
|
|
$joinColumns = []; |
|
214
|
|
|
|
|
215
|
|
|
$joinColumn = new Mapping\JoinColumnMetadata(); |
|
216
|
|
|
|
|
217
|
|
|
$joinColumn->setColumnName('cmsuser_id'); |
|
218
|
|
|
$joinColumn->setReferencedColumnName('id'); |
|
219
|
|
|
$joinColumn->setOnDelete('CASCADE'); |
|
220
|
|
|
|
|
221
|
|
|
$joinColumns[] = $joinColumn; |
|
222
|
|
|
|
|
223
|
|
|
$inverseJoinColumns = []; |
|
224
|
|
|
|
|
225
|
|
|
$joinColumn = new Mapping\JoinColumnMetadata(); |
|
226
|
|
|
|
|
227
|
|
|
$joinColumn->setColumnName('cmsgroup_id'); |
|
228
|
|
|
$joinColumn->setReferencedColumnName('id'); |
|
229
|
|
|
$joinColumn->setOnDelete('CASCADE'); |
|
230
|
|
|
|
|
231
|
|
|
$inverseJoinColumns[] = $joinColumn; |
|
232
|
|
|
|
|
233
|
|
|
$joinTable = $association->getJoinTable(); |
|
234
|
|
|
|
|
235
|
|
|
self::assertEquals('cmsuser_cmsgroup', $joinTable->getName()); |
|
236
|
|
|
self::assertEquals($joinColumns, $joinTable->getJoinColumns()); |
|
237
|
|
|
self::assertEquals($inverseJoinColumns, $joinTable->getInverseJoinColumns()); |
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
public function testSerializeManyToManyJoinTableCascade() : void |
|
241
|
|
|
{ |
|
242
|
|
|
$this->markTestIncomplete('This test needs to be moved to JoinTableMetadataBuilderTest'); |
|
243
|
|
|
|
|
244
|
|
|
$cm = new ClassMetadata(CMS\CmsUser::class, null); |
|
245
|
|
|
$cm->setTable(new Mapping\TableMetadata('cms_users')); |
|
246
|
|
|
|
|
247
|
|
|
$association = new Mapping\ManyToManyAssociationMetadata('groups'); |
|
248
|
|
|
|
|
249
|
|
|
$association->setTargetEntity(CMS\CmsGroup::class); |
|
250
|
|
|
|
|
251
|
|
|
$cm->addProperty($association); |
|
252
|
|
|
|
|
253
|
|
|
$association = $cm->getProperty('groups'); |
|
254
|
|
|
$association = unserialize(serialize($association)); |
|
255
|
|
|
|
|
256
|
|
|
$joinTable = $association->getJoinTable(); |
|
257
|
|
|
|
|
258
|
|
|
foreach ($joinTable->getJoinColumns() as $joinColumn) { |
|
259
|
|
|
self::assertEquals('CASCADE', $joinColumn->getOnDelete()); |
|
260
|
|
|
} |
|
261
|
|
|
} |
|
262
|
|
|
|
|
263
|
|
|
/** |
|
264
|
|
|
* @group DDC-115 |
|
265
|
|
|
*/ |
|
266
|
|
|
public function testSetDiscriminatorMapInGlobalNamespace() : void |
|
267
|
|
|
{ |
|
268
|
|
|
require_once __DIR__ . '/../../Models/Global/GlobalNamespaceModel.php'; |
|
269
|
|
|
|
|
270
|
|
|
$cm = new ClassMetadata('DoctrineGlobalUser', null); |
|
271
|
|
|
$cm->setTable(new Mapping\TableMetadata('doctrine_global_user')); |
|
272
|
|
|
|
|
273
|
|
|
$cm->setDiscriminatorMap(['descr' => 'DoctrineGlobalArticle', 'foo' => 'DoctrineGlobalUser']); |
|
274
|
|
|
|
|
275
|
|
|
self::assertEquals('DoctrineGlobalArticle', $cm->discriminatorMap['descr']); |
|
276
|
|
|
self::assertEquals('DoctrineGlobalUser', $cm->discriminatorMap['foo']); |
|
277
|
|
|
} |
|
278
|
|
|
|
|
279
|
|
|
/** |
|
280
|
|
|
* @group DDC-115 |
|
281
|
|
|
*/ |
|
282
|
|
|
public function testSetSubClassesInGlobalNamespace() : void |
|
283
|
|
|
{ |
|
284
|
|
|
require_once __DIR__ . '/../../Models/Global/GlobalNamespaceModel.php'; |
|
285
|
|
|
|
|
286
|
|
|
$cm = new ClassMetadata('DoctrineGlobalUser', null); |
|
287
|
|
|
$cm->setTable(new Mapping\TableMetadata('doctrine_global_user')); |
|
288
|
|
|
|
|
289
|
|
|
$cm->setSubclasses(['DoctrineGlobalArticle']); |
|
290
|
|
|
|
|
291
|
|
|
self::assertEquals('DoctrineGlobalArticle', $cm->getSubClasses()[0]); |
|
292
|
|
|
} |
|
293
|
|
|
|
|
294
|
|
|
/** |
|
295
|
|
|
* @group DDC-268 |
|
296
|
|
|
*/ |
|
297
|
|
|
public function testSetInvalidVersionMappingThrowsException() : void |
|
298
|
|
|
{ |
|
299
|
|
|
$this->markTestIncomplete('This test needs to be moved to FieldMetadataBuilderTest'); |
|
300
|
|
|
|
|
301
|
|
|
$cm = new ClassMetadata(CMS\CmsUser::class, null); |
|
302
|
|
|
$cm->setTable(new Mapping\TableMetadata('cms_users')); |
|
303
|
|
|
|
|
304
|
|
|
$property = new Mapping\FieldMetadata('foo'); |
|
305
|
|
|
|
|
306
|
|
|
$property->setDeclaringClass($cm); |
|
307
|
|
|
$property->setColumnName('foo'); |
|
308
|
|
|
$property->setType(Type::getType('string')); |
|
309
|
|
|
$property->setVersioned(true); |
|
310
|
|
|
|
|
311
|
|
|
$this->expectException(MappingException::class); |
|
312
|
|
|
|
|
313
|
|
|
$cm->addProperty($property); |
|
314
|
|
|
} |
|
315
|
|
|
|
|
316
|
|
|
public function testGetSingleIdentifierFieldNameMultipleIdentifierEntityThrowsException() : void |
|
317
|
|
|
{ |
|
318
|
|
|
$cm = new ClassMetadata(CMS\CmsUser::class, null); |
|
319
|
|
|
$cm->setTable(new Mapping\TableMetadata('cms_users')); |
|
320
|
|
|
|
|
321
|
|
|
$fieldMetadata = new Mapping\FieldMetadata('name'); |
|
322
|
|
|
$fieldMetadata->setType(Type::getType('string')); |
|
323
|
|
|
|
|
324
|
|
|
$cm->addProperty($fieldMetadata); |
|
325
|
|
|
|
|
326
|
|
|
$fieldMetadata = new Mapping\FieldMetadata('username'); |
|
327
|
|
|
$fieldMetadata->setType(Type::getType('string')); |
|
328
|
|
|
|
|
329
|
|
|
$cm->addProperty($fieldMetadata); |
|
330
|
|
|
|
|
331
|
|
|
$cm->setIdentifier(['name', 'username']); |
|
332
|
|
|
|
|
333
|
|
|
$this->expectException(MappingException::class); |
|
334
|
|
|
|
|
335
|
|
|
$cm->getSingleIdentifierFieldName(); |
|
336
|
|
|
} |
|
337
|
|
|
|
|
338
|
|
|
public function testGetSingleIdentifierFieldNameNoIdEntityThrowsException() : void |
|
339
|
|
|
{ |
|
340
|
|
|
$cm = new ClassMetadata(DDC6412File::class, null); |
|
341
|
|
|
$cm->setTable(new Mapping\TableMetadata('ddc6412_file')); |
|
342
|
|
|
|
|
343
|
|
|
$this->expectException(MappingException::class); |
|
344
|
|
|
|
|
345
|
|
|
$cm->getSingleIdentifierFieldName(); |
|
346
|
|
|
} |
|
347
|
|
|
|
|
348
|
|
|
public function testDuplicateAssociationMappingException() : void |
|
349
|
|
|
{ |
|
350
|
|
|
$cm = new ClassMetadata(CMS\CmsUser::class, null); |
|
351
|
|
|
$cm->setTable(new Mapping\TableMetadata('cms_users')); |
|
352
|
|
|
|
|
353
|
|
|
$association = new Mapping\OneToOneAssociationMetadata('foo'); |
|
354
|
|
|
|
|
355
|
|
|
$association->setDeclaringClass($cm); |
|
356
|
|
|
$association->setSourceEntity(stdClass::class); |
|
357
|
|
|
$association->setTargetEntity(stdClass::class); |
|
358
|
|
|
$association->setMappedBy('foo'); |
|
359
|
|
|
|
|
360
|
|
|
$cm->addInheritedProperty($association); |
|
361
|
|
|
|
|
362
|
|
|
$this->expectException(MappingException::class); |
|
363
|
|
|
|
|
364
|
|
|
$association = new Mapping\OneToOneAssociationMetadata('foo'); |
|
365
|
|
|
|
|
366
|
|
|
$association->setDeclaringClass($cm); |
|
367
|
|
|
$association->setSourceEntity(stdClass::class); |
|
368
|
|
|
$association->setTargetEntity(stdClass::class); |
|
369
|
|
|
$association->setMappedBy('foo'); |
|
370
|
|
|
|
|
371
|
|
|
$cm->addInheritedProperty($association); |
|
372
|
|
|
} |
|
373
|
|
|
|
|
374
|
|
|
public function testDuplicateColumnNameThrowsMappingException() : void |
|
375
|
|
|
{ |
|
376
|
|
|
$this->markTestIncomplete('This test needs to be moved to ClassMetadataBuilderTest'); |
|
377
|
|
|
|
|
378
|
|
|
$cm = new ClassMetadata(CMS\CmsUser::class, null); |
|
379
|
|
|
$cm->setTable(new Mapping\TableMetadata('cms_users')); |
|
380
|
|
|
|
|
381
|
|
|
$fieldMetadata = new Mapping\FieldMetadata('name'); |
|
382
|
|
|
|
|
383
|
|
|
$fieldMetadata->setType(Type::getType('string')); |
|
384
|
|
|
$fieldMetadata->setColumnName('name'); |
|
385
|
|
|
|
|
386
|
|
|
$cm->addProperty($fieldMetadata); |
|
387
|
|
|
|
|
388
|
|
|
self::assertTrue($cm->checkPropertyDuplication($fieldMetadata->getColumnName())); |
|
389
|
|
|
} |
|
390
|
|
|
|
|
391
|
|
|
public function testDuplicateColumnNameDiscriminatorColumnThrowsMappingException() : void |
|
392
|
|
|
{ |
|
393
|
|
|
$cm = new ClassMetadata(CMS\CmsUser::class, null); |
|
394
|
|
|
$cm->setTable(new Mapping\TableMetadata('cms_users')); |
|
395
|
|
|
|
|
396
|
|
|
$discrColumn = new DiscriminatorColumnMetadata(); |
|
397
|
|
|
|
|
398
|
|
|
$discrColumn->setColumnName('name'); |
|
399
|
|
|
$discrColumn->setType(Type::getType('string')); |
|
400
|
|
|
$discrColumn->setLength(255); |
|
401
|
|
|
|
|
402
|
|
|
$cm->setDiscriminatorColumn($discrColumn); |
|
403
|
|
|
|
|
404
|
|
|
self::assertTrue($cm->checkPropertyDuplication($discrColumn->getColumnName())); |
|
405
|
|
|
} |
|
406
|
|
|
|
|
407
|
|
|
public function testDuplicateFieldAndAssociationMapping1ThrowsException() : void |
|
408
|
|
|
{ |
|
409
|
|
|
$cm = new ClassMetadata(CMS\CmsUser::class, null); |
|
410
|
|
|
$cm->setTable(new Mapping\TableMetadata('cms_users')); |
|
411
|
|
|
|
|
412
|
|
|
$fieldMetadata = new Mapping\FieldMetadata('name'); |
|
413
|
|
|
|
|
414
|
|
|
$fieldMetadata->setType(Type::getType('string')); |
|
415
|
|
|
|
|
416
|
|
|
$cm->addProperty($fieldMetadata); |
|
417
|
|
|
|
|
418
|
|
|
$this->expectException(MappingException::class); |
|
419
|
|
|
|
|
420
|
|
|
$association = new Mapping\OneToOneAssociationMetadata('name'); |
|
421
|
|
|
|
|
422
|
|
|
$association->setTargetEntity(CMS\CmsUser::class); |
|
423
|
|
|
|
|
424
|
|
|
$cm->addProperty($association); |
|
425
|
|
|
} |
|
426
|
|
|
|
|
427
|
|
|
public function testDuplicateFieldAndAssociationMapping2ThrowsException() : void |
|
428
|
|
|
{ |
|
429
|
|
|
$cm = new ClassMetadata(CMS\CmsUser::class, null); |
|
430
|
|
|
$cm->setTable(new Mapping\TableMetadata('cms_users')); |
|
431
|
|
|
|
|
432
|
|
|
$association = new Mapping\OneToOneAssociationMetadata('name'); |
|
433
|
|
|
|
|
434
|
|
|
$association->setTargetEntity(CMS\CmsUser::class); |
|
435
|
|
|
|
|
436
|
|
|
$cm->addProperty($association); |
|
437
|
|
|
|
|
438
|
|
|
$this->expectException(MappingException::class); |
|
439
|
|
|
|
|
440
|
|
|
$fieldMetadata = new Mapping\FieldMetadata('name'); |
|
441
|
|
|
|
|
442
|
|
|
$fieldMetadata->setType(Type::getType('string')); |
|
443
|
|
|
|
|
444
|
|
|
$cm->addProperty($fieldMetadata); |
|
445
|
|
|
} |
|
446
|
|
|
|
|
447
|
|
|
/** |
|
448
|
|
|
* @group DDC-1224 |
|
449
|
|
|
*/ |
|
450
|
|
|
public function testGetTemporaryTableNameSchema() : void |
|
451
|
|
|
{ |
|
452
|
|
|
$cm = new ClassMetadata(CMS\CmsUser::class, null); |
|
453
|
|
|
$cm->setTable(new Mapping\TableMetadata('cms_users')); |
|
454
|
|
|
|
|
455
|
|
|
$tableMetadata = new Mapping\TableMetadata(); |
|
456
|
|
|
|
|
457
|
|
|
$tableMetadata->setSchema('foo'); |
|
458
|
|
|
$tableMetadata->setName('bar'); |
|
459
|
|
|
|
|
460
|
|
|
$cm->setTable($tableMetadata); |
|
461
|
|
|
|
|
462
|
|
|
self::assertEquals('foo_bar_id_tmp', $cm->getTemporaryIdTableName()); |
|
463
|
|
|
} |
|
464
|
|
|
|
|
465
|
|
|
public function testDefaultTableName() : void |
|
466
|
|
|
{ |
|
467
|
|
|
$this->markTestIncomplete('This test needs to be moved to JoinTableMetadataBuilderTest'); |
|
468
|
|
|
|
|
469
|
|
|
$cm = new ClassMetadata(CMS\CmsUser::class, null); |
|
470
|
|
|
$cm->setTable(new Mapping\TableMetadata('CmsUser')); |
|
471
|
|
|
|
|
472
|
|
|
// When table's name is not given |
|
473
|
|
|
self::assertEquals('CmsUser', $cm->getTableName()); |
|
474
|
|
|
self::assertEquals('CmsUser', $cm->table->getName()); |
|
475
|
|
|
|
|
476
|
|
|
$cm = new ClassMetadata(CMS\CmsAddress::class, null); |
|
477
|
|
|
|
|
478
|
|
|
// When joinTable's name is not given |
|
479
|
|
|
$joinTable = new Mapping\JoinTableMetadata(); |
|
480
|
|
|
|
|
481
|
|
|
$joinColumn = new Mapping\JoinColumnMetadata(); |
|
482
|
|
|
$joinColumn->setReferencedColumnName('id'); |
|
483
|
|
|
|
|
484
|
|
|
$joinTable->addJoinColumn($joinColumn); |
|
485
|
|
|
|
|
486
|
|
|
$joinColumn = new Mapping\JoinColumnMetadata(); |
|
487
|
|
|
$joinColumn->setReferencedColumnName('id'); |
|
488
|
|
|
|
|
489
|
|
|
$joinTable->addInverseJoinColumn($joinColumn); |
|
490
|
|
|
|
|
491
|
|
|
$association = new Mapping\ManyToManyAssociationMetadata('user'); |
|
492
|
|
|
|
|
493
|
|
|
$association->setJoinTable($joinTable); |
|
494
|
|
|
$association->setTargetEntity(CMS\CmsUser::class); |
|
495
|
|
|
$association->setInversedBy('users'); |
|
496
|
|
|
|
|
497
|
|
|
$cm->addProperty($association); |
|
498
|
|
|
|
|
499
|
|
|
$association = $cm->getProperty('user'); |
|
500
|
|
|
|
|
501
|
|
|
self::assertEquals('cmsaddress_cmsuser', $association->getJoinTable()->getName()); |
|
502
|
|
|
} |
|
503
|
|
|
|
|
504
|
|
|
public function testDefaultJoinColumnName() : void |
|
505
|
|
|
{ |
|
506
|
|
|
$this->markTestIncomplete('This test needs to be moved to JoinColumnMetadataBuilderTest'); |
|
507
|
|
|
|
|
508
|
|
|
$cm = new ClassMetadata(CMS\CmsAddress::class, null); |
|
509
|
|
|
$cm->setTable(new Mapping\TableMetadata('cms_address')); |
|
510
|
|
|
|
|
511
|
|
|
// this is really dirty, but it's the simplest way to test whether |
|
512
|
|
|
// joinColumn's name will be automatically set to user_id |
|
513
|
|
|
$joinColumns = []; |
|
514
|
|
|
|
|
515
|
|
|
$joinColumn = new JoinColumnMetadata(); |
|
516
|
|
|
|
|
517
|
|
|
$joinColumn->setReferencedColumnName('id'); |
|
518
|
|
|
|
|
519
|
|
|
$joinColumns[] = $joinColumn; |
|
520
|
|
|
|
|
521
|
|
|
$association = new Mapping\OneToOneAssociationMetadata('user'); |
|
522
|
|
|
|
|
523
|
|
|
$association->setJoinColumns($joinColumns); |
|
524
|
|
|
$association->setTargetEntity(CMS\CmsUser::class); |
|
525
|
|
|
|
|
526
|
|
|
$cm->addProperty($association); |
|
527
|
|
|
|
|
528
|
|
|
$association = $cm->getProperty('user'); |
|
529
|
|
|
$joinColumns = $association->getJoinColumns(); |
|
530
|
|
|
$joinColumn = reset($joinColumns); |
|
531
|
|
|
|
|
532
|
|
|
self::assertEquals('user_id', $joinColumn->getColumnName()); |
|
533
|
|
|
|
|
534
|
|
|
$cm = new ClassMetadata(CMS\CmsAddress::class, null); |
|
535
|
|
|
$cm->setTable(new Mapping\TableMetadata('cms_address')); |
|
536
|
|
|
|
|
537
|
|
|
$joinTable = new Mapping\JoinTableMetadata(); |
|
538
|
|
|
$joinTable->setName('user_CmsUser'); |
|
539
|
|
|
|
|
540
|
|
|
$joinColumn = new JoinColumnMetadata(); |
|
541
|
|
|
$joinColumn->setReferencedColumnName('id'); |
|
542
|
|
|
|
|
543
|
|
|
$joinTable->addJoinColumn($joinColumn); |
|
544
|
|
|
|
|
545
|
|
|
$joinColumn = new JoinColumnMetadata(); |
|
546
|
|
|
$joinColumn->setReferencedColumnName('id'); |
|
547
|
|
|
|
|
548
|
|
|
$joinTable->addInverseJoinColumn($joinColumn); |
|
549
|
|
|
|
|
550
|
|
|
$association = new Mapping\ManyToManyAssociationMetadata('user'); |
|
551
|
|
|
|
|
552
|
|
|
$association->setJoinTable($joinTable); |
|
553
|
|
|
$association->setTargetEntity(CMS\CmsUser::class); |
|
554
|
|
|
$association->setInversedBy('users'); |
|
555
|
|
|
|
|
556
|
|
|
$cm->addProperty($association); |
|
557
|
|
|
|
|
558
|
|
|
$association = $cm->getProperty('user'); |
|
559
|
|
|
$joinTable = $association->getJoinTable(); |
|
560
|
|
|
$joinColumns = $joinTable->getJoinColumns(); |
|
561
|
|
|
$joinColumn = reset($joinColumns); |
|
562
|
|
|
$inverseJoinColumns = $joinTable->getInverseJoinColumns(); |
|
563
|
|
|
$inverseJoinColumn = reset($inverseJoinColumns); |
|
564
|
|
|
|
|
565
|
|
|
self::assertEquals('cmsaddress_id', $joinColumn->getColumnName()); |
|
566
|
|
|
self::assertEquals('cmsuser_id', $inverseJoinColumn->getColumnName()); |
|
567
|
|
|
} |
|
568
|
|
|
|
|
569
|
|
|
/** |
|
570
|
|
|
* @group DDC-559 |
|
571
|
|
|
*/ |
|
572
|
|
|
public function testOneToOneUnderscoreNamingStrategyDefaults() : void |
|
573
|
|
|
{ |
|
574
|
|
|
$this->markTestIncomplete('This test needs to be moved to JoinColumnMetadataBuilderTest'); |
|
575
|
|
|
|
|
576
|
|
|
$metadata = new ClassMetadata(CMS\CmsAddress::class, null); |
|
577
|
|
|
$metadata->setTable(new Mapping\TableMetadata('cms_address')); |
|
578
|
|
|
|
|
579
|
|
|
$association = new Mapping\OneToOneAssociationMetadata('user'); |
|
580
|
|
|
|
|
581
|
|
|
$association->setTargetEntity(CMS\CmsUser::class); |
|
582
|
|
|
|
|
583
|
|
|
$metadata->addProperty($association); |
|
584
|
|
|
|
|
585
|
|
|
$association = $metadata->getProperty('user'); |
|
586
|
|
|
$joinColumns = $association->getJoinColumns(); |
|
587
|
|
|
$joinColumn = reset($joinColumns); |
|
588
|
|
|
|
|
589
|
|
|
self::assertEquals('USER_ID', $joinColumn->getColumnName()); |
|
590
|
|
|
self::assertEquals('ID', $joinColumn->getReferencedColumnName()); |
|
591
|
|
|
} |
|
592
|
|
|
|
|
593
|
|
|
/** |
|
594
|
|
|
* @group DDC-559 |
|
595
|
|
|
*/ |
|
596
|
|
|
public function testManyToManyUnderscoreNamingStrategyDefaults() : void |
|
597
|
|
|
{ |
|
598
|
|
|
$this->markTestIncomplete('This test needs to be moved to JoinTableMetadataBuilderTest'); |
|
599
|
|
|
|
|
600
|
|
|
$metadata = new ClassMetadata(CMS\CmsAddress::class, null); |
|
601
|
|
|
$metadata->setTable(new Mapping\TableMetadata('cms_address')); |
|
602
|
|
|
|
|
603
|
|
|
$association = new Mapping\ManyToManyAssociationMetadata('user'); |
|
604
|
|
|
|
|
605
|
|
|
$association->setTargetEntity(CMS\CmsUser::class); |
|
606
|
|
|
|
|
607
|
|
|
$metadata->addProperty($association); |
|
608
|
|
|
|
|
609
|
|
|
$association = $metadata->getProperty('user'); |
|
610
|
|
|
$joinTable = $association->getJoinTable(); |
|
611
|
|
|
$joinColumns = $joinTable->getJoinColumns(); |
|
612
|
|
|
$joinColumn = reset($joinColumns); |
|
613
|
|
|
$inverseJoinColumns = $joinTable->getInverseJoinColumns(); |
|
614
|
|
|
$inverseJoinColumn = reset($inverseJoinColumns); |
|
615
|
|
|
|
|
616
|
|
|
self::assertEquals('CMS_ADDRESS_CMS_USER', $joinTable->getName()); |
|
617
|
|
|
|
|
618
|
|
|
self::assertEquals('CMS_ADDRESS_ID', $joinColumn->getColumnName()); |
|
619
|
|
|
self::assertEquals('ID', $joinColumn->getReferencedColumnName()); |
|
620
|
|
|
|
|
621
|
|
|
self::assertEquals('CMS_USER_ID', $inverseJoinColumn->getColumnName()); |
|
622
|
|
|
self::assertEquals('ID', $inverseJoinColumn->getReferencedColumnName()); |
|
623
|
|
|
|
|
624
|
|
|
$cm = new ClassMetadata('DoctrineGlobalArticle', null); |
|
625
|
|
|
|
|
626
|
|
|
$association = new Mapping\ManyToManyAssociationMetadata('author'); |
|
627
|
|
|
|
|
628
|
|
|
$association->setTargetEntity(CMS\CmsUser::class); |
|
629
|
|
|
|
|
630
|
|
|
$cm->addProperty($association); |
|
631
|
|
|
|
|
632
|
|
|
$association = $cm->getProperty('author'); |
|
633
|
|
|
|
|
634
|
|
|
self::assertEquals('DOCTRINE_GLOBAL_ARTICLE_CMS_USER', $association->getJoinTable()->getName()); |
|
635
|
|
|
} |
|
636
|
|
|
|
|
637
|
|
|
/** |
|
638
|
|
|
* @group DDC-886 |
|
639
|
|
|
*/ |
|
640
|
|
|
public function testSetMultipleIdentifierSetsComposite() : void |
|
641
|
|
|
{ |
|
642
|
|
|
$cm = new ClassMetadata(CMS\CmsUser::class, null); |
|
643
|
|
|
$cm->setTable(new Mapping\TableMetadata('cms_users')); |
|
644
|
|
|
|
|
645
|
|
|
$fieldMetadata = new Mapping\FieldMetadata('name'); |
|
646
|
|
|
$fieldMetadata->setType(Type::getType('string')); |
|
647
|
|
|
|
|
648
|
|
|
$cm->addProperty($fieldMetadata); |
|
649
|
|
|
|
|
650
|
|
|
$fieldMetadata = new Mapping\FieldMetadata('username'); |
|
651
|
|
|
$fieldMetadata->setType(Type::getType('string')); |
|
652
|
|
|
|
|
653
|
|
|
$cm->addProperty($fieldMetadata); |
|
654
|
|
|
|
|
655
|
|
|
$cm->setIdentifier(['name', 'username']); |
|
656
|
|
|
|
|
657
|
|
|
self::assertTrue($cm->isIdentifierComposite()); |
|
658
|
|
|
} |
|
659
|
|
|
|
|
660
|
|
|
/** |
|
661
|
|
|
* @group DDC-961 |
|
662
|
|
|
*/ |
|
663
|
|
|
public function testJoinTableMappingDefaults() : void |
|
664
|
|
|
{ |
|
665
|
|
|
$this->markTestIncomplete('This test needs to be moved to JoinTableMetadataBuilderTest'); |
|
666
|
|
|
|
|
667
|
|
|
$cm = new ClassMetadata('DoctrineGlobalArticle', null); |
|
668
|
|
|
|
|
669
|
|
|
$association = new Mapping\ManyToManyAssociationMetadata('author'); |
|
670
|
|
|
|
|
671
|
|
|
$association->setTargetEntity(CMS\CmsUser::class); |
|
672
|
|
|
|
|
673
|
|
|
$cm->addProperty($association); |
|
674
|
|
|
|
|
675
|
|
|
$association = $cm->getProperty('author'); |
|
676
|
|
|
|
|
677
|
|
|
self::assertEquals('doctrineglobalarticle_cmsuser', $association->getJoinTable()->getName()); |
|
678
|
|
|
} |
|
679
|
|
|
|
|
680
|
|
|
/** |
|
681
|
|
|
* @group DDC-117 |
|
682
|
|
|
*/ |
|
683
|
|
|
public function testMapIdentifierAssociation() : void |
|
684
|
|
|
{ |
|
685
|
|
|
$cm = new ClassMetadata(DDC117ArticleDetails::class, null); |
|
686
|
|
|
$cm->setTable(new Mapping\TableMetadata('ddc117_article_details')); |
|
687
|
|
|
|
|
688
|
|
|
$association = new Mapping\OneToOneAssociationMetadata('article'); |
|
689
|
|
|
|
|
690
|
|
|
$association->setTargetEntity(DDC117Article::class); |
|
691
|
|
|
$association->setPrimaryKey(true); |
|
692
|
|
|
|
|
693
|
|
|
$cm->addProperty($association); |
|
694
|
|
|
|
|
695
|
|
|
self::assertEquals(['article'], $cm->identifier); |
|
696
|
|
|
} |
|
697
|
|
|
|
|
698
|
|
|
/** |
|
699
|
|
|
* @group DDC-117 |
|
700
|
|
|
*/ |
|
701
|
|
|
public function testOrphanRemovalIdentifierAssociation() : void |
|
702
|
|
|
{ |
|
703
|
|
|
$this->markTestIncomplete('This test needs to be moved to ClassMetadataBuilderTest'); |
|
704
|
|
|
|
|
705
|
|
|
$cm = new ClassMetadata(DDC117ArticleDetails::class, null); |
|
706
|
|
|
$cm->setTable(new Mapping\TableMetadata('ddc117_article_details')); |
|
707
|
|
|
|
|
708
|
|
|
$this->expectException(MappingException::class); |
|
709
|
|
|
$this->expectExceptionMessage('The orphan removal option is not allowed on an association that'); |
|
710
|
|
|
|
|
711
|
|
|
$association = new Mapping\OneToOneAssociationMetadata('article'); |
|
712
|
|
|
|
|
713
|
|
|
$association->setTargetEntity(DDC117Article::class); |
|
714
|
|
|
$association->setPrimaryKey(true); |
|
715
|
|
|
$association->setOrphanRemoval(true); |
|
716
|
|
|
|
|
717
|
|
|
$cm->addProperty($association); |
|
718
|
|
|
} |
|
719
|
|
|
|
|
720
|
|
|
/** |
|
721
|
|
|
* @group DDC-117 |
|
722
|
|
|
*/ |
|
723
|
|
|
public function testInverseIdentifierAssociation() : void |
|
724
|
|
|
{ |
|
725
|
|
|
$this->markTestIncomplete('This test needs to be moved to ClassMetadataBuilderTest'); |
|
726
|
|
|
|
|
727
|
|
|
$cm = new ClassMetadata(DDC117ArticleDetails::class, null); |
|
728
|
|
|
$cm->setTable(new Mapping\TableMetadata('ddc117_article_details')); |
|
729
|
|
|
|
|
730
|
|
|
$this->expectException(MappingException::class); |
|
731
|
|
|
$this->expectExceptionMessage('An inverse association is not allowed to be identifier in'); |
|
732
|
|
|
|
|
733
|
|
|
$association = new Mapping\OneToOneAssociationMetadata('article'); |
|
734
|
|
|
|
|
735
|
|
|
$association->setTargetEntity(DDC117Article::class); |
|
736
|
|
|
$association->setPrimaryKey(true); |
|
737
|
|
|
$association->setMappedBy('details'); |
|
738
|
|
|
$association->setOwningSide(false); |
|
739
|
|
|
|
|
740
|
|
|
$cm->addProperty($association); |
|
741
|
|
|
} |
|
742
|
|
|
|
|
743
|
|
|
/** |
|
744
|
|
|
* @group DDC-117 |
|
745
|
|
|
*/ |
|
746
|
|
|
public function testIdentifierAssociationManyToMany() : void |
|
747
|
|
|
{ |
|
748
|
|
|
$this->markTestIncomplete('This test needs to be moved to ClassMetadataBuilderTest'); |
|
749
|
|
|
|
|
750
|
|
|
$cm = new ClassMetadata(DDC117ArticleDetails::class, null); |
|
751
|
|
|
$cm->setTable(new Mapping\TableMetadata('ddc117_article_details')); |
|
752
|
|
|
|
|
753
|
|
|
$this->expectException(MappingException::class); |
|
754
|
|
|
$this->expectExceptionMessage('Many-to-many or one-to-many associations are not allowed to be identifier in'); |
|
755
|
|
|
|
|
756
|
|
|
$association = new Mapping\ManyToManyAssociationMetadata('article'); |
|
757
|
|
|
|
|
758
|
|
|
$association->setTargetEntity(DDC117Article::class); |
|
759
|
|
|
$association->setPrimaryKey(true); |
|
760
|
|
|
|
|
761
|
|
|
$cm->addProperty($association); |
|
762
|
|
|
} |
|
763
|
|
|
|
|
764
|
|
|
/** |
|
765
|
|
|
* @group DDC-996 |
|
766
|
|
|
*/ |
|
767
|
|
|
public function testEmptyFieldNameThrowsException() : void |
|
768
|
|
|
{ |
|
769
|
|
|
$this->expectException(MappingException::class); |
|
770
|
|
|
$this->expectExceptionMessage("The field or association mapping misses the 'fieldName' attribute in entity '" . CMS\CmsUser::class . "'."); |
|
771
|
|
|
|
|
772
|
|
|
$cm = new ClassMetadata(CMS\CmsUser::class, null); |
|
773
|
|
|
$cm->setTable(new Mapping\TableMetadata('cms_users')); |
|
774
|
|
|
|
|
775
|
|
|
$fieldMetadata = new Mapping\FieldMetadata(''); |
|
776
|
|
|
|
|
777
|
|
|
$fieldMetadata->setType(Type::getType('string')); |
|
778
|
|
|
|
|
779
|
|
|
$cm->addProperty($fieldMetadata); |
|
780
|
|
|
} |
|
781
|
|
|
|
|
782
|
|
|
/** |
|
783
|
|
|
* @group DDC-2451 |
|
784
|
|
|
*/ |
|
785
|
|
|
public function testSerializeEntityListeners() : void |
|
786
|
|
|
{ |
|
787
|
|
|
$metadata = new ClassMetadata(CompanyContract::class, null); |
|
788
|
|
|
|
|
789
|
|
|
$metadata->addEntityListener(Events::prePersist, CompanyContractListener::class, 'prePersistHandler'); |
|
790
|
|
|
$metadata->addEntityListener(Events::postPersist, CompanyContractListener::class, 'postPersistHandler'); |
|
791
|
|
|
|
|
792
|
|
|
$serialize = serialize($metadata); |
|
793
|
|
|
$unserialize = unserialize($serialize); |
|
794
|
|
|
|
|
795
|
|
|
self::assertEquals($metadata->entityListeners, $unserialize->entityListeners); |
|
796
|
|
|
} |
|
797
|
|
|
|
|
798
|
|
|
/** |
|
799
|
|
|
* @group DDC-1068 |
|
800
|
|
|
*/ |
|
801
|
|
|
public function testClassCaseSensitivity() : void |
|
802
|
|
|
{ |
|
803
|
|
|
$this->markTestIncomplete('This test needs to be moved to ClassMetadataBuilderTest'); |
|
804
|
|
|
|
|
805
|
|
|
$cm = new ClassMetadata(strtoupper(CMS\CmsUser::class), null); |
|
806
|
|
|
$cm->setTable(new Mapping\TableMetadata('cms_users')); |
|
807
|
|
|
|
|
808
|
|
|
self::assertEquals(CMS\CmsUser::class, $cm->getClassName()); |
|
809
|
|
|
} |
|
810
|
|
|
|
|
811
|
|
|
/** |
|
812
|
|
|
* @group DDC-659 |
|
813
|
|
|
*/ |
|
814
|
|
|
public function testLifecycleCallbackNotFound() : void |
|
815
|
|
|
{ |
|
816
|
|
|
$cm = new ClassMetadata(CMS\CmsUser::class, null); |
|
817
|
|
|
$cm->setTable(new Mapping\TableMetadata('cms_users')); |
|
818
|
|
|
|
|
819
|
|
|
$cm->addLifecycleCallback('postLoad', 'notfound'); |
|
820
|
|
|
|
|
821
|
|
|
$this->expectException(MappingException::class); |
|
822
|
|
|
$this->expectExceptionMessage("Entity '" . CMS\CmsUser::class . "' has no public method 'notfound' to be registered as lifecycle callback."); |
|
823
|
|
|
|
|
824
|
|
|
$cm->validateLifecycleCallbacks(new RuntimeReflectionService()); |
|
825
|
|
|
} |
|
826
|
|
|
|
|
827
|
|
|
/** |
|
828
|
|
|
* @group ImproveErrorMessages |
|
829
|
|
|
*/ |
|
830
|
|
|
public function testTargetEntityNotFound() : void |
|
831
|
|
|
{ |
|
832
|
|
|
$this->markTestIncomplete('This test needs to be moved to ClassMetadataBuilderTest'); |
|
833
|
|
|
|
|
834
|
|
|
$cm = new ClassMetadata(CMS\CmsUser::class, null); |
|
835
|
|
|
$cm->setTable(new Mapping\TableMetadata('cms_users')); |
|
836
|
|
|
|
|
837
|
|
|
$association = new Mapping\ManyToOneAssociationMetadata('address'); |
|
838
|
|
|
|
|
839
|
|
|
$association->setTargetEntity('UnknownClass'); |
|
840
|
|
|
|
|
841
|
|
|
$cm->addProperty($association); |
|
842
|
|
|
|
|
843
|
|
|
$this->expectException(MappingException::class); |
|
844
|
|
|
$this->expectExceptionMessage("The target-entity 'UnknownClass' cannot be found in '" . CMS\CmsUser::class . "#address'."); |
|
845
|
|
|
|
|
846
|
|
|
$cm->validateAssociations(); |
|
847
|
|
|
} |
|
848
|
|
|
|
|
849
|
|
|
/** |
|
850
|
|
|
* @group DDC-1746 |
|
851
|
|
|
* @expectedException \Doctrine\ORM\Mapping\MappingException |
|
852
|
|
|
* @expectedExceptionMessage You have specified invalid cascade options for Doctrine\Tests\Models\CMS\CmsUser::$address: 'invalid'; available options: 'remove', 'persist', and 'refresh' |
|
853
|
|
|
*/ |
|
854
|
|
|
public function testInvalidCascade() : void |
|
855
|
|
|
{ |
|
856
|
|
|
$this->markTestIncomplete('This test needs to be moved to ClassMetadataBuilderTest'); |
|
857
|
|
|
|
|
858
|
|
|
$cm = new ClassMetadata(CMS\CmsUser::class, null); |
|
859
|
|
|
$cm->setTable(new Mapping\TableMetadata('cms_users')); |
|
860
|
|
|
|
|
861
|
|
|
$association = new Mapping\ManyToOneAssociationMetadata('address'); |
|
862
|
|
|
|
|
863
|
|
|
$association->setTargetEntity('UnknownClass'); |
|
864
|
|
|
$association->setCascade(['invalid']); |
|
865
|
|
|
|
|
866
|
|
|
$cm->addProperty($association); |
|
867
|
|
|
} |
|
868
|
|
|
|
|
869
|
|
|
/** |
|
870
|
|
|
* @group DDC-964 |
|
871
|
|
|
* @expectedException \Doctrine\ORM\Mapping\MappingException |
|
872
|
|
|
* @expectedExceptionMessage Invalid field override named 'invalidPropertyName' for class 'Doctrine\Tests\Models\DDC964\DDC964Admin' |
|
873
|
|
|
*/ |
|
874
|
|
|
public function testInvalidPropertyAssociationOverrideNameException() : void |
|
875
|
|
|
{ |
|
876
|
|
|
$cm = new ClassMetadata(DDC964Admin::class, null); |
|
877
|
|
|
$cm->setTable(new Mapping\TableMetadata('ddc964_admin')); |
|
878
|
|
|
|
|
879
|
|
|
$association = new Mapping\ManyToOneAssociationMetadata('address'); |
|
880
|
|
|
|
|
881
|
|
|
$association->setTargetEntity(DDC964Address::class); |
|
882
|
|
|
|
|
883
|
|
|
$cm->addProperty($association); |
|
884
|
|
|
|
|
885
|
|
|
$cm->setPropertyOverride(new Mapping\ManyToOneAssociationMetadata('invalidPropertyName')); |
|
886
|
|
|
} |
|
887
|
|
|
|
|
888
|
|
|
/** |
|
889
|
|
|
* @group DDC-964 |
|
890
|
|
|
* @expectedException \Doctrine\ORM\Mapping\MappingException |
|
891
|
|
|
* @expectedExceptionMessage Invalid field override named 'invalidPropertyName' for class 'Doctrine\Tests\Models\DDC964\DDC964Guest'. |
|
892
|
|
|
*/ |
|
893
|
|
|
public function testInvalidPropertyAttributeOverrideNameException() : void |
|
894
|
|
|
{ |
|
895
|
|
|
$cm = new ClassMetadata(DDC964Guest::class, null); |
|
896
|
|
|
$cm->setTable(new Mapping\TableMetadata('ddc964_guest')); |
|
897
|
|
|
|
|
898
|
|
|
$fieldMetadata = new Mapping\FieldMetadata('name'); |
|
899
|
|
|
$fieldMetadata->setType(Type::getType('string')); |
|
900
|
|
|
|
|
901
|
|
|
$cm->addProperty($fieldMetadata); |
|
902
|
|
|
|
|
903
|
|
|
$fieldMetadata = new Mapping\FieldMetadata('invalidPropertyName'); |
|
904
|
|
|
$fieldMetadata->setType(Type::getType('string')); |
|
905
|
|
|
|
|
906
|
|
|
$cm->setPropertyOverride($fieldMetadata); |
|
907
|
|
|
} |
|
908
|
|
|
|
|
909
|
|
|
/** |
|
910
|
|
|
* @group DDC-1955 |
|
911
|
|
|
* @expectedException \Doctrine\ORM\Mapping\MappingException |
|
912
|
|
|
* @expectedExceptionMessage Entity Listener "\InvalidClassName" declared on "Doctrine\Tests\Models\CMS\CmsUser" not found. |
|
913
|
|
|
*/ |
|
914
|
|
|
public function testInvalidEntityListenerClassException() : void |
|
915
|
|
|
{ |
|
916
|
|
|
$cm = new ClassMetadata(CMS\CmsUser::class, null); |
|
917
|
|
|
$cm->setTable(new Mapping\TableMetadata('cms_users')); |
|
918
|
|
|
|
|
919
|
|
|
$cm->addEntityListener(Events::postLoad, '\InvalidClassName', 'postLoadHandler'); |
|
920
|
|
|
} |
|
921
|
|
|
|
|
922
|
|
|
/** |
|
923
|
|
|
* @group DDC-1955 |
|
924
|
|
|
* @expectedException \Doctrine\ORM\Mapping\MappingException |
|
925
|
|
|
* @expectedExceptionMessage Entity Listener "Doctrine\Tests\Models\Company\CompanyContractListener" declared on "Doctrine\Tests\Models\CMS\CmsUser" has no method "invalidMethod". |
|
926
|
|
|
*/ |
|
927
|
|
|
public function testInvalidEntityListenerMethodException() : void |
|
928
|
|
|
{ |
|
929
|
|
|
$cm = new ClassMetadata(CMS\CmsUser::class, null); |
|
930
|
|
|
$cm->setTable(new Mapping\TableMetadata('cms_users')); |
|
931
|
|
|
|
|
932
|
|
|
$cm->addEntityListener(Events::postLoad, 'Doctrine\Tests\Models\Company\CompanyContractListener', 'invalidMethod'); |
|
933
|
|
|
} |
|
934
|
|
|
|
|
935
|
|
|
public function testManyToManySelfReferencingNamingStrategyDefaults() : void |
|
936
|
|
|
{ |
|
937
|
|
|
$this->markTestIncomplete('This test needs to be moved to JoinTableMetadataBuilderTest'); |
|
938
|
|
|
|
|
939
|
|
|
$cm = new ClassMetadata(CustomTypeParent::class, null); |
|
940
|
|
|
$cm->setTable(new Mapping\TableMetadata('custom_type_parent')); |
|
941
|
|
|
|
|
942
|
|
|
$association = new Mapping\ManyToManyAssociationMetadata('friendsWithMe'); |
|
943
|
|
|
|
|
944
|
|
|
$association->setTargetEntity(CustomTypeParent::class); |
|
945
|
|
|
|
|
946
|
|
|
$cm->addProperty($association); |
|
947
|
|
|
|
|
948
|
|
|
$association = $cm->getProperty('friendsWithMe'); |
|
949
|
|
|
|
|
950
|
|
|
$joinColumns = []; |
|
951
|
|
|
|
|
952
|
|
|
$joinColumn = new Mapping\JoinColumnMetadata(); |
|
953
|
|
|
|
|
954
|
|
|
$joinColumn->setColumnName('customtypeparent_source'); |
|
955
|
|
|
$joinColumn->setReferencedColumnName('id'); |
|
956
|
|
|
$joinColumn->setOnDelete('CASCADE'); |
|
957
|
|
|
|
|
958
|
|
|
$joinColumns[] = $joinColumn; |
|
959
|
|
|
|
|
960
|
|
|
$inverseJoinColumns = []; |
|
961
|
|
|
|
|
962
|
|
|
$joinColumn = new Mapping\JoinColumnMetadata(); |
|
963
|
|
|
|
|
964
|
|
|
$joinColumn->setColumnName('customtypeparent_target'); |
|
965
|
|
|
$joinColumn->setReferencedColumnName('id'); |
|
966
|
|
|
$joinColumn->setOnDelete('CASCADE'); |
|
967
|
|
|
|
|
968
|
|
|
$inverseJoinColumns[] = $joinColumn; |
|
969
|
|
|
|
|
970
|
|
|
$joinTable = $association->getJoinTable(); |
|
971
|
|
|
|
|
972
|
|
|
self::assertEquals('customtypeparent_customtypeparent', $joinTable->getName()); |
|
973
|
|
|
self::assertEquals($joinColumns, $joinTable->getJoinColumns()); |
|
974
|
|
|
self::assertEquals($inverseJoinColumns, $joinTable->getInverseJoinColumns()); |
|
975
|
|
|
} |
|
976
|
|
|
|
|
977
|
|
|
/** |
|
978
|
|
|
* @group DDC-2662 |
|
979
|
|
|
* @group 6682 |
|
980
|
|
|
*/ |
|
981
|
|
|
public function testQuotedSequenceName() : void |
|
982
|
|
|
{ |
|
983
|
|
|
self::markTestIncomplete( |
|
984
|
|
|
'@guilhermeblanco, in #6683 we added allocationSize/initialValue as to the sequence definition but with the' |
|
985
|
|
|
. ' changes you have made I am not sure if the "initialValue" should still be verified here or if it should' |
|
986
|
|
|
. ' part of the metadata drivers' |
|
987
|
|
|
); |
|
988
|
|
|
|
|
989
|
|
|
$cm = new ClassMetadata(CMS\CmsUser::class, null); |
|
990
|
|
|
$cm->setTable(new Mapping\TableMetadata('cms_users')); |
|
991
|
|
|
|
|
992
|
|
|
$id = new Mapping\FieldMetadata('id'); |
|
993
|
|
|
$id->setValueGenerator(new Mapping\ValueGeneratorMetadata( |
|
994
|
|
|
Mapping\GeneratorType::SEQUENCE, |
|
995
|
|
|
[ |
|
996
|
|
|
'sequenceName' => 'foo', |
|
997
|
|
|
'allocationSize' => 1, |
|
998
|
|
|
] |
|
999
|
|
|
)); |
|
1000
|
|
|
$cm->addProperty($id); |
|
1001
|
|
|
|
|
1002
|
|
|
self::assertEquals( |
|
1003
|
|
|
['sequenceName' => 'foo', 'allocationSize' => 1, 'initialValue' => '1'], |
|
1004
|
|
|
$cm->getProperty('id')->getValueGenerator()->getDefinition() |
|
1005
|
|
|
); |
|
1006
|
|
|
} |
|
1007
|
|
|
|
|
1008
|
|
|
/** |
|
1009
|
|
|
* @group DDC-2700 |
|
1010
|
|
|
*/ |
|
1011
|
|
|
public function testIsIdentifierMappedSuperClass() : void |
|
1012
|
|
|
{ |
|
1013
|
|
|
$class = new ClassMetadata(DDC2700MappedSuperClass::class, null); |
|
1014
|
|
|
|
|
1015
|
|
|
self::assertFalse($class->isIdentifier('foo')); |
|
1016
|
|
|
} |
|
1017
|
|
|
|
|
1018
|
|
|
/** |
|
1019
|
|
|
* @group embedded |
|
1020
|
|
|
*/ |
|
1021
|
|
|
public function testWakeupReflectionWithEmbeddableAndStaticReflectionService() : void |
|
1022
|
|
|
{ |
|
1023
|
|
|
$metadata = new ClassMetadata(TestEntity1::class, null); |
|
1024
|
|
|
$cm->setTable(new Mapping\TableMetadata('test_entity1')); |
|
|
|
|
|
|
1025
|
|
|
|
|
1026
|
|
|
$metadata->mapEmbedded( |
|
1027
|
|
|
[ |
|
1028
|
|
|
'fieldName' => 'test', |
|
1029
|
|
|
'class' => TestEntity1::class, |
|
1030
|
|
|
'columnPrefix' => false, |
|
1031
|
|
|
] |
|
1032
|
|
|
); |
|
1033
|
|
|
|
|
1034
|
|
|
$fieldMetadata = new Mapping\FieldMetadata('test.embeddedProperty'); |
|
1035
|
|
|
$fieldMetadata->setType(Type::getType('string')); |
|
1036
|
|
|
|
|
1037
|
|
|
$metadata->addProperty($fieldMetadata); |
|
1038
|
|
|
|
|
1039
|
|
|
/* |
|
1040
|
|
|
$mapping = [ |
|
1041
|
|
|
'originalClass' => TestEntity1::class, |
|
1042
|
|
|
'declaredField' => 'test', |
|
1043
|
|
|
'originalField' => 'embeddedProperty' |
|
1044
|
|
|
]; |
|
1045
|
|
|
|
|
1046
|
|
|
$metadata->addProperty('test.embeddedProperty', Type::getType('string'), $mapping); |
|
1047
|
|
|
*/ |
|
1048
|
|
|
|
|
1049
|
|
|
$metadata->wakeupReflection(new StaticReflectionService()); |
|
1050
|
|
|
|
|
1051
|
|
|
self::assertEquals( |
|
1052
|
|
|
[ |
|
1053
|
|
|
'test' => null, |
|
1054
|
|
|
'test.embeddedProperty' => null, |
|
1055
|
|
|
], |
|
1056
|
|
|
$metadata->getReflectionProperties() |
|
|
|
|
|
|
1057
|
|
|
); |
|
1058
|
|
|
} |
|
1059
|
|
|
} |
|
1060
|
|
|
|
|
1061
|
|
|
/** |
|
1062
|
|
|
* @ORM\MappedSuperclass |
|
1063
|
|
|
*/ |
|
1064
|
|
|
class DDC2700MappedSuperClass |
|
1065
|
|
|
{ |
|
1066
|
|
|
/** @ORM\Column */ |
|
1067
|
|
|
private $foo; |
|
|
|
|
|
|
1068
|
|
|
} |
|
1069
|
|
|
|
|
1070
|
|
|
class MyNamespacedNamingStrategy extends DefaultNamingStrategy |
|
1071
|
|
|
{ |
|
1072
|
|
|
/** |
|
1073
|
|
|
* {@inheritdoc} |
|
1074
|
|
|
*/ |
|
1075
|
|
|
public function classToTableName(string $className) : string |
|
1076
|
|
|
{ |
|
1077
|
|
|
if (strpos($className, '\\') !== false) { |
|
1078
|
|
|
$className = str_replace('\\', '_', str_replace('Doctrine\Tests\Models\\', '', $className)); |
|
1079
|
|
|
} |
|
1080
|
|
|
|
|
1081
|
|
|
return strtolower($className); |
|
1082
|
|
|
} |
|
1083
|
|
|
} |
|
1084
|
|
|
|
|
1085
|
|
|
class MyPrefixNamingStrategy extends DefaultNamingStrategy |
|
1086
|
|
|
{ |
|
1087
|
|
|
/** |
|
1088
|
|
|
* {@inheritdoc} |
|
1089
|
|
|
*/ |
|
1090
|
|
|
public function propertyToColumnName(string $propertyName, ?string $className = null) : string |
|
1091
|
|
|
{ |
|
1092
|
|
|
return strtolower($this->classToTableName($className)) . '_' . $propertyName; |
|
|
|
|
|
|
1093
|
|
|
} |
|
1094
|
|
|
} |
|
1095
|
|
|
|