Passed
Pull Request — master (#7457)
by Michael
13:35
created

testNoDefaultDiscriminatorMapIsAssumed()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 2
dl 0
loc 13
rs 10
c 0
b 0
f 0
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\Exception\ORMException;
15
use Doctrine\ORM\Mapping;
16
use Doctrine\ORM\Mapping\ClassMetadata;
17
use Doctrine\ORM\Mapping\ClassMetadataFactory;
18
use Doctrine\ORM\Mapping\Driver\MappingDriver;
19
use Doctrine\ORM\Mapping\MappingException;
20
use Doctrine\ORM\Reflection\RuntimeReflectionService;
21
use Doctrine\ORM\Sequencing\Generator;
22
use Doctrine\Tests\Mocks\ConnectionMock;
23
use Doctrine\Tests\Mocks\DriverMock;
24
use Doctrine\Tests\Mocks\EntityManagerMock;
25
use Doctrine\Tests\Mocks\MetadataDriverMock;
26
use Doctrine\Tests\Models\CMS\CmsArticle;
27
use Doctrine\Tests\Models\CMS\CmsUser;
28
use Doctrine\Tests\Models\DDC4006\DDC4006User;
29
use Doctrine\Tests\Models\JoinedInheritanceType\AnotherChildClass;
30
use Doctrine\Tests\Models\JoinedInheritanceType\ChildClass;
31
use Doctrine\Tests\Models\JoinedInheritanceType\RootClass;
32
use Doctrine\Tests\Models\Quote;
33
use Doctrine\Tests\OrmTestCase;
34
use DoctrineGlobalArticle;
35
use function reset;
36
use function sprintf;
37
38
class ClassMetadataFactoryTest extends OrmTestCase
39
{
40
    public function testGetMetadataForSingleClass() : void
41
    {
42
        $mockDriver    = new MetadataDriverMock();
43
        $entityManager = $this->createEntityManager($mockDriver);
44
45
        $conn         = $entityManager->getConnection();
46
        $mockPlatform = $conn->getDatabasePlatform();
47
        $mockPlatform->setPrefersSequences(true);
0 ignored issues
show
Bug introduced by
The method setPrefersSequences() does not exist on Doctrine\DBAL\Platforms\AbstractPlatform. It seems like you code against a sub-type of Doctrine\DBAL\Platforms\AbstractPlatform such as Doctrine\Tests\Mocks\DatabasePlatformMock. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

47
        $mockPlatform->/** @scrutinizer ignore-call */ 
48
                       setPrefersSequences(true);
Loading history...
48
        $mockPlatform->setPrefersIdentityColumns(false);
0 ignored issues
show
Bug introduced by
The method setPrefersIdentityColumns() does not exist on Doctrine\DBAL\Platforms\AbstractPlatform. It seems like you code against a sub-type of Doctrine\DBAL\Platforms\AbstractPlatform such as Doctrine\Tests\Mocks\DatabasePlatformMock. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

48
        $mockPlatform->/** @scrutinizer ignore-call */ 
49
                       setPrefersIdentityColumns(false);
Loading history...
49
50
        $cm1 = $this->createValidClassMetadata();
51
52
        // SUT
53
        $cmf = new ClassMetadataFactory();
54
        $cmf->setEntityManager($entityManager);
55
        $cmf->setMetadataFor($cm1->getClassName(), $cm1);
56
57
        // Prechecks
58
        self::assertCount(0, $cm1->getAncestorsIterator());
59
        self::assertEquals(Mapping\InheritanceType::NONE, $cm1->inheritanceType);
60
        self::assertEquals(Mapping\GeneratorType::AUTO, $cm1->getProperty('id')->getValueGenerator()->getType());
0 ignored issues
show
Bug introduced by
The method getValueGenerator() does not exist on Doctrine\ORM\Mapping\Property. Did you maybe mean getValue()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

60
        self::assertEquals(Mapping\GeneratorType::AUTO, $cm1->getProperty('id')->/** @scrutinizer ignore-call */ getValueGenerator()->getType());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
61
        self::assertTrue($cm1->hasField('name'));
62
        self::assertCount(4, $cm1->getDeclaredPropertiesIterator()); // 2 fields + 2 associations
63
        self::assertEquals('group', $cm1->table->getName());
64
65
        // Go
66
        $cmMap1 = $cmf->getMetadataFor($cm1->getClassName());
67
68
        self::assertSame($cm1, $cmMap1);
69
        self::assertEquals('group', $cmMap1->table->getName());
70
        self::assertCount(0, $cmMap1->getAncestorsIterator());
71
        self::assertTrue($cmMap1->hasField('name'));
72
    }
73
74
    public function testGetMetadataForThrowsExceptionOnUnknownCustomGeneratorClass() : void
75
    {
76
        $cm1 = $this->createValidClassMetadata();
77
78
        $cm1->getProperty('id')->setValueGenerator(
0 ignored issues
show
Bug introduced by
The method setValueGenerator() does not exist on Doctrine\ORM\Mapping\Property. Did you maybe mean setValue()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

78
        $cm1->getProperty('id')->/** @scrutinizer ignore-call */ setValueGenerator(

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
79
            new Mapping\ValueGeneratorMetadata(
80
                Mapping\GeneratorType::CUSTOM,
81
                [
82
                    'class' => 'NotExistingGenerator',
83
                    'arguments' => [],
84
                ]
85
            )
86
        );
87
88
        $cmf = $this->createTestFactory();
89
90
        $cmf->setMetadataForClass($cm1->getClassName(), $cm1);
91
92
        $this->expectException(ORMException::class);
93
94
        $actual = $cmf->getMetadataFor($cm1->getClassName());
0 ignored issues
show
Unused Code introduced by
The assignment to $actual is dead and can be removed.
Loading history...
95
    }
96
97
    public function testGetMetadataForThrowsExceptionOnMissingCustomGeneratorDefinition() : void
98
    {
99
        $cm1 = $this->createValidClassMetadata();
100
101
        $cm1->getProperty('id')->setValueGenerator(
102
            new Mapping\ValueGeneratorMetadata(Mapping\GeneratorType::CUSTOM)
103
        );
104
105
        $cmf = $this->createTestFactory();
106
107
        $cmf->setMetadataForClass($cm1->getClassName(), $cm1);
108
109
        $this->expectException(ORMException::class);
110
111
        $actual = $cmf->getMetadataFor($cm1->getClassName());
0 ignored issues
show
Unused Code introduced by
The assignment to $actual is dead and can be removed.
Loading history...
112
    }
113
114
    public function testHasGetMetadataNamespaceSeparatorIsNotNormalized() : void
115
    {
116
        require_once __DIR__ . '/../../Models/Global/GlobalNamespaceModel.php';
117
118
        $metadataDriver = $this->createAnnotationDriver([__DIR__ . '/../../Models/Global/']);
119
120
        $entityManager = $this->createEntityManager($metadataDriver);
121
122
        $mf = $entityManager->getMetadataFactory();
123
124
        self::assertSame(
125
            $mf->getMetadataFor(DoctrineGlobalArticle::class),
126
            $mf->getMetadataFor('\\' . DoctrineGlobalArticle::class)
127
        );
128
        self::assertTrue($mf->hasMetadataFor(DoctrineGlobalArticle::class));
129
        self::assertTrue($mf->hasMetadataFor('\\' . DoctrineGlobalArticle::class));
130
    }
131
132
    /**
133
     * @group DDC-1512
134
     */
135
    public function testIsTransient() : void
136
    {
137
        $cmf    = new ClassMetadataFactory();
0 ignored issues
show
Unused Code introduced by
The assignment to $cmf is dead and can be removed.
Loading history...
138
        $driver = $this->createMock(MappingDriver::class);
139
        $driver->expects($this->at(0))
140
               ->method('isTransient')
141
               ->with($this->equalTo(CmsUser::class))
142
               ->will($this->returnValue(true));
143
        $driver->expects($this->at(1))
144
               ->method('isTransient')
145
               ->with($this->equalTo(CmsArticle::class))
146
               ->will($this->returnValue(false));
147
148
        $em = $this->createEntityManager($driver);
149
150
        self::assertTrue($em->getMetadataFactory()->isTransient(CmsUser::class));
151
        self::assertFalse($em->getMetadataFactory()->isTransient(CmsArticle::class));
152
    }
153
154
    /**
155
     * @dataProvider classesInInheritanceWithNoMapProvider()
156
     */
157
    public function testNoDefaultDiscriminatorMapIsAssumed(string $rootClassName, string $targetClassName) : void
158
    {
159
        $cmf    = new ClassMetadataFactory();
160
        $driver = $this->createAnnotationDriver([__DIR__ . '/../../Models/JoinedInheritanceType/']);
161
        $em     = $this->createEntityManager($driver);
162
        $cmf->setEntityManager($em);
163
164
        $this->expectException(MappingException::class);
165
        $this->expectExceptionMessage(
166
            sprintf("Entity class '%s' is using inheritance but no discriminator map was defined.", $rootClassName)
167
        );
168
169
        $cmf->getMetadataFor($targetClassName);
170
    }
171
172
    /**
173
     * @return string[]
174
     */
175
    public function classesInInheritanceWithNoMapProvider() : iterable
176
    {
177
        yield 'root entity' => [RootClass::class, RootClass::class];
0 ignored issues
show
Bug Best Practice introduced by
The expression yield 'root entity' => a...eType\RootClass::class) returns the type Generator which is incompatible with the documented return type string[].
Loading history...
178
        yield 'child entity' => [RootClass::class, ChildClass::class];
179
        yield 'another child entity' => [RootClass::class, AnotherChildClass::class];
180
    }
181
182
    public function testGetAllMetadataWorksWithBadConnection() : void
183
    {
184
        // DDC-3551
185
        $conn       = $this->createMock(Connection::class);
186
        $mockDriver = new MetadataDriverMock();
187
        $conn->expects($this->any())
188
            ->method('getEventManager')
189
            ->willReturn(new EventManager());
190
        $em = $this->createEntityManager($mockDriver, $conn);
191
192
        $conn->expects($this->any())
193
            ->method('getDatabasePlatform')
194
            ->will($this->throwException(new \Exception('Exception thrown in test when calling getDatabasePlatform')));
195
196
        $cmf = new ClassMetadataFactory();
197
        $cmf->setEntityManager($em);
198
199
        // getting all the metadata should work, even if get DatabasePlatform blows up
200
        $metadata = $cmf->getAllMetadata();
201
        // this will just be an empty array - there was no error
202
        self::assertEquals([], $metadata);
203
    }
204
205
    protected function createEntityManager($metadataDriver, $conn = null)
206
    {
207
        $driverMock = new DriverMock();
208
        $config     = new Configuration();
209
210
        $config->setProxyDir(__DIR__ . '/../../Proxies');
211
        $config->setProxyNamespace('Doctrine\Tests\Proxies');
212
213
        if (! $conn) {
214
            $conn = new ConnectionMock([], $driverMock, $config, new EventManager());
215
        }
216
        $eventManager = $conn->getEventManager();
217
218
        $config->setMetadataDriverImpl($metadataDriver);
219
220
        return EntityManagerMock::create($conn, $config, $eventManager);
221
    }
222
223
    /**
224
     * @return ClassMetadataFactoryTestSubject
225
     */
226
    protected function createTestFactory()
227
    {
228
        $mockDriver    = new MetadataDriverMock();
229
        $entityManager = $this->createEntityManager($mockDriver);
230
        $cmf           = new ClassMetadataFactoryTestSubject();
231
        $cmf->setEntityManager($entityManager);
232
        return $cmf;
233
    }
234
235
    /**
236
     * @return ClassMetadata
237
     */
238
    protected function createValidClassMetadata()
239
    {
240
        // Self-made metadata
241
        $metadataBuildingContext = new Mapping\ClassMetadataBuildingContext(
242
            $this->createMock(ClassMetadataFactory::class),
243
            new RuntimeReflectionService()
244
        );
245
246
        $cm1 = new ClassMetadata(TestEntity1::class, $metadataBuildingContext);
247
248
        $tableMetadata = new Mapping\TableMetadata();
249
        $tableMetadata->setName('group');
250
251
        $cm1->setTable($tableMetadata);
252
253
        // Add a mapped field
254
        $fieldMetadata = new Mapping\FieldMetadata('id');
255
256
        $fieldMetadata->setType(Type::getType('integer'));
257
        $fieldMetadata->setPrimaryKey(true);
258
        $fieldMetadata->setValueGenerator(new Mapping\ValueGeneratorMetadata(Mapping\GeneratorType::AUTO));
259
260
        $cm1->addProperty($fieldMetadata);
261
262
        // Add a mapped field
263
        $fieldMetadata = new Mapping\FieldMetadata('name');
264
265
        $fieldMetadata->setType(Type::getType('string'));
266
267
        $cm1->addProperty($fieldMetadata);
268
269
        // and a mapped association
270
        $association = new Mapping\OneToOneAssociationMetadata('other');
271
272
        $association->setTargetEntity(TestEntity1::class);
273
        $association->setMappedBy('this');
274
275
        $cm1->addProperty($association);
276
277
        // and an association on the owning side
278
        $joinColumns = [];
279
280
        $joinColumn = new Mapping\JoinColumnMetadata();
281
282
        $joinColumn->setColumnName('other_id');
283
        $joinColumn->setReferencedColumnName('id');
284
285
        $joinColumns[] = $joinColumn;
286
287
        $association = new Mapping\OneToOneAssociationMetadata('association');
288
289
        $association->setJoinColumns($joinColumns);
290
        $association->setTargetEntity(TestEntity1::class);
291
292
        $cm1->addProperty($association);
293
294
        return $cm1;
295
    }
296
297
    /**
298
     * @group DDC-1845
299
     */
300
    public function testQuoteMetadata() : void
301
    {
302
        $cmf    = new ClassMetadataFactory();
303
        $driver = $this->createAnnotationDriver([__DIR__ . '/../../Models/Quote/']);
304
        $em     = $this->createEntityManager($driver);
305
        $cmf->setEntityManager($em);
306
307
        $userMetadata    = $cmf->getMetadataFor(Quote\User::class);
308
        $phoneMetadata   = $cmf->getMetadataFor(Quote\Phone::class);
309
        $groupMetadata   = $cmf->getMetadataFor(Quote\Group::class);
310
        $addressMetadata = $cmf->getMetadataFor(Quote\Address::class);
311
312
        // Phone Class Metadata
313
        self::assertNotNull($phoneMetadata->getProperty('number'));
314
        self::assertEquals('phone-number', $phoneMetadata->getProperty('number')->getColumnName());
0 ignored issues
show
Bug introduced by
The method getColumnName() does not exist on Doctrine\ORM\Mapping\Property. It seems like you code against a sub-type of Doctrine\ORM\Mapping\Property such as Doctrine\ORM\Mapping\FieldMetadata. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

314
        self::assertEquals('phone-number', $phoneMetadata->getProperty('number')->/** @scrutinizer ignore-call */ getColumnName());
Loading history...
315
316
        $user                = $phoneMetadata->getProperty('user');
317
        $userJoinColumns     = $user->getJoinColumns();
0 ignored issues
show
Bug introduced by
The method getJoinColumns() does not exist on Doctrine\ORM\Mapping\Property. It seems like you code against a sub-type of Doctrine\ORM\Mapping\Property such as Doctrine\ORM\Mapping\ToOneAssociationMetadata. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

317
        /** @scrutinizer ignore-call */ 
318
        $userJoinColumns     = $user->getJoinColumns();
Loading history...
318
        $phoneUserJoinColumn = reset($userJoinColumns);
319
320
        self::assertEquals('user-id', $phoneUserJoinColumn->getColumnName());
321
        self::assertEquals('user-id', $phoneUserJoinColumn->getReferencedColumnName());
322
323
        // Address Class Metadata
324
        self::assertNotNull($addressMetadata->getProperty('id'));
325
        self::assertNotNull($addressMetadata->getProperty('zip'));
326
        self::assertEquals('address-id', $addressMetadata->getProperty('id')->getColumnName());
327
        self::assertEquals('address-zip', $addressMetadata->getProperty('zip')->getColumnName());
328
329
        // User Class Metadata
330
        self::assertNotNull($userMetadata->getProperty('id'));
331
        self::assertNotNull($userMetadata->getProperty('name'));
332
        self::assertEquals('user-id', $userMetadata->getProperty('id')->getColumnName());
333
        self::assertEquals('user-name', $userMetadata->getProperty('name')->getColumnName());
334
335
        $group               = $groupMetadata->getProperty('parent');
336
        $groupJoinColumns    = $group->getJoinColumns();
337
        $groupUserJoinColumn = reset($groupJoinColumns);
338
339
        self::assertEquals('parent-id', $groupUserJoinColumn->getColumnName());
340
        self::assertEquals('group-id', $groupUserJoinColumn->getReferencedColumnName());
341
342
        $user                  = $addressMetadata->getProperty('user');
343
        $userJoinColumns       = $user->getJoinColumns();
344
        $addressUserJoinColumn = reset($userJoinColumns);
345
346
        self::assertEquals('user-id', $addressUserJoinColumn->getColumnName());
347
        self::assertEquals('user-id', $addressUserJoinColumn->getReferencedColumnName());
348
349
        $groups                       = $userMetadata->getProperty('groups');
350
        $groupsJoinTable              = $groups->getJoinTable();
0 ignored issues
show
Bug introduced by
The method getJoinTable() does not exist on Doctrine\ORM\Mapping\Property. It seems like you code against a sub-type of Doctrine\ORM\Mapping\Property such as Doctrine\ORM\Mapping\ManyToManyAssociationMetadata. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

350
        /** @scrutinizer ignore-call */ 
351
        $groupsJoinTable              = $groups->getJoinTable();
Loading history...
351
        $userGroupsJoinColumns        = $groupsJoinTable->getJoinColumns();
352
        $userGroupsJoinColumn         = reset($userGroupsJoinColumns);
353
        $userGroupsInverseJoinColumns = $groupsJoinTable->getInverseJoinColumns();
354
        $userGroupsInverseJoinColumn  = reset($userGroupsInverseJoinColumns);
355
356
        self::assertEquals('quote-users-groups', $groupsJoinTable->getName());
357
        self::assertEquals('user-id', $userGroupsJoinColumn->getColumnName());
358
        self::assertEquals('user-id', $userGroupsJoinColumn->getReferencedColumnName());
359
        self::assertEquals('group-id', $userGroupsInverseJoinColumn->getColumnName());
360
        self::assertEquals('group-id', $userGroupsInverseJoinColumn->getReferencedColumnName());
361
    }
362
363
    /**
364
     * @group DDC-3385
365
     * @group 1181
366
     * @group 385
367
     */
368
    public function testFallbackLoadingCausesEventTriggeringThatCanModifyFetchedMetadata() : void
369
    {
370
        $test = $this;
371
372
        /** @var ClassMetadata $metadata */
373
        $metadata     = $this->createMock(ClassMetadata::class);
374
        $cmf          = new ClassMetadataFactory();
375
        $mockDriver   = new MetadataDriverMock();
376
        $em           = $this->createEntityManager($mockDriver);
377
        $listener     = $this->getMockBuilder(\stdClass::class)->setMethods(['onClassMetadataNotFound'])->getMock();
378
        $eventManager = $em->getEventManager();
379
380
        $cmf->setEntityManager($em);
381
382
        $listener
383
            ->expects($this->any())
384
            ->method('onClassMetadataNotFound')
385
            ->will($this->returnCallback(function (OnClassMetadataNotFoundEventArgs $args) use ($metadata, $em, $test) {
386
                $test->assertNull($args->getFoundMetadata());
387
                $test->assertSame('Foo', $args->getClassName());
388
                $test->assertSame($em, $args->getObjectManager());
389
390
                $args->setFoundMetadata($metadata);
391
            }));
392
393
        $eventManager->addEventListener([Events::onClassMetadataNotFound], $listener);
394
395
        self::assertSame($metadata, $cmf->getMetadataFor('Foo'));
396
    }
397
398
    /**
399
     * @group DDC-3427
400
     */
401
    public function testAcceptsEntityManagerInterfaceInstances() : void
402
    {
403
        $classMetadataFactory = new ClassMetadataFactory();
404
405
        /** @var EntityManagerInterface $entityManager */
406
        $entityManager = $this->createMock(EntityManagerInterface::class);
407
408
        $classMetadataFactory->setEntityManager($entityManager);
409
410
        // not really the cleanest way to check it, but we won't add a getter to the CMF just for the sake of testing.
411
        self::assertAttributeSame($entityManager, 'em', $classMetadataFactory);
412
    }
413
414
    /**
415
     * @group embedded
416
     * @group DDC-3305
417
     */
418
    public function testRejectsEmbeddableWithoutValidClassName() : void
419
    {
420
        $metadata = $this->createValidClassMetadata();
421
422
        $metadata->mapEmbedded(
423
            [
424
            'fieldName'    => 'embedded',
425
            'class'        => '',
426
            'columnPrefix' => false,
427
            ]
428
        );
429
430
        $cmf = $this->createTestFactory();
431
432
        $cmf->setMetadataForClass($metadata->getClassName(), $metadata);
433
434
        $this->expectException(MappingException::class);
435
        $this->expectExceptionMessage('The embed mapping \'embedded\' misses the \'class\' attribute.');
436
437
        $cmf->getMetadataFor($metadata->getClassName());
438
    }
439
440
    /**
441
     * @group embedded
442
     * @group DDC-4006
443
     */
444
    public function testInheritsIdGeneratorMappingFromEmbeddable() : void
445
    {
446
        $cmf    = new ClassMetadataFactory();
447
        $driver = $this->createAnnotationDriver([__DIR__ . '/../../Models/DDC4006/']);
448
        $em     = $this->createEntityManager($driver);
449
        $cmf->setEntityManager($em);
450
451
        $userMetadata = $cmf->getMetadataFor(DDC4006User::class);
452
453
        self::assertTrue($userMetadata->isIdGeneratorIdentity());
0 ignored issues
show
Bug introduced by
The method isIdGeneratorIdentity() does not exist on Doctrine\ORM\Mapping\ClassMetadata. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

453
        self::assertTrue($userMetadata->/** @scrutinizer ignore-call */ isIdGeneratorIdentity());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
454
    }
455
}
456
457
/* Test subject class with overridden factory method for mocking purposes */
458
class ClassMetadataFactoryTestSubject extends ClassMetadataFactory
459
{
460
    private $mockMetadata     = [];
461
    private $requestedClasses = [];
462
463
    protected function newClassMetadataInstance(
464
        string $className,
465
        ?Mapping\ClassMetadata $parent,
0 ignored issues
show
Unused Code introduced by
The parameter $parent is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

465
        /** @scrutinizer ignore-unused */ ?Mapping\ClassMetadata $parent,

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
466
        Mapping\ClassMetadataBuildingContext $metadataBuildingContext
0 ignored issues
show
Unused Code introduced by
The parameter $metadataBuildingContext is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

466
        /** @scrutinizer ignore-unused */ Mapping\ClassMetadataBuildingContext $metadataBuildingContext

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
467
    ) : ClassMetadata {
468
        $this->requestedClasses[] = $className;
469
470
        if (! isset($this->mockMetadata[$className])) {
471
            throw new \InvalidArgumentException(sprintf('No mock metadata found for class %s.', $className));
472
        }
473
474
        return $this->mockMetadata[$className];
475
    }
476
477
    public function setMetadataForClass($className, $metadata)
478
    {
479
        $this->mockMetadata[$className] = $metadata;
480
    }
481
482
    public function getRequestedClasses()
483
    {
484
        return $this->requestedClasses;
485
    }
486
}
487
488
class TestEntity1
489
{
490
    private $id;
0 ignored issues
show
introduced by
The private property $id is not used, and could be removed.
Loading history...
491
    private $name;
0 ignored issues
show
introduced by
The private property $name is not used, and could be removed.
Loading history...
492
    private $other;
0 ignored issues
show
introduced by
The private property $other is not used, and could be removed.
Loading history...
493
    private $association;
0 ignored issues
show
introduced by
The private property $association is not used, and could be removed.
Loading history...
494
    private $embedded;
0 ignored issues
show
introduced by
The private property $embedded is not used, and could be removed.
Loading history...
495
}
496
497
class CustomIdGenerator implements Generator
498
{
499
    /**
500
     * {@inheritdoc}
501
     */
502
    public function generate(EntityManagerInterface $em, ?object $entity)
503
    {
504
    }
505
506
    /**
507
     * {@inheritdoc}
508
     */
509
    public function isPostInsertGenerator() : bool
510
    {
511
        return false;
512
    }
513
}
514