1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\Tests\ORM\Mapping; |
6
|
|
|
|
7
|
|
|
use Doctrine\Common\EventManager; |
8
|
|
|
use Doctrine\DBAL\Connection; |
9
|
|
|
use Doctrine\DBAL\Types\Type; |
10
|
|
|
use Doctrine\ORM\Configuration; |
11
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
12
|
|
|
use Doctrine\ORM\Event\OnClassMetadataNotFoundEventArgs; |
13
|
|
|
use Doctrine\ORM\Events; |
14
|
|
|
use Doctrine\ORM\Mapping; |
15
|
|
|
use Doctrine\ORM\Mapping\ClassMetadata; |
16
|
|
|
use Doctrine\ORM\Mapping\ClassMetadataFactory; |
17
|
|
|
use Doctrine\ORM\Mapping\Driver\MappingDriver; |
18
|
|
|
use Doctrine\ORM\Mapping\MappingException; |
19
|
|
|
use Doctrine\ORM\Sequencing\Generator; |
20
|
|
|
use Doctrine\Tests\Mocks\ConnectionMock; |
21
|
|
|
use Doctrine\Tests\Mocks\DriverMock; |
22
|
|
|
use Doctrine\Tests\Mocks\EntityManagerMock; |
23
|
|
|
use Doctrine\Tests\Mocks\MetadataDriverMock; |
24
|
|
|
use Doctrine\Tests\Models\CMS\CmsArticle; |
25
|
|
|
use Doctrine\Tests\Models\CMS\CmsUser; |
26
|
|
|
use Doctrine\Tests\Models\DDC4006\DDC4006User; |
27
|
|
|
use Doctrine\Tests\Models\JoinedInheritanceType\AnotherChildClass; |
28
|
|
|
use Doctrine\Tests\Models\JoinedInheritanceType\ChildClass; |
29
|
|
|
use Doctrine\Tests\Models\JoinedInheritanceType\RootClass; |
30
|
|
|
use Doctrine\Tests\Models\Quote; |
31
|
|
|
use Doctrine\Tests\OrmTestCase; |
32
|
|
|
use DoctrineGlobalArticle; |
33
|
|
|
use Exception; |
34
|
|
|
use InvalidArgumentException; |
35
|
|
|
use stdClass; |
36
|
|
|
use function reset; |
37
|
|
|
use function sprintf; |
38
|
|
|
|
39
|
|
|
class ClassMetadataFactoryTest extends OrmTestCase |
40
|
|
|
{ |
41
|
|
|
public function testGetMetadataForSingleClass() : void |
42
|
|
|
{ |
43
|
|
|
$mockDriver = new MetadataDriverMock(); |
44
|
|
|
$entityManager = $this->createEntityManager($mockDriver); |
45
|
|
|
|
46
|
|
|
$conn = $entityManager->getConnection(); |
47
|
|
|
$mockPlatform = $conn->getDatabasePlatform(); |
48
|
|
|
$mockPlatform->setPrefersSequences(true); |
|
|
|
|
49
|
|
|
$mockPlatform->setPrefersIdentityColumns(false); |
|
|
|
|
50
|
|
|
|
51
|
|
|
$cm1 = $this->createValidClassMetadata(); |
52
|
|
|
|
53
|
|
|
// SUT |
54
|
|
|
$cmf = new ClassMetadataFactory(); |
55
|
|
|
$cmf->setEntityManager($entityManager); |
56
|
|
|
$cmf->setMetadataFor($cm1->getClassName(), $cm1); |
57
|
|
|
|
58
|
|
|
// Prechecks |
59
|
|
|
self::assertCount(0, $cm1->getAncestorsIterator()); |
60
|
|
|
self::assertEquals(Mapping\InheritanceType::NONE, $cm1->inheritanceType); |
61
|
|
|
self::assertEquals(Mapping\GeneratorType::SEQUENCE, $cm1->getProperty('id')->getValueGenerator()->getType()); |
|
|
|
|
62
|
|
|
self::assertTrue($cm1->hasField('name')); |
63
|
|
|
self::assertCount(4, $cm1->getPropertiesIterator()); // 2 fields + 2 associations |
64
|
|
|
self::assertEquals('group', $cm1->table->getName()); |
65
|
|
|
|
66
|
|
|
// Go |
67
|
|
|
$cmMap1 = $cmf->getMetadataFor($cm1->getClassName()); |
68
|
|
|
|
69
|
|
|
self::assertSame($cm1, $cmMap1); |
70
|
|
|
self::assertEquals('group', $cmMap1->table->getName()); |
71
|
|
|
self::assertCount(0, $cmMap1->getAncestorsIterator()); |
72
|
|
|
self::assertTrue($cmMap1->hasField('name')); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function testHasGetMetadataNamespaceSeparatorIsNotNormalized() : void |
76
|
|
|
{ |
77
|
|
|
require_once __DIR__ . '/../../Models/Global/GlobalNamespaceModel.php'; |
78
|
|
|
|
79
|
|
|
$metadataDriver = $this->createAnnotationDriver([__DIR__ . '/../../Models/Global/']); |
80
|
|
|
|
81
|
|
|
$entityManager = $this->createEntityManager($metadataDriver); |
82
|
|
|
|
83
|
|
|
$mf = $entityManager->getMetadataFactory(); |
84
|
|
|
|
85
|
|
|
self::assertSame( |
86
|
|
|
$mf->getMetadataFor(DoctrineGlobalArticle::class), |
87
|
|
|
$mf->getMetadataFor('\\' . DoctrineGlobalArticle::class) |
88
|
|
|
); |
89
|
|
|
self::assertTrue($mf->hasMetadataFor(DoctrineGlobalArticle::class)); |
90
|
|
|
self::assertTrue($mf->hasMetadataFor('\\' . DoctrineGlobalArticle::class)); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @group DDC-1512 |
95
|
|
|
*/ |
96
|
|
|
public function testIsTransient() : void |
97
|
|
|
{ |
98
|
|
|
$cmf = new ClassMetadataFactory(); |
|
|
|
|
99
|
|
|
$driver = $this->createMock(MappingDriver::class); |
100
|
|
|
$driver->expects($this->at(0)) |
101
|
|
|
->method('isTransient') |
102
|
|
|
->with($this->equalTo(CmsUser::class)) |
103
|
|
|
->will($this->returnValue(true)); |
104
|
|
|
$driver->expects($this->at(1)) |
105
|
|
|
->method('isTransient') |
106
|
|
|
->with($this->equalTo(CmsArticle::class)) |
107
|
|
|
->will($this->returnValue(false)); |
108
|
|
|
|
109
|
|
|
$em = $this->createEntityManager($driver); |
110
|
|
|
|
111
|
|
|
self::assertTrue($em->getMetadataFactory()->isTransient(CmsUser::class)); |
112
|
|
|
self::assertFalse($em->getMetadataFactory()->isTransient(CmsArticle::class)); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @dataProvider classesInInheritanceWithNoMapProvider() |
117
|
|
|
*/ |
118
|
|
|
public function testNoDefaultDiscriminatorMapIsAssumed(string $rootClassName, string $targetClassName) : void |
119
|
|
|
{ |
120
|
|
|
$cmf = new ClassMetadataFactory(); |
121
|
|
|
$driver = $this->createAnnotationDriver([__DIR__ . '/../../Models/JoinedInheritanceType/']); |
122
|
|
|
$em = $this->createEntityManager($driver); |
123
|
|
|
$cmf->setEntityManager($em); |
124
|
|
|
|
125
|
|
|
$this->expectException(MappingException::class); |
126
|
|
|
$this->expectExceptionMessage( |
127
|
|
|
sprintf("Entity class '%s' is using inheritance but no discriminator map was defined.", $rootClassName) |
128
|
|
|
); |
129
|
|
|
|
130
|
|
|
$cmf->getMetadataFor($targetClassName); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @return string[] |
135
|
|
|
*/ |
136
|
|
|
public function classesInInheritanceWithNoMapProvider() : iterable |
137
|
|
|
{ |
138
|
|
|
yield 'root entity' => [RootClass::class, RootClass::class]; |
|
|
|
|
139
|
|
|
yield 'child entity' => [RootClass::class, ChildClass::class]; |
140
|
|
|
yield 'another child entity' => [RootClass::class, AnotherChildClass::class]; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
public function testGetAllMetadataWorksWithBadConnection() : void |
144
|
|
|
{ |
145
|
|
|
// DDC-3551 |
146
|
|
|
$conn = $this->createMock(Connection::class); |
147
|
|
|
$mockDriver = new MetadataDriverMock(); |
148
|
|
|
$conn->expects($this->any()) |
149
|
|
|
->method('getEventManager') |
150
|
|
|
->willReturn(new EventManager()); |
151
|
|
|
$em = $this->createEntityManager($mockDriver, $conn); |
152
|
|
|
|
153
|
|
|
$conn->expects($this->any()) |
154
|
|
|
->method('getDatabasePlatform') |
155
|
|
|
->will($this->throwException(new Exception('Exception thrown in test when calling getDatabasePlatform'))); |
156
|
|
|
|
157
|
|
|
$cmf = new ClassMetadataFactory(); |
158
|
|
|
$cmf->setEntityManager($em); |
159
|
|
|
|
160
|
|
|
// getting all the metadata should work, even if get DatabasePlatform blows up |
161
|
|
|
$metadata = $cmf->getAllMetadata(); |
162
|
|
|
// this will just be an empty array - there was no error |
163
|
|
|
self::assertEquals([], $metadata); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
protected function createEntityManager($metadataDriver, $conn = null) |
167
|
|
|
{ |
168
|
|
|
$driverMock = new DriverMock(); |
169
|
|
|
$config = new Configuration(); |
170
|
|
|
|
171
|
|
|
$config->setProxyDir(__DIR__ . '/../../Proxies'); |
172
|
|
|
$config->setProxyNamespace('Doctrine\Tests\Proxies'); |
173
|
|
|
|
174
|
|
|
if (! $conn) { |
175
|
|
|
$conn = new ConnectionMock([], $driverMock, $config, new EventManager()); |
176
|
|
|
} |
177
|
|
|
$eventManager = $conn->getEventManager(); |
178
|
|
|
|
179
|
|
|
$config->setMetadataDriverImpl($metadataDriver); |
180
|
|
|
|
181
|
|
|
return EntityManagerMock::create($conn, $config, $eventManager); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* @return ClassMetadataFactoryTestSubject |
186
|
|
|
*/ |
187
|
|
|
protected function createTestFactory() |
188
|
|
|
{ |
189
|
|
|
$mockDriver = new MetadataDriverMock(); |
190
|
|
|
$entityManager = $this->createEntityManager($mockDriver); |
191
|
|
|
$cmf = new ClassMetadataFactoryTestSubject(); |
192
|
|
|
$cmf->setEntityManager($entityManager); |
193
|
|
|
|
194
|
|
|
return $cmf; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* @return ClassMetadata |
199
|
|
|
*/ |
200
|
|
|
protected function createValidClassMetadata() |
201
|
|
|
{ |
202
|
|
|
$cm1 = new ClassMetadata(TestEntity1::class, null); |
203
|
|
|
|
204
|
|
|
$tableMetadata = new Mapping\TableMetadata(); |
205
|
|
|
$tableMetadata->setName('group'); |
206
|
|
|
|
207
|
|
|
$cm1->setTable($tableMetadata); |
208
|
|
|
|
209
|
|
|
// Add a mapped field |
210
|
|
|
$fieldMetadata = new Mapping\FieldMetadata('id'); |
211
|
|
|
|
212
|
|
|
$fieldMetadata->setType(Type::getType('integer')); |
213
|
|
|
$fieldMetadata->setPrimaryKey(true); |
214
|
|
|
$fieldMetadata->setValueGenerator(new Mapping\ValueGeneratorMetadata( |
215
|
|
|
Mapping\GeneratorType::SEQUENCE, |
216
|
|
|
new Generator\SequenceGenerator('group_id_seq', 1) |
217
|
|
|
)); |
218
|
|
|
|
219
|
|
|
$cm1->addProperty($fieldMetadata); |
220
|
|
|
|
221
|
|
|
// Add a mapped field |
222
|
|
|
$fieldMetadata = new Mapping\FieldMetadata('name'); |
223
|
|
|
|
224
|
|
|
$fieldMetadata->setType(Type::getType('string')); |
225
|
|
|
|
226
|
|
|
$cm1->addProperty($fieldMetadata); |
227
|
|
|
|
228
|
|
|
// and a mapped association |
229
|
|
|
$association = new Mapping\OneToOneAssociationMetadata('other'); |
230
|
|
|
|
231
|
|
|
$association->setTargetEntity(TestEntity1::class); |
232
|
|
|
$association->setMappedBy('this'); |
233
|
|
|
|
234
|
|
|
$cm1->addProperty($association); |
235
|
|
|
|
236
|
|
|
// and an association on the owning side |
237
|
|
|
$joinColumns = []; |
238
|
|
|
|
239
|
|
|
$joinColumn = new Mapping\JoinColumnMetadata(); |
240
|
|
|
|
241
|
|
|
$joinColumn->setColumnName('other_id'); |
242
|
|
|
$joinColumn->setReferencedColumnName('id'); |
243
|
|
|
|
244
|
|
|
$joinColumns[] = $joinColumn; |
245
|
|
|
|
246
|
|
|
$association = new Mapping\OneToOneAssociationMetadata('association'); |
247
|
|
|
|
248
|
|
|
$association->setJoinColumns($joinColumns); |
249
|
|
|
$association->setTargetEntity(TestEntity1::class); |
250
|
|
|
|
251
|
|
|
$cm1->addProperty($association); |
252
|
|
|
|
253
|
|
|
return $cm1; |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
/** |
257
|
|
|
* @group DDC-1845 |
258
|
|
|
*/ |
259
|
|
|
public function testQuoteMetadata() : void |
260
|
|
|
{ |
261
|
|
|
$cmf = new ClassMetadataFactory(); |
262
|
|
|
$driver = $this->createAnnotationDriver([__DIR__ . '/../../Models/Quote/']); |
263
|
|
|
$em = $this->createEntityManager($driver); |
264
|
|
|
$cmf->setEntityManager($em); |
265
|
|
|
|
266
|
|
|
$userMetadata = $cmf->getMetadataFor(Quote\User::class); |
267
|
|
|
$phoneMetadata = $cmf->getMetadataFor(Quote\Phone::class); |
268
|
|
|
$groupMetadata = $cmf->getMetadataFor(Quote\Group::class); |
269
|
|
|
$addressMetadata = $cmf->getMetadataFor(Quote\Address::class); |
270
|
|
|
|
271
|
|
|
// Phone Class Metadata |
272
|
|
|
self::assertNotNull($phoneMetadata->getProperty('number')); |
273
|
|
|
self::assertEquals('phone-number', $phoneMetadata->getProperty('number')->getColumnName()); |
|
|
|
|
274
|
|
|
|
275
|
|
|
$user = $phoneMetadata->getProperty('user'); |
276
|
|
|
$userJoinColumns = $user->getJoinColumns(); |
|
|
|
|
277
|
|
|
$phoneUserJoinColumn = reset($userJoinColumns); |
278
|
|
|
|
279
|
|
|
self::assertEquals('user-id', $phoneUserJoinColumn->getColumnName()); |
280
|
|
|
self::assertEquals('user-id', $phoneUserJoinColumn->getReferencedColumnName()); |
281
|
|
|
|
282
|
|
|
// Address Class Metadata |
283
|
|
|
self::assertNotNull($addressMetadata->getProperty('id')); |
284
|
|
|
self::assertNotNull($addressMetadata->getProperty('zip')); |
285
|
|
|
self::assertEquals('address-id', $addressMetadata->getProperty('id')->getColumnName()); |
286
|
|
|
self::assertEquals('address-zip', $addressMetadata->getProperty('zip')->getColumnName()); |
287
|
|
|
|
288
|
|
|
// User Class Metadata |
289
|
|
|
self::assertNotNull($userMetadata->getProperty('id')); |
290
|
|
|
self::assertNotNull($userMetadata->getProperty('name')); |
291
|
|
|
self::assertEquals('user-id', $userMetadata->getProperty('id')->getColumnName()); |
292
|
|
|
self::assertEquals('user-name', $userMetadata->getProperty('name')->getColumnName()); |
293
|
|
|
|
294
|
|
|
$group = $groupMetadata->getProperty('parent'); |
295
|
|
|
$groupJoinColumns = $group->getJoinColumns(); |
296
|
|
|
$groupUserJoinColumn = reset($groupJoinColumns); |
297
|
|
|
|
298
|
|
|
self::assertEquals('parent-id', $groupUserJoinColumn->getColumnName()); |
299
|
|
|
self::assertEquals('group-id', $groupUserJoinColumn->getReferencedColumnName()); |
300
|
|
|
|
301
|
|
|
$user = $addressMetadata->getProperty('user'); |
302
|
|
|
$userJoinColumns = $user->getJoinColumns(); |
303
|
|
|
$addressUserJoinColumn = reset($userJoinColumns); |
304
|
|
|
|
305
|
|
|
self::assertEquals('user-id', $addressUserJoinColumn->getColumnName()); |
306
|
|
|
self::assertEquals('user-id', $addressUserJoinColumn->getReferencedColumnName()); |
307
|
|
|
|
308
|
|
|
$groups = $userMetadata->getProperty('groups'); |
309
|
|
|
$groupsJoinTable = $groups->getJoinTable(); |
|
|
|
|
310
|
|
|
$userGroupsJoinColumns = $groupsJoinTable->getJoinColumns(); |
311
|
|
|
$userGroupsJoinColumn = reset($userGroupsJoinColumns); |
312
|
|
|
$userGroupsInverseJoinColumns = $groupsJoinTable->getInverseJoinColumns(); |
313
|
|
|
$userGroupsInverseJoinColumn = reset($userGroupsInverseJoinColumns); |
314
|
|
|
|
315
|
|
|
self::assertEquals('quote-users-groups', $groupsJoinTable->getName()); |
316
|
|
|
self::assertEquals('user-id', $userGroupsJoinColumn->getColumnName()); |
317
|
|
|
self::assertEquals('user-id', $userGroupsJoinColumn->getReferencedColumnName()); |
318
|
|
|
self::assertEquals('group-id', $userGroupsInverseJoinColumn->getColumnName()); |
319
|
|
|
self::assertEquals('group-id', $userGroupsInverseJoinColumn->getReferencedColumnName()); |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
/** |
323
|
|
|
* @group DDC-3385 |
324
|
|
|
* @group 1181 |
325
|
|
|
* @group 385 |
326
|
|
|
*/ |
327
|
|
|
public function testFallbackLoadingCausesEventTriggeringThatCanModifyFetchedMetadata() : void |
328
|
|
|
{ |
329
|
|
|
/** @var ClassMetadata $metadata */ |
330
|
|
|
$metadata = $this->createMock(ClassMetadata::class); |
331
|
|
|
$cmf = new ClassMetadataFactory(); |
332
|
|
|
$mockDriver = new MetadataDriverMock(); |
333
|
|
|
$em = $this->createEntityManager($mockDriver); |
334
|
|
|
$listener = $this->getMockBuilder(stdClass::class)->setMethods(['onClassMetadataNotFound'])->getMock(); |
335
|
|
|
$eventManager = $em->getEventManager(); |
336
|
|
|
|
337
|
|
|
$cmf->setEntityManager($em); |
338
|
|
|
|
339
|
|
|
$listener |
340
|
|
|
->expects($this->any()) |
341
|
|
|
->method('onClassMetadataNotFound') |
342
|
|
|
->will($this->returnCallback(static function (OnClassMetadataNotFoundEventArgs $args) use ($metadata, $em) { |
343
|
|
|
self::assertNull($args->getFoundMetadata()); |
344
|
|
|
self::assertSame('Foo', $args->getClassName()); |
345
|
|
|
self::assertSame($em, $args->getObjectManager()); |
346
|
|
|
|
347
|
|
|
$args->setFoundMetadata($metadata); |
348
|
|
|
})); |
349
|
|
|
|
350
|
|
|
$eventManager->addEventListener([Events::onClassMetadataNotFound], $listener); |
351
|
|
|
|
352
|
|
|
self::assertSame($metadata, $cmf->getMetadataFor('Foo')); |
353
|
|
|
} |
354
|
|
|
|
355
|
|
|
/** |
356
|
|
|
* @group DDC-3427 |
357
|
|
|
*/ |
358
|
|
|
public function testAcceptsEntityManagerInterfaceInstances() : void |
359
|
|
|
{ |
360
|
|
|
$classMetadataFactory = new ClassMetadataFactory(); |
361
|
|
|
|
362
|
|
|
/** @var EntityManagerInterface $entityManager */ |
363
|
|
|
$entityManager = $this->createMock(EntityManagerInterface::class); |
364
|
|
|
|
365
|
|
|
$classMetadataFactory->setEntityManager($entityManager); |
366
|
|
|
|
367
|
|
|
// not really the cleanest way to check it, but we won't add a getter to the CMF just for the sake of testing. |
368
|
|
|
self::assertAttributeSame($entityManager, 'em', $classMetadataFactory); |
|
|
|
|
369
|
|
|
} |
370
|
|
|
|
371
|
|
|
/** |
372
|
|
|
* @group embedded |
373
|
|
|
* @group DDC-3305 |
374
|
|
|
*/ |
375
|
|
|
public function testRejectsEmbeddableWithoutValidClassName() : void |
376
|
|
|
{ |
377
|
|
|
$metadata = $this->createValidClassMetadata(); |
378
|
|
|
|
379
|
|
|
$metadata->mapEmbedded( |
380
|
|
|
[ |
381
|
|
|
'fieldName' => 'embedded', |
382
|
|
|
'class' => '', |
383
|
|
|
'columnPrefix' => false, |
384
|
|
|
] |
385
|
|
|
); |
386
|
|
|
|
387
|
|
|
$cmf = $this->createTestFactory(); |
388
|
|
|
|
389
|
|
|
$cmf->setMetadataForClass($metadata->getClassName(), $metadata); |
390
|
|
|
|
391
|
|
|
$this->expectException(MappingException::class); |
392
|
|
|
$this->expectExceptionMessage('The embed mapping \'embedded\' misses the \'class\' attribute.'); |
393
|
|
|
|
394
|
|
|
$cmf->getMetadataFor($metadata->getClassName()); |
395
|
|
|
} |
396
|
|
|
|
397
|
|
|
/** |
398
|
|
|
* @group embedded |
399
|
|
|
* @group DDC-4006 |
400
|
|
|
*/ |
401
|
|
|
public function testInheritsIdGeneratorMappingFromEmbeddable() : void |
402
|
|
|
{ |
403
|
|
|
$cmf = new ClassMetadataFactory(); |
404
|
|
|
$driver = $this->createAnnotationDriver([__DIR__ . '/../../Models/DDC4006/']); |
405
|
|
|
$em = $this->createEntityManager($driver); |
406
|
|
|
$cmf->setEntityManager($em); |
407
|
|
|
|
408
|
|
|
$userMetadata = $cmf->getMetadataFor(DDC4006User::class); |
409
|
|
|
|
410
|
|
|
self::assertTrue($userMetadata->isIdGeneratorIdentity()); |
|
|
|
|
411
|
|
|
} |
412
|
|
|
} |
413
|
|
|
|
414
|
|
|
/* Test subject class with overridden factory method for mocking purposes */ |
415
|
|
|
class ClassMetadataFactoryTestSubject extends ClassMetadataFactory |
416
|
|
|
{ |
417
|
|
|
private $mockMetadata = []; |
418
|
|
|
private $requestedClasses = []; |
419
|
|
|
|
420
|
|
|
protected function newClassMetadataInstance( |
421
|
|
|
string $className, |
422
|
|
|
?Mapping\ClassMetadata $parent, |
|
|
|
|
423
|
|
|
Mapping\ClassMetadataBuildingContext $metadataBuildingContext |
|
|
|
|
424
|
|
|
) : ClassMetadata { |
425
|
|
|
$this->requestedClasses[] = $className; |
426
|
|
|
|
427
|
|
|
if (! isset($this->mockMetadata[$className])) { |
428
|
|
|
throw new InvalidArgumentException(sprintf('No mock metadata found for class %s.', $className)); |
429
|
|
|
} |
430
|
|
|
|
431
|
|
|
return $this->mockMetadata[$className]; |
432
|
|
|
} |
433
|
|
|
|
434
|
|
|
public function setMetadataForClass($className, $metadata) |
435
|
|
|
{ |
436
|
|
|
$this->mockMetadata[$className] = $metadata; |
437
|
|
|
} |
438
|
|
|
|
439
|
|
|
public function getRequestedClasses() |
440
|
|
|
{ |
441
|
|
|
return $this->requestedClasses; |
442
|
|
|
} |
443
|
|
|
} |
444
|
|
|
|
445
|
|
|
class TestEntity1 |
446
|
|
|
{ |
447
|
|
|
private $id; |
|
|
|
|
448
|
|
|
private $name; |
|
|
|
|
449
|
|
|
private $other; |
|
|
|
|
450
|
|
|
private $association; |
|
|
|
|
451
|
|
|
private $embedded; |
|
|
|
|
452
|
|
|
} |
453
|
|
|
|
454
|
|
|
class CustomIdGenerator implements Generator\Generator |
455
|
|
|
{ |
456
|
|
|
/** |
457
|
|
|
* {@inheritdoc} |
458
|
|
|
*/ |
459
|
|
|
public function generate(EntityManagerInterface $em, ?object $entity) |
460
|
|
|
{ |
461
|
|
|
} |
462
|
|
|
|
463
|
|
|
/** |
464
|
|
|
* {@inheritdoc} |
465
|
|
|
*/ |
466
|
|
|
public function isPostInsertGenerator() : bool |
467
|
|
|
{ |
468
|
|
|
return false; |
469
|
|
|
} |
470
|
|
|
} |
471
|
|
|
|