Failed Conditions
Pull Request — master (#7085)
by Guilherme
11:32
created

testOwningSideResolution()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 54
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 32
nc 1
nop 0
dl 0
loc 54
rs 9.6716
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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\Annotation as ORM;
9
use Doctrine\ORM\EntityManagerInterface;
10
use Doctrine\ORM\Events;
11
use Doctrine\ORM\Mapping;
12
use Doctrine\ORM\Mapping\ClassMetadata;
13
use Doctrine\ORM\Mapping\ClassMetadataFactory;
14
use Doctrine\ORM\Mapping\Factory\DefaultNamingStrategy;
15
use Doctrine\ORM\Mapping\Factory\UnderscoreNamingStrategy;
16
use Doctrine\ORM\Mapping\MappingException;
17
use Doctrine\ORM\Reflection\RuntimeReflectionService;
18
use Doctrine\Tests\Models\Cache\City;
19
use Doctrine\Tests\Models\CMS\CmsAddress;
20
use Doctrine\Tests\Models\CMS\CmsAddressListener;
21
use Doctrine\Tests\Models\CMS\CmsUser;
22
use Doctrine\Tests\Models\Company\CompanyContract;
23
use Doctrine\Tests\Models\Company\CompanyContractListener;
24
use Doctrine\Tests\Models\Company\CompanyFixContract;
25
use Doctrine\Tests\Models\Company\CompanyFlexContract;
26
use Doctrine\Tests\Models\Company\CompanyFlexUltraContract;
27
use Doctrine\Tests\Models\Company\CompanyFlexUltraContractListener;
28
use Doctrine\Tests\Models\Company\CompanyPerson;
29
use Doctrine\Tests\Models\Quote;
30
use Doctrine\Tests\Models\DDC1476\DDC1476EntityWithDefaultFieldType;
31
use Doctrine\Tests\Models\DDC2825\ExplicitSchemaAndTable;
32
use Doctrine\Tests\Models\DDC2825\SchemaAndTableInTableName;
33
use Doctrine\Tests\Models\DDC3579\DDC3579Admin;
34
use Doctrine\Tests\Models\DDC5934\DDC5934Contract;
35
use Doctrine\Tests\Models\DDC869\DDC869ChequePayment;
36
use Doctrine\Tests\Models\DDC869\DDC869CreditCardPayment;
37
use Doctrine\Tests\Models\DDC869\DDC869PaymentRepository;
38
use Doctrine\Tests\Models\DDC889\DDC889Class;
39
use Doctrine\Tests\Models\DDC889\DDC889Entity;
40
use Doctrine\Tests\Models\DDC964\DDC964Admin;
41
use Doctrine\Tests\Models\DDC964\DDC964Guest;
42
use Doctrine\Tests\OrmTestCase;
43
44
abstract class AbstractMappingDriverTest extends OrmTestCase
45
{
46
    /**
47
     * @var Mapping\ClassMetadataBuildingContext
48
     */
49
    protected $metadataBuildingContext;
50
51
    public function setUp()
52
    {
53
        parent::setUp();
54
55
        $this->metadataBuildingContext = new Mapping\ClassMetadataBuildingContext(
56
            $this->createMock(ClassMetadataFactory::class),
57
            new RuntimeReflectionService()
58
        );
59
    }
60
61
    abstract protected function loadDriver();
62
63
    public function createClassMetadata($entityClassName)
64
    {
65
        $mappingDriver = $this->loadDriver();
66
67
        $class = new ClassMetadata($entityClassName, $this->metadataBuildingContext);
68
69
        $mappingDriver->loadMetadataForClass($entityClassName, $class, $this->metadataBuildingContext);
70
71
        return $class;
72
    }
73
74
    protected function createClassMetadataFactory(EntityManagerInterface $em = null) : ClassMetadataFactory
75
    {
76
        $driver     = $this->loadDriver();
77
        $em         = $em ?: $this->getTestEntityManager();
78
        $factory    = new ClassMetadataFactory();
79
80
        $em->getConfiguration()->setMetadataDriverImpl($driver);
81
        $factory->setEntityManager($em);
82
83
        return $factory;
84
    }
85
86
    /**
87
     * @param ClassMetadata $class
88
     */
89
    public function testEntityTableNameAndInheritance()
90
    {
91
        $class = $this->createClassMetadata(User::class);
92
93
        self::assertEquals('cms_users', $class->getTableName());
94
        self::assertEquals(Mapping\InheritanceType::NONE, $class->inheritanceType);
95
96
        return $class;
97
    }
98
99
    /**
100
     * @param ClassMetadata $class
101
     */
102
    public function testEntityIndexes()
103
    {
104
        $class = $this->createClassMetadata('Doctrine\Tests\ORM\Mapping\User');
105
106
        self::assertCount(2, $class->table->getIndexes());
107
        self::assertEquals(
108
            [
109
                'name_idx' => [
110
                    'name'    => 'name_idx',
111
                    'columns' => ['name'],
112
                    'unique'  => false,
113
                    'options' => [],
114
                    'flags'   => [],
115
                ],
116
                0 => [
117
                    'name'    => null,
118
                    'columns' => ['user_email'],
119
                    'unique'  => false,
120
                    'options' => [],
121
                    'flags'   => [],
122
                ]
123
            ],
124
            $class->table->getIndexes()
125
        );
126
127
        return $class;
128
    }
129
130
    public function testEntityIndexFlagsAndPartialIndexes()
131
    {
132
        $class = $this->createClassMetadata(Comment::class);
133
134
        self::assertEquals(
135
            [
136
                0 => [
137
                    'name'    => null,
138
                    'columns' => ['content'],
139
                    'unique'  => false,
140
                    'flags'   => ['fulltext'],
141
                    'options' => ['where' => 'content IS NOT NULL'],
142
                ]
143
            ],
144
            $class->table->getIndexes()
145
        );
146
    }
147
148
    /**
149
     * @depends testEntityTableNameAndInheritance
150
     * @param ClassMetadata $class
151
     */
152
    public function testEntityUniqueConstraints($class)
153
    {
154
        self::assertCount(1, $class->table->getUniqueConstraints());
155
        self::assertEquals(
156
            [
157
                'search_idx' => [
158
                    'name'    => 'search_idx',
159
                    'columns' => ['name', 'user_email'],
160
                    'options' => [],
161
                    'flags'   => [],
162
                ]
163
            ],
164
            $class->table->getUniqueConstraints()
165
        );
166
167
        return $class;
168
    }
169
170
    /**
171
     * @depends testEntityTableNameAndInheritance
172
     * @param ClassMetadata $class
173
     */
174
    public function testEntityOptions($class)
175
    {
176
        self::assertCount(2, $class->table->getOptions());
177
        self::assertEquals(
178
            [
179
                'foo' => 'bar',
180
                'baz' => ['key' => 'val']
181
            ],
182
            $class->table->getOptions()
183
        );
184
185
        return $class;
186
    }
187
188
    /**
189
     * @depends testEntityOptions
190
     * @param ClassMetadata $class
191
     */
192
    public function testEntitySequence($class)
193
    {
194
        self::assertInternalType(
195
            'array',
196
            $class->getProperty('id')->getValueGenerator()->getDefinition(),
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

196
            $class->getProperty('id')->/** @scrutinizer ignore-call */ getValueGenerator()->getDefinition(),

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...
197
            'No Sequence Definition set on this driver.'
198
        );
199
        self::assertEquals(
200
            [
201
                'sequenceName'   => 'tablename_seq',
202
                'allocationSize' => 100,
203
            ],
204
            $class->getProperty('id')->getValueGenerator()->getDefinition()
205
        );
206
    }
207
208
    public function testEntityCustomGenerator()
209
    {
210
        $class = $this->createClassMetadata(Animal::class);
211
212
        self::assertEquals(Mapping\GeneratorType::CUSTOM, $class->getProperty('id')->getValueGenerator()->getType(), "Generator Type");
213
        self::assertEquals(
214
            [
215
                'class'     => 'stdClass',
216
                'arguments' => [],
217
            ],
218
            $class->getProperty('id')->getValueGenerator()->getDefinition(),
219
            "Generator Definition"
220
        );
221
    }
222
223
224
    /**
225
     * @depends testEntityTableNameAndInheritance
226
     * @param ClassMetadata $class
227
     */
228
    public function testProperties($class)
229
    {
230
        self::assertCount(7, $class->getDeclaredPropertiesIterator());
0 ignored issues
show
Bug introduced by
$class->getDeclaredPropertiesIterator() of type Generator is incompatible with the type Countable|iterable expected by parameter $haystack of PHPUnit\Framework\Assert::assertCount(). ( Ignorable by Annotation )

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

230
        self::assertCount(7, /** @scrutinizer ignore-type */ $class->getDeclaredPropertiesIterator());
Loading history...
231
232
        self::assertNotNull($class->getProperty('id'));
233
        self::assertNotNull($class->getProperty('name'));
234
        self::assertNotNull($class->getProperty('email'));
235
        self::assertNotNull($class->getProperty('version'));
236
        self::assertNotNull($class->getProperty('version'));
237
238
        return $class;
239
    }
240
241
    /**
242
     * @depends testProperties
243
     * @param ClassMetadata $class
244
     */
245
    public function testVersionProperty($class)
246
    {
247
        self::assertTrue($class->isVersioned());
248
        self::assertNotNull($class->versionProperty);
249
250
        $versionPropertyName = $class->versionProperty->getName();
0 ignored issues
show
Bug introduced by
The method getName() does not exist on null. ( Ignorable by Annotation )

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

250
        /** @scrutinizer ignore-call */ 
251
        $versionPropertyName = $class->versionProperty->getName();

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...
251
252
        self::assertEquals("version", $versionPropertyName);
253
        self::assertNotNull($class->getProperty($versionPropertyName));
254
    }
255
256
    /**
257
     * @depends testEntityTableNameAndInheritance
258
     * @param ClassMetadata $class
259
     */
260
    public function testFieldMappingsColumnNames($class)
261
    {
262
        self::assertNotNull($class->getProperty('id'));
263
        self::assertNotNull($class->getProperty('name'));
264
        self::assertNotNull($class->getProperty('email'));
265
266
        self::assertEquals("id", $class->getProperty('id')->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

266
        self::assertEquals("id", $class->getProperty('id')->/** @scrutinizer ignore-call */ getColumnName());
Loading history...
267
        self::assertEquals("name", $class->getProperty('name')->getColumnName());
268
        self::assertEquals("user_email", $class->getProperty('email')->getColumnName());
269
270
        return $class;
271
    }
272
273
    /**
274
     * @depends testEntityTableNameAndInheritance
275
     * @param ClassMetadata $class
276
     */
277
    public function testStringFieldMappings($class)
278
    {
279
        self::assertNotNull($class->getProperty('name'));
280
281
        $property = $class->getProperty('name');
282
283
        self::assertEquals('string', $property->getTypeName());
0 ignored issues
show
Bug introduced by
The method getTypeName() 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

283
        self::assertEquals('string', $property->/** @scrutinizer ignore-call */ getTypeName());
Loading history...
284
        self::assertEquals(50, $property->getLength());
0 ignored issues
show
Bug introduced by
The method getLength() 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

284
        self::assertEquals(50, $property->/** @scrutinizer ignore-call */ getLength());
Loading history...
285
        self::assertTrue($property->isNullable());
0 ignored issues
show
Bug introduced by
The method isNullable() 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

285
        self::assertTrue($property->/** @scrutinizer ignore-call */ isNullable());
Loading history...
286
        self::assertTrue($property->isUnique());
0 ignored issues
show
Bug introduced by
The method isUnique() 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

286
        self::assertTrue($property->/** @scrutinizer ignore-call */ isUnique());
Loading history...
287
288
        return $class;
289
    }
290
291
    /**
292
     * @depends testEntityTableNameAndInheritance
293
     *
294
     * @param ClassMetadata $class
295
     *
296
     * @return ClassMetadata
297
     */
298
    public function testFieldOptions(ClassMetadata $class)
299
    {
300
        self::assertNotNull($class->getProperty('name'));
301
302
        $property = $class->getProperty('name');
303
        $expected = ['foo' => 'bar', 'baz' => ['key' => 'val'], 'fixed' => false];
304
305
        self::assertEquals($expected, $property->getOptions());
0 ignored issues
show
Bug introduced by
The method getOptions() 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

305
        self::assertEquals($expected, $property->/** @scrutinizer ignore-call */ getOptions());
Loading history...
306
307
        return $class;
308
    }
309
310
    /**
311
     * @depends testEntityTableNameAndInheritance
312
     * @param ClassMetadata $class
313
     */
314
    public function testIdFieldOptions($class)
315
    {
316
        self::assertNotNull($class->getProperty('id'));
317
318
        $property = $class->getProperty('id');
319
        $expected = ['foo' => 'bar', 'unsigned' => false];
320
321
        self::assertEquals($expected, $property->getOptions());
322
323
        return $class;
324
    }
325
326
    /**
327
     * @depends testProperties
328
     * @param ClassMetadata $class
329
     */
330
    public function testIdentifier($class)
331
    {
332
        self::assertNotNull($class->getProperty('id'));
333
334
        $property = $class->getProperty('id');
335
336
        self::assertEquals('integer', $property->getTypeName());
337
        self::assertEquals(['id'], $class->identifier);
338
        self::assertEquals(Mapping\GeneratorType::AUTO, $property->getValueGenerator()->getType(), "ID-Generator is not GeneratorType::AUTO");
339
340
        return $class;
341
    }
342
343
    /**
344
     * @group #6129
345
     *
346
     * @return ClassMetadata
347
     */
348
    public function testBooleanValuesForOptionIsSetCorrectly()
349
    {
350
        $class = $this->createClassMetadata(User::class);
351
352
        $idOptions = $class->getProperty('id')->getOptions();
353
        $nameOptions = $class->getProperty('name')->getOptions();
354
355
        self::assertInternalType('bool', $idOptions['unsigned']);
356
        self::assertFalse($idOptions['unsigned']);
357
        self::assertInternalType('bool', $nameOptions['fixed']);
358
        self::assertFalse($nameOptions['fixed']);
359
360
        return $class;
361
    }
362
363
    public function testOwningSideResolution() : void
364
    {
365
        // One to One owning
366
        $fullAddressClass = $this->createClassMetadata(Quote\FullAddress::class);
367
        $cityAssociation  = $fullAddressClass->getProperty('city');
368
369
        self::assertInstanceOf(Mapping\OneToOneAssociationMetadata::class, $cityAssociation);
370
        self::assertTrue($cityAssociation->isOwningSide());
0 ignored issues
show
Bug introduced by
The method isOwningSide() 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\AssociationMetadata. ( Ignorable by Annotation )

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

370
        self::assertTrue($cityAssociation->/** @scrutinizer ignore-call */ isOwningSide());
Loading history...
371
372
        // One to One owning / One To One inverse
373
        $addressClass    = $this->createClassMetadata(Quote\Address::class);
374
        $userAssociation = $addressClass->getProperty('user');
375
376
        self::assertInstanceOf(Mapping\OneToOneAssociationMetadata::class, $userAssociation);
377
        self::assertTrue($userAssociation->isOwningSide());
378
379
        $userClass          = $this->createClassMetadata(Quote\User::class);
380
        $addressAssociation = $userClass->getProperty('address');
381
382
        self::assertInstanceOf(Mapping\OneToOneAssociationMetadata::class, $addressAssociation);
383
        self::assertFalse($addressAssociation->isOwningSide());
384
385
        // Many to One owning
386
        $groupClass       = $this->createClassMetadata(Quote\Group::class);
387
        $groupAssociation = $groupClass->getProperty('parent');
388
389
        self::assertInstanceOf(Mapping\ManyToOneAssociationMetadata::class, $groupAssociation);
390
        self::assertTrue($groupAssociation->isOwningSide());
391
392
        // Many To One owning / One To Many inverse
393
        $phoneClass      = $this->createClassMetadata(Quote\Phone::class);
394
        $userAssociation = $phoneClass->getProperty('user');
395
396
        self::assertInstanceOf(Mapping\ManyToOneAssociationMetadata::class, $userAssociation);
397
        self::assertTrue($userAssociation->isOwningSide());
398
399
        $userClass        = $this->createClassMetadata(Quote\User::class);
400
        $phoneAssociation = $userClass->getProperty('phones');
401
402
        self::assertInstanceOf(Mapping\OneToManyAssociationMetadata::class, $phoneAssociation);
403
        self::assertFalse($phoneAssociation->isOwningSide());
404
405
        // Many to Many owning / Many to Many inverse
406
        $userClass        = $this->createClassMetadata(Quote\User::class);
407
        $groupAssociation = $userClass->getProperty('groups');
408
409
        self::assertInstanceOf(Mapping\ManyToManyAssociationMetadata::class, $groupAssociation);
410
        self::assertTrue($groupAssociation->isOwningSide());
411
412
        $groupClass      = $this->createClassMetadata(Quote\Group::class);
413
        $userAssociation = $groupClass->getProperty('users');
414
415
        self::assertInstanceOf(Mapping\ManyToManyAssociationMetadata::class, $userAssociation);
416
        self::assertFalse($userAssociation->isOwningSide());
417
    }
418
419
    /**
420
     * @depends testProperties
421
     * @param ClassMetadata $class
422
     */
423
    public function testOwningOneToOneAssociation($class)
424
    {
425
        self::assertArrayHasKey('address', iterator_to_array($class->getDeclaredPropertiesIterator()));
426
427
        $association = $class->getProperty('address');
428
429
        self::assertTrue($association->isOwningSide());
430
        self::assertEquals('user', $association->getInversedBy());
0 ignored issues
show
Bug introduced by
The method getInversedBy() 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\AssociationMetadata. ( Ignorable by Annotation )

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

430
        self::assertEquals('user', $association->/** @scrutinizer ignore-call */ getInversedBy());
Loading history...
431
        // Check cascading
432
        self::assertEquals(['remove'], $association->getCascade());
0 ignored issues
show
Bug introduced by
The method getCascade() 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\AssociationMetadata. ( Ignorable by Annotation )

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

432
        self::assertEquals(['remove'], $association->/** @scrutinizer ignore-call */ getCascade());
Loading history...
433
434
        return $class;
435
    }
436
437
    /**
438
     * @depends testOwningOneToOneAssociation
439
     * @param ClassMetadata $class
440
     */
441
    public function testInverseOneToManyAssociation($class)
442
    {
443
        self::assertArrayHasKey('phonenumbers', iterator_to_array($class->getDeclaredPropertiesIterator()));
444
445
        $association = $class->getProperty('phonenumbers');
446
447
        self::assertFalse($association->isOwningSide());
448
        self::assertTrue($association->isOrphanRemoval());
0 ignored issues
show
Bug introduced by
The method isOrphanRemoval() 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\AssociationMetadata. ( Ignorable by Annotation )

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

448
        self::assertTrue($association->/** @scrutinizer ignore-call */ isOrphanRemoval());
Loading history...
449
450
        // Check cascading
451
        self::assertEquals(['persist', 'remove'], $association->getCascade());
452
453
        // Test Order By
454
        self::assertEquals(['number' => 'ASC'], $association->getOrderBy());
0 ignored issues
show
Bug introduced by
The method getOrderBy() 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\ToManyAssociationMetadata. ( Ignorable by Annotation )

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

454
        self::assertEquals(['number' => 'ASC'], $association->/** @scrutinizer ignore-call */ getOrderBy());
Loading history...
455
456
        return $class;
457
    }
458
459
    /**
460
     * @depends testInverseOneToManyAssociation
461
     * @param ClassMetadata $class
462
     */
463
    public function testManyToManyAssociationWithCascadeAll($class)
464
    {
465
        self::assertArrayHasKey('groups', iterator_to_array($class->getDeclaredPropertiesIterator()));
466
467
        $association = $class->getProperty('groups');
468
469
        self::assertTrue($association->isOwningSide());
470
471
        // Make sure that cascade-all works as expected
472
        self::assertEquals(['remove', 'persist', 'refresh'], $association->getCascade());
473
474
        // Test Order By
475
        self::assertEquals([], $association->getOrderBy());
476
477
        return $class;
478
    }
479
480
    /**
481
     * @depends testManyToManyAssociationWithCascadeAll
482
     * @param ClassMetadata $class
483
     */
484
    public function testLifecycleCallbacks($class)
485
    {
486
        self::assertCount(2, $class->lifecycleCallbacks);
487
        self::assertEquals($class->lifecycleCallbacks['prePersist'][0], 'doStuffOnPrePersist');
488
        self::assertEquals($class->lifecycleCallbacks['postPersist'][0], 'doStuffOnPostPersist');
489
490
        return $class;
491
    }
492
493
    /**
494
     * @depends testManyToManyAssociationWithCascadeAll
495
     * @param ClassMetadata $class
496
     */
497
    public function testLifecycleCallbacksSupportMultipleMethodNames($class)
498
    {
499
        self::assertCount(2, $class->lifecycleCallbacks['prePersist']);
500
        self::assertEquals($class->lifecycleCallbacks['prePersist'][1], 'doOtherStuffOnPrePersistToo');
501
502
        return $class;
503
    }
504
505
    /**
506
     * @depends testLifecycleCallbacksSupportMultipleMethodNames
507
     * @param ClassMetadata $class
508
     */
509
    public function testJoinColumnUniqueAndNullable($class)
510
    {
511
        // Non-Nullability of Join Column
512
        $association = $class->getProperty('groups');
513
        $joinTable   = $association->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

513
        /** @scrutinizer ignore-call */ 
514
        $joinTable   = $association->getJoinTable();
Loading history...
514
        $joinColumns = $joinTable->getJoinColumns();
515
        $joinColumn  = reset($joinColumns);
516
517
        self::assertFalse($joinColumn->isNullable());
518
        self::assertFalse($joinColumn->isUnique());
519
520
        return $class;
521
    }
522
523
    /**
524
     * @depends testJoinColumnUniqueAndNullable
525
     * @param ClassMetadata $class
526
     */
527
    public function testColumnDefinition($class)
528
    {
529
        self::assertNotNull($class->getProperty('email'));
530
531
        $property           = $class->getProperty('email');
532
        $association        = $class->getProperty('groups');
533
        $joinTable          = $association->getJoinTable();
534
        $inverseJoinColumns = $joinTable->getInverseJoinColumns();
535
        $inverseJoinColumn  = reset($inverseJoinColumns);
536
537
        self::assertEquals("CHAR(32) NOT NULL", $property->getColumnDefinition());
0 ignored issues
show
Bug introduced by
The method getColumnDefinition() 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

537
        self::assertEquals("CHAR(32) NOT NULL", $property->/** @scrutinizer ignore-call */ getColumnDefinition());
Loading history...
538
        self::assertEquals("INT NULL", $inverseJoinColumn->getColumnDefinition());
539
540
        return $class;
541
    }
542
543
    /**
544
     * @depends testColumnDefinition
545
     * @param ClassMetadata $class
546
     */
547
    public function testJoinColumnOnDelete($class)
548
    {
549
        $association = $class->getProperty('address');
550
        $joinColumns = $association->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

550
        /** @scrutinizer ignore-call */ 
551
        $joinColumns = $association->getJoinColumns();
Loading history...
551
        $joinColumn  = reset($joinColumns);
552
553
        self::assertEquals('CASCADE', $joinColumn->getOnDelete());
554
555
        return $class;
556
    }
557
558
    /**
559
     * @group DDC-514
560
     */
561
    public function testDiscriminatorColumnDefaults()
562
    {
563
        if (strpos(get_class($this), 'PHPMappingDriver') !== false) {
564
            $this->markTestSkipped('PHP Mapping Drivers have no defaults.');
565
        }
566
567
        $class = $this->createClassMetadata(Animal::class);
568
569
        self::assertNotNull($class->discriminatorColumn);
570
571
        $discrColumn = $class->discriminatorColumn;
572
573
        self::assertEquals('Animal', $discrColumn->getTableName());
574
        self::assertEquals('discr', $discrColumn->getColumnName());
575
        self::assertEquals('string', $discrColumn->getTypeName());
576
        self::assertEquals(32, $discrColumn->getLength());
577
        self::assertNull($discrColumn->getColumnDefinition());
578
    }
579
580
    /**
581
     * @group DDC-869
582
     */
583
    public function testMappedSuperclassWithRepository()
584
    {
585
        $em      = $this->getTestEntityManager();
586
        $factory = $this->createClassMetadataFactory($em);
587
        $class   = $factory->getMetadataFor(DDC869CreditCardPayment::class);
588
589
        self::assertNotNull($class->getProperty('id'));
590
        self::assertNotNull($class->getProperty('value'));
591
        self::assertNotNull($class->getProperty('creditCardNumber'));
592
        self::assertEquals($class->getCustomRepositoryClassName(), DDC869PaymentRepository::class);
593
        self::assertInstanceOf(DDC869PaymentRepository::class, $em->getRepository(DDC869CreditCardPayment::class));
594
        self::assertTrue($em->getRepository(DDC869ChequePayment::class)->isTrue());
595
596
        $class = $factory->getMetadataFor(DDC869ChequePayment::class);
597
598
        self::assertNotNull($class->getProperty('id'));
599
        self::assertNotNull($class->getProperty('value'));
600
        self::assertNotNull($class->getProperty('serialNumber'));
601
        self::assertEquals($class->getCustomRepositoryClassName(), DDC869PaymentRepository::class);
602
        self::assertInstanceOf(DDC869PaymentRepository::class, $em->getRepository(DDC869ChequePayment::class));
603
        self::assertTrue($em->getRepository(DDC869ChequePayment::class)->isTrue());
604
    }
605
606
    /**
607
     * @group DDC-1476
608
     */
609
    public function testDefaultFieldType()
610
    {
611
        $factory = $this->createClassMetadataFactory();
612
        $class   = $factory->getMetadataFor(DDC1476EntityWithDefaultFieldType::class);
613
614
        self::assertNotNull($class->getProperty('id'));
615
        self::assertNotNull($class->getProperty('name'));
616
617
        $idProperty = $class->getProperty('id');
618
        $nameProperty = $class->getProperty('name');
619
620
        self::assertInstanceOf(Mapping\FieldMetadata::class, $idProperty);
621
        self::assertInstanceOf(Mapping\FieldMetadata::class, $nameProperty);
622
623
        self::assertEquals('string', $idProperty->getTypeName());
624
        self::assertEquals('string', $nameProperty->getTypeName());
625
626
        self::assertEquals('id', $idProperty->getName());
627
        self::assertEquals('name', $nameProperty->getName());
628
629
        self::assertEquals('id', $idProperty->getColumnName());
630
        self::assertEquals('name', $nameProperty->getColumnName());
631
632
        self::assertFalse($idProperty->hasValueGenerator());
0 ignored issues
show
Bug introduced by
The method hasValueGenerator() 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

632
        self::assertFalse($idProperty->/** @scrutinizer ignore-call */ hasValueGenerator());
Loading history...
633
    }
634
635
    /**
636
     * @group DDC-1170
637
     */
638
    public function testIdentifierColumnDefinition()
639
    {
640
        $class = $this->createClassMetadata(DDC1170Entity::class);
641
642
        self::assertNotNull($class->getProperty('id'));
643
        self::assertNotNull($class->getProperty('value'));
644
645
        self::assertEquals("INT unsigned NOT NULL", $class->getProperty('id')->getColumnDefinition());
646
        self::assertEquals("VARCHAR(255) NOT NULL", $class->getProperty('value')->getColumnDefinition());
647
    }
648
649
    /**
650
     * @group DDC-559
651
     */
652
    public function testNamingStrategy()
653
    {
654
        $em      = $this->getTestEntityManager();
655
        $factory = $this->createClassMetadataFactory($em);
656
657
        self::assertInstanceOf(DefaultNamingStrategy::class, $em->getConfiguration()->getNamingStrategy());
658
        $em->getConfiguration()->setNamingStrategy(new UnderscoreNamingStrategy(CASE_UPPER));
659
        self::assertInstanceOf(UnderscoreNamingStrategy::class, $em->getConfiguration()->getNamingStrategy());
660
661
        $class        = $factory->getMetadataFor(DDC1476EntityWithDefaultFieldType::class);
662
        $idProperty   = $class->getProperty('id');
663
        $nameProperty = $class->getProperty('name');
664
665
        self::assertEquals('ID', $idProperty->getColumnName());
666
        self::assertEquals('NAME', $nameProperty->getColumnName());
667
        self::assertEquals('DDC1476ENTITY_WITH_DEFAULT_FIELD_TYPE', $class->table->getName());
668
    }
669
670
    /**
671
     * @group DDC-807
672
     * @group DDC-553
673
     */
674
    public function testDiscriminatorColumnDefinition()
675
    {
676
        $class = $this->createClassMetadata(DDC807Entity::class);
677
678
        self::assertNotNull($class->discriminatorColumn);
679
680
        $discrColumn = $class->discriminatorColumn;
681
682
        self::assertEquals('dtype', $discrColumn->getColumnName());
683
        self::assertEquals("ENUM('ONE','TWO')", $discrColumn->getColumnDefinition());
684
    }
685
686
    /**
687
     * @group DDC-889
688
     */
689
    public function testInvalidEntityOrMappedSuperClassShouldMentionParentClasses()
690
    {
691
        $this->expectException(MappingException::class);
692
        $this->expectExceptionMessage('Class "Doctrine\Tests\Models\DDC889\DDC889Class" sub class of "Doctrine\Tests\Models\DDC889\DDC889SuperClass" is not a valid entity or mapped super class.');
693
694
        $this->createClassMetadata(DDC889Class::class);
695
    }
696
697
    /**
698
     * @group DDC-889
699
     */
700
    public function testIdentifierRequiredShouldMentionParentClasses()
701
    {
702
        $factory = $this->createClassMetadataFactory();
703
704
        $this->expectException(MappingException::class);
705
        $this->expectExceptionMessage('No identifier/primary key specified for Entity "Doctrine\Tests\Models\DDC889\DDC889Entity" sub class of "Doctrine\Tests\Models\DDC889\DDC889SuperClass". Every Entity must have an identifier/primary key.');
706
707
        $factory->getMetadataFor(DDC889Entity::class);
708
    }
709
710
    /**
711
     * @group DDC-1663
712
     */
713
    public function testNamedNativeQuery()
714
    {
715
        $class = $this->createClassMetadata(CmsAddress::class);
716
717
        // named native query
718
        self::assertCount(3, $class->namedNativeQueries);
719
        self::assertArrayHasKey('find-all', $class->namedNativeQueries);
720
        self::assertArrayHasKey('find-by-id', $class->namedNativeQueries);
721
722
        $findAllQuery = $class->getNamedNativeQuery('find-all');
723
724
        self::assertEquals('mapping-find-all', $findAllQuery['resultSetMapping']);
725
        self::assertEquals('SELECT id, country, city FROM cms_addresses', $findAllQuery['query']);
726
727
        $findByIdQuery = $class->getNamedNativeQuery('find-by-id');
728
729
        self::assertEquals(CmsAddress::class, $findByIdQuery['resultClass']);
730
        self::assertEquals('SELECT * FROM cms_addresses WHERE id = ?',  $findByIdQuery['query']);
731
732
        $countQuery = $class->getNamedNativeQuery('count');
733
734
        self::assertEquals('mapping-count', $countQuery['resultSetMapping']);
735
        self::assertEquals('SELECT COUNT(*) AS count FROM cms_addresses',  $countQuery['query']);
736
737
        // result set mapping
738
        self::assertCount(3, $class->sqlResultSetMappings);
739
        self::assertArrayHasKey('mapping-count', $class->sqlResultSetMappings);
740
        self::assertArrayHasKey('mapping-find-all', $class->sqlResultSetMappings);
741
        self::assertArrayHasKey('mapping-without-fields', $class->sqlResultSetMappings);
742
743
        $findAllMapping = $class->getSqlResultSetMapping('mapping-find-all');
744
745
        self::assertEquals(CmsAddress::class, $findAllMapping['entities'][0]['entityClass']);
746
        self::assertEquals(['name'=>'id','column'=>'id'], $findAllMapping['entities'][0]['fields'][0]);
747
        self::assertEquals(['name'=>'city','column'=>'city'], $findAllMapping['entities'][0]['fields'][1]);
748
        self::assertEquals(['name'=>'country','column'=>'country'], $findAllMapping['entities'][0]['fields'][2]);
749
750
        $withoutFieldsMapping = $class->getSqlResultSetMapping('mapping-without-fields');
751
752
        self::assertEquals('__CLASS__', $withoutFieldsMapping['entities'][0]['entityClass']);
753
        self::assertEquals([], $withoutFieldsMapping['entities'][0]['fields']);
754
755
        $countMapping = $class->getSqlResultSetMapping('mapping-count');
756
757
        self::assertEquals(['name'=>'count'], $countMapping['columns'][0]);
758
    }
759
760
    /**
761
     * @group DDC-1663
762
     */
763
    public function testSqlResultSetMapping()
764
    {
765
        $userMetadata   = $this->createClassMetadata(CmsUser::class);
766
        $personMetadata = $this->createClassMetadata(CompanyPerson::class);
767
768
        // user asserts
769
        self::assertCount(4, $userMetadata->getSqlResultSetMappings());
770
771
        $mapping = $userMetadata->getSqlResultSetMapping('mappingJoinedAddress');
772
773
        self::assertEquals([], $mapping['columns']);
774
        self::assertEquals('mappingJoinedAddress', $mapping['name']);
775
776
        self::assertNull($mapping['entities'][0]['discriminatorColumn']);
777
778
        self::assertEquals(['name'=>'id','column'=>'id'],                   $mapping['entities'][0]['fields'][0]);
779
        self::assertEquals(['name'=>'name','column'=>'name'],               $mapping['entities'][0]['fields'][1]);
780
        self::assertEquals(['name'=>'status','column'=>'status'],           $mapping['entities'][0]['fields'][2]);
781
        self::assertEquals(['name'=>'address.zip','column'=>'zip'],         $mapping['entities'][0]['fields'][3]);
782
        self::assertEquals(['name'=>'address.city','column'=>'city'],       $mapping['entities'][0]['fields'][4]);
783
        self::assertEquals(['name'=>'address.country','column'=>'country'], $mapping['entities'][0]['fields'][5]);
784
        self::assertEquals(['name'=>'address.id','column'=>'a_id'],         $mapping['entities'][0]['fields'][6]);
785
        self::assertEquals('__CLASS__',                            $mapping['entities'][0]['entityClass']);
786
787
        $mapping = $userMetadata->getSqlResultSetMapping('mappingJoinedPhonenumber');
788
789
        self::assertEquals([], $mapping['columns']);
790
        self::assertEquals('mappingJoinedPhonenumber', $mapping['name']);
791
792
        self::assertNull($mapping['entities'][0]['discriminatorColumn']);
793
794
        self::assertEquals(['name'=>'id','column'=>'id'],                             $mapping['entities'][0]['fields'][0]);
795
        self::assertEquals(['name'=>'name','column'=>'name'],                         $mapping['entities'][0]['fields'][1]);
796
        self::assertEquals(['name'=>'status','column'=>'status'],                     $mapping['entities'][0]['fields'][2]);
797
        self::assertEquals(['name'=>'phonenumbers.phonenumber','column'=>'number'],   $mapping['entities'][0]['fields'][3]);
798
        self::assertEquals($userMetadata->getClassName(),                             $mapping['entities'][0]['entityClass']);
799
800
        $mapping = $userMetadata->getSqlResultSetMapping('mappingUserPhonenumberCount');
801
802
        self::assertEquals(['name'=>'numphones'], $mapping['columns'][0]);
803
        self::assertEquals('mappingUserPhonenumberCount', $mapping['name']);
804
805
        self::assertNull($mapping['entities'][0]['discriminatorColumn']);
806
807
        self::assertEquals(['name'=>'id','column'=>'id'],         $mapping['entities'][0]['fields'][0]);
808
        self::assertEquals(['name'=>'name','column'=>'name'],     $mapping['entities'][0]['fields'][1]);
809
        self::assertEquals(['name'=>'status','column'=>'status'], $mapping['entities'][0]['fields'][2]);
810
        self::assertEquals($userMetadata->getClassName(),         $mapping['entities'][0]['entityClass']);
811
812
        $mapping = $userMetadata->getSqlResultSetMapping('mappingMultipleJoinsEntityResults');
813
814
        self::assertEquals(['name'=>'numphones'], $mapping['columns'][0]);
815
        self::assertEquals('mappingMultipleJoinsEntityResults', $mapping['name']);
816
817
        self::assertNull($mapping['entities'][0]['discriminatorColumn']);
818
819
        self::assertEquals(['name'=>'id','column'=>'u_id'],           $mapping['entities'][0]['fields'][0]);
820
        self::assertEquals(['name'=>'name','column'=>'u_name'],       $mapping['entities'][0]['fields'][1]);
821
        self::assertEquals(['name'=>'status','column'=>'u_status'],   $mapping['entities'][0]['fields'][2]);
822
        self::assertEquals('__CLASS__',                      $mapping['entities'][0]['entityClass']);
823
824
        self::assertNull($mapping['entities'][1]['discriminatorColumn']);
825
826
        self::assertEquals(['name'=>'id','column'=>'a_id'],           $mapping['entities'][1]['fields'][0]);
827
        self::assertEquals(['name'=>'zip','column'=>'a_zip'],         $mapping['entities'][1]['fields'][1]);
828
        self::assertEquals(['name'=>'country','column'=>'a_country'], $mapping['entities'][1]['fields'][2]);
829
        self::assertEquals(CmsAddress::class,                $mapping['entities'][1]['entityClass']);
830
831
        //person asserts
832
        self::assertCount(1, $personMetadata->getSqlResultSetMappings());
833
834
        $mapping = $personMetadata->getSqlResultSetMapping('mappingFetchAll');
835
836
        self::assertEquals([], $mapping['columns']);
837
        self::assertEquals('mappingFetchAll', $mapping['name']);
838
839
        self::assertEquals('discriminator', $mapping['entities'][0]['discriminatorColumn']);
840
841
        self::assertEquals(['name'=>'id','column'=>'id'],     $mapping['entities'][0]['fields'][0]);
842
        self::assertEquals(['name'=>'name','column'=>'name'], $mapping['entities'][0]['fields'][1]);
843
        self::assertEquals('__CLASS__',              $mapping['entities'][0]['entityClass']);
844
    }
845
846
    /*
847
     * @group DDC-964
848
     */
849
    public function testAssociationOverridesMapping()
850
    {
851
        $factory        = $this->createClassMetadataFactory();
852
        $adminMetadata  = $factory->getMetadataFor(DDC964Admin::class);
853
        $guestMetadata  = $factory->getMetadataFor(DDC964Guest::class);
854
855
        // assert groups association mappings
856
        self::assertArrayHasKey('groups', iterator_to_array($guestMetadata->getDeclaredPropertiesIterator()));
857
        self::assertArrayHasKey('groups', iterator_to_array($adminMetadata->getDeclaredPropertiesIterator()));
858
859
        $guestGroups = $guestMetadata->getProperty('groups');
860
        $adminGroups = $adminMetadata->getProperty('groups');
861
862
        // assert not override attributes
863
        self::assertEquals($guestGroups->getName(), $adminGroups->getName());
864
        self::assertEquals(get_class($guestGroups), get_class($adminGroups));
865
        self::assertEquals($guestGroups->getMappedBy(), $adminGroups->getMappedBy());
0 ignored issues
show
Bug introduced by
The method getMappedBy() 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\AssociationMetadata. ( Ignorable by Annotation )

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

865
        self::assertEquals($guestGroups->/** @scrutinizer ignore-call */ getMappedBy(), $adminGroups->getMappedBy());
Loading history...
866
        self::assertEquals($guestGroups->getInversedBy(), $adminGroups->getInversedBy());
867
        self::assertEquals($guestGroups->isOwningSide(), $adminGroups->isOwningSide());
868
        self::assertEquals($guestGroups->getFetchMode(), $adminGroups->getFetchMode());
0 ignored issues
show
Bug introduced by
The method getFetchMode() 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\AssociationMetadata. ( Ignorable by Annotation )

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

868
        self::assertEquals($guestGroups->/** @scrutinizer ignore-call */ getFetchMode(), $adminGroups->getFetchMode());
Loading history...
869
        self::assertEquals($guestGroups->getCascade(), $adminGroups->getCascade());
870
871
        // assert not override attributes
872
        $guestGroupsJoinTable          = $guestGroups->getJoinTable();
873
        $guestGroupsJoinColumns        = $guestGroupsJoinTable->getJoinColumns();
874
        $guestGroupsJoinColumn         = reset($guestGroupsJoinColumns);
875
        $guestGroupsInverseJoinColumns = $guestGroupsJoinTable->getInverseJoinColumns();
876
        $guestGroupsInverseJoinColumn  = reset($guestGroupsInverseJoinColumns);
877
878
        self::assertEquals('ddc964_users_groups', $guestGroupsJoinTable->getName());
879
        self::assertEquals('user_id', $guestGroupsJoinColumn->getColumnName());
880
        self::assertEquals('group_id', $guestGroupsInverseJoinColumn->getColumnName());
881
882
        $adminGroupsJoinTable          = $adminGroups->getJoinTable();
883
        $adminGroupsJoinColumns        = $adminGroupsJoinTable->getJoinColumns();
884
        $adminGroupsJoinColumn         = reset($adminGroupsJoinColumns);
885
        $adminGroupsInverseJoinColumns = $adminGroupsJoinTable->getInverseJoinColumns();
886
        $adminGroupsInverseJoinColumn  = reset($adminGroupsInverseJoinColumns);
887
888
        self::assertEquals('ddc964_users_admingroups', $adminGroupsJoinTable->getName());
889
        self::assertEquals('adminuser_id', $adminGroupsJoinColumn->getColumnName());
890
        self::assertEquals('admingroup_id', $adminGroupsInverseJoinColumn->getColumnName());
891
892
        // assert address association mappings
893
        self::assertArrayHasKey('address', iterator_to_array($guestMetadata->getDeclaredPropertiesIterator()));
894
        self::assertArrayHasKey('address', iterator_to_array($adminMetadata->getDeclaredPropertiesIterator()));
895
896
        $guestAddress = $guestMetadata->getProperty('address');
897
        $adminAddress = $adminMetadata->getProperty('address');
898
899
        // assert not override attributes
900
        self::assertEquals($guestAddress->getName(), $adminAddress->getName());
901
        self::assertEquals(get_class($guestAddress), get_class($adminAddress));
902
        self::assertEquals($guestAddress->getMappedBy(), $adminAddress->getMappedBy());
903
        self::assertEquals($guestAddress->getInversedBy(), $adminAddress->getInversedBy());
904
        self::assertEquals($guestAddress->isOwningSide(), $adminAddress->isOwningSide());
905
        self::assertEquals($guestAddress->getFetchMode(), $adminAddress->getFetchMode());
906
        self::assertEquals($guestAddress->getCascade(), $adminAddress->getCascade());
907
908
        // assert override
909
        $guestAddressJoinColumns = $guestAddress->getJoinColumns();
910
        $guestAddressJoinColumn  = reset($guestAddressJoinColumns);
911
912
        self::assertEquals('address_id', $guestAddressJoinColumn->getColumnName());
913
914
        $adminAddressJoinColumns = $adminAddress->getJoinColumns();
915
        $adminAddressJoinColumn  = reset($adminAddressJoinColumns);
916
917
        self::assertEquals('adminaddress_id', $adminAddressJoinColumn->getColumnName());
918
    }
919
920
    /*
921
     * @group DDC-3579
922
     */
923
    public function testInversedByOverrideMapping()
924
    {
925
        $factory        = $this->createClassMetadataFactory();
926
        $adminMetadata  = $factory->getMetadataFor(DDC3579Admin::class);
927
928
        // assert groups association mappings
929
        self::assertArrayHasKey('groups', iterator_to_array($adminMetadata->getDeclaredPropertiesIterator()));
930
931
        $adminGroups = $adminMetadata->getProperty('groups');
932
933
        // assert override
934
        self::assertEquals('admins', $adminGroups->getInversedBy());
935
    }
936
937
    /**
938
     * @group DDC-5934
939
     */
940
    public function testFetchOverrideMapping()
941
    {
942
        // check override metadata
943
        $contractMetadata = $this->createClassMetadataFactory()->getMetadataFor(DDC5934Contract::class);
944
945
        self::assertArrayHasKey('members', iterator_to_array($contractMetadata->getDeclaredPropertiesIterator()));
946
947
        $contractMembers = $contractMetadata->getProperty('members');
948
949
        self::assertSame(Mapping\FetchMode::EXTRA_LAZY, $contractMembers->getFetchMode());
950
    }
951
952
    /**
953
     * @group DDC-964
954
     */
955
    public function testAttributeOverridesMapping()
956
    {
957
        $factory       = $this->createClassMetadataFactory();
958
        $adminMetadata = $factory->getMetadataFor(DDC964Admin::class);
959
960
        self::assertEquals(
961
            [
962
                'user_id' => 'id',
963
                'user_name' => 'name',
964
                'adminaddress_id' => 'address',
965
            ],
966
            $adminMetadata->fieldNames
967
        );
968
969
        self::assertNotNull($adminMetadata->getProperty('id'));
970
971
        $idProperty = $adminMetadata->getProperty('id');
972
973
        self::assertTrue($idProperty->isPrimaryKey());
974
        self::assertEquals('id', $idProperty->getName());
975
        self::assertEquals('user_id', $idProperty->getColumnName());
976
977
        self::assertNotNull($adminMetadata->getProperty('name'));
978
979
        $nameProperty = $adminMetadata->getProperty('name');
980
981
        self::assertEquals('name', $nameProperty->getName());
982
        self::assertEquals('user_name', $nameProperty->getColumnName());
983
        self::assertEquals(250, $nameProperty->getLength());
984
        self::assertTrue($nameProperty->isNullable());
985
        self::assertFalse($nameProperty->isUnique());
986
987
        $guestMetadata = $factory->getMetadataFor(DDC964Guest::class);
988
989
        self::assertEquals(
990
            [
991
                'guest_id' => 'id',
992
                'guest_name' => 'name',
993
                'address_id' => 'address',
994
            ],
995
            $guestMetadata->fieldNames
996
        );
997
998
        self::assertNotNull($guestMetadata->getProperty('id'));
999
1000
        $idProperty = $guestMetadata->getProperty('id');
1001
1002
        self::assertTrue($idProperty->isPrimaryKey());
1003
        self::assertEquals('id', $idProperty->getName());
1004
        self::assertEquals('guest_id', $idProperty->getColumnName());
1005
1006
        self::assertNotNull($guestMetadata->getProperty('name'));
1007
1008
        $nameProperty = $guestMetadata->getProperty('name');
1009
1010
        self::assertEquals('name', $nameProperty->getName());
1011
        self::assertEquals('guest_name', $nameProperty->getColumnName());
1012
        self::assertEquals(240, $nameProperty->getLength());
1013
        self::assertFalse($nameProperty->isNullable());
1014
        self::assertTrue($nameProperty->isUnique());
1015
    }
1016
1017
    /**
1018
     * @group DDC-1955
1019
     */
1020
    public function testEntityListeners()
1021
    {
1022
        $factory    = $this->createClassMetadataFactory();
1023
        $superClass = $factory->getMetadataFor(CompanyContract::class);
1024
        $flexClass  = $factory->getMetadataFor(CompanyFixContract::class);
1025
        $fixClass   = $factory->getMetadataFor(CompanyFlexContract::class);
1026
1027
        self::assertArrayHasKey(Events::prePersist, $superClass->entityListeners);
1028
        self::assertArrayHasKey(Events::postPersist, $superClass->entityListeners);
1029
1030
        self::assertCount(1, $superClass->entityListeners[Events::prePersist]);
1031
        self::assertCount(1, $superClass->entityListeners[Events::postPersist]);
1032
1033
        $postPersist = $superClass->entityListeners[Events::postPersist][0];
1034
        $prePersist  = $superClass->entityListeners[Events::prePersist][0];
1035
1036
        self::assertEquals(CompanyContractListener::class, $postPersist['class']);
1037
        self::assertEquals(CompanyContractListener::class, $prePersist['class']);
1038
        self::assertEquals('postPersistHandler', $postPersist['method']);
1039
        self::assertEquals('prePersistHandler', $prePersist['method']);
1040
1041
        //Inherited listeners
1042
        self::assertEquals($fixClass->entityListeners, $superClass->entityListeners);
1043
        self::assertEquals($flexClass->entityListeners, $superClass->entityListeners);
1044
    }
1045
1046
    /**
1047
     * @group DDC-1955
1048
     */
1049
    public function testEntityListenersOverride()
1050
    {
1051
        $factory    = $this->createClassMetadataFactory();
1052
        $ultraClass = $factory->getMetadataFor(CompanyFlexUltraContract::class);
1053
1054
        //overridden listeners
1055
        self::assertArrayHasKey(Events::postPersist, $ultraClass->entityListeners);
1056
        self::assertArrayHasKey(Events::prePersist, $ultraClass->entityListeners);
1057
1058
        self::assertCount(1, $ultraClass->entityListeners[Events::postPersist]);
1059
        self::assertCount(3, $ultraClass->entityListeners[Events::prePersist]);
1060
1061
        $postPersist = $ultraClass->entityListeners[Events::postPersist][0];
1062
        $prePersist  = $ultraClass->entityListeners[Events::prePersist][0];
1063
1064
        self::assertEquals(CompanyContractListener::class, $postPersist['class']);
1065
        self::assertEquals(CompanyContractListener::class, $prePersist['class']);
1066
        self::assertEquals('postPersistHandler', $postPersist['method']);
1067
        self::assertEquals('prePersistHandler', $prePersist['method']);
1068
1069
        $prePersist = $ultraClass->entityListeners[Events::prePersist][1];
1070
        self::assertEquals(CompanyFlexUltraContractListener::class, $prePersist['class']);
1071
        self::assertEquals('prePersistHandler1', $prePersist['method']);
1072
1073
        $prePersist = $ultraClass->entityListeners[Events::prePersist][2];
1074
        self::assertEquals(CompanyFlexUltraContractListener::class, $prePersist['class']);
1075
        self::assertEquals('prePersistHandler2', $prePersist['method']);
1076
    }
1077
1078
1079
    /**
1080
     * @group DDC-1955
1081
     */
1082
    public function testEntityListenersNamingConvention()
1083
    {
1084
        $factory  = $this->createClassMetadataFactory();
1085
        $metadata = $factory->getMetadataFor(CmsAddress::class);
1086
1087
        self::assertArrayHasKey(Events::postPersist, $metadata->entityListeners);
1088
        self::assertArrayHasKey(Events::prePersist, $metadata->entityListeners);
1089
        self::assertArrayHasKey(Events::postUpdate, $metadata->entityListeners);
1090
        self::assertArrayHasKey(Events::preUpdate, $metadata->entityListeners);
1091
        self::assertArrayHasKey(Events::postRemove, $metadata->entityListeners);
1092
        self::assertArrayHasKey(Events::preRemove, $metadata->entityListeners);
1093
        self::assertArrayHasKey(Events::postLoad, $metadata->entityListeners);
1094
        self::assertArrayHasKey(Events::preFlush, $metadata->entityListeners);
1095
1096
        self::assertCount(1, $metadata->entityListeners[Events::postPersist]);
1097
        self::assertCount(1, $metadata->entityListeners[Events::prePersist]);
1098
        self::assertCount(1, $metadata->entityListeners[Events::postUpdate]);
1099
        self::assertCount(1, $metadata->entityListeners[Events::preUpdate]);
1100
        self::assertCount(1, $metadata->entityListeners[Events::postRemove]);
1101
        self::assertCount(1, $metadata->entityListeners[Events::preRemove]);
1102
        self::assertCount(1, $metadata->entityListeners[Events::postLoad]);
1103
        self::assertCount(1, $metadata->entityListeners[Events::preFlush]);
1104
1105
        $postPersist = $metadata->entityListeners[Events::postPersist][0];
1106
        $prePersist  = $metadata->entityListeners[Events::prePersist][0];
1107
        $postUpdate  = $metadata->entityListeners[Events::postUpdate][0];
1108
        $preUpdate   = $metadata->entityListeners[Events::preUpdate][0];
1109
        $postRemove  = $metadata->entityListeners[Events::postRemove][0];
1110
        $preRemove   = $metadata->entityListeners[Events::preRemove][0];
1111
        $postLoad    = $metadata->entityListeners[Events::postLoad][0];
1112
        $preFlush    = $metadata->entityListeners[Events::preFlush][0];
1113
1114
        self::assertEquals(CmsAddressListener::class, $postPersist['class']);
1115
        self::assertEquals(CmsAddressListener::class, $prePersist['class']);
1116
        self::assertEquals(CmsAddressListener::class, $postUpdate['class']);
1117
        self::assertEquals(CmsAddressListener::class, $preUpdate['class']);
1118
        self::assertEquals(CmsAddressListener::class, $postRemove['class']);
1119
        self::assertEquals(CmsAddressListener::class, $preRemove['class']);
1120
        self::assertEquals(CmsAddressListener::class, $postLoad['class']);
1121
        self::assertEquals(CmsAddressListener::class, $preFlush['class']);
1122
1123
        self::assertEquals(Events::postPersist, $postPersist['method']);
1124
        self::assertEquals(Events::prePersist, $prePersist['method']);
1125
        self::assertEquals(Events::postUpdate, $postUpdate['method']);
1126
        self::assertEquals(Events::preUpdate, $preUpdate['method']);
1127
        self::assertEquals(Events::postRemove, $postRemove['method']);
1128
        self::assertEquals(Events::preRemove, $preRemove['method']);
1129
        self::assertEquals(Events::postLoad, $postLoad['method']);
1130
        self::assertEquals(Events::preFlush, $preFlush['method']);
1131
    }
1132
1133
    /**
1134
     * @group DDC-2183
1135
     */
1136
    public function testSecondLevelCacheMapping()
1137
    {
1138
        $factory = $this->createClassMetadataFactory();
1139
        $class   = $factory->getMetadataFor(City::class);
1140
1141
        self::assertNotNull($class->getCache());
1142
        self::assertEquals(Mapping\CacheUsage::READ_ONLY, $class->getCache()->getUsage());
1143
        self::assertEquals('doctrine_tests_models_cache_city', $class->getCache()->getRegion());
1144
1145
        self::assertArrayHasKey('state', iterator_to_array($class->getDeclaredPropertiesIterator()));
1146
1147
        $stateAssociation = $class->getProperty('state');
1148
1149
        self::assertNotNull($stateAssociation->getCache());
0 ignored issues
show
Bug introduced by
The method getCache() 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\AssociationMetadata or Doctrine\ORM\Mapping\EmbeddedClassMetadata. ( Ignorable by Annotation )

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

1149
        self::assertNotNull($stateAssociation->/** @scrutinizer ignore-call */ getCache());
Loading history...
1150
        self::assertEquals(Mapping\CacheUsage::READ_ONLY, $stateAssociation->getCache()->getUsage());
1151
        self::assertEquals('doctrine_tests_models_cache_city__state', $stateAssociation->getCache()->getRegion());
1152
1153
        self::assertArrayHasKey('attractions', iterator_to_array($class->getDeclaredPropertiesIterator()));
1154
1155
        $attractionsAssociation = $class->getProperty('attractions');
1156
1157
        self::assertNotNull($attractionsAssociation->getCache());
1158
        self::assertEquals(Mapping\CacheUsage::READ_ONLY, $attractionsAssociation->getCache()->getUsage());
1159
        self::assertEquals('doctrine_tests_models_cache_city__attractions', $attractionsAssociation->getCache()->getRegion());
1160
    }
1161
1162
    /**
1163
     * @group DDC-2825
1164
     * @group 881
1165
     */
1166
    public function testSchemaDefinitionViaExplicitTableSchemaAnnotationProperty()
1167
    {
1168
        $factory  = $this->createClassMetadataFactory();
1169
        $metadata = $factory->getMetadataFor(ExplicitSchemaAndTable::class);
1170
1171
        self::assertSame('explicit_schema', $metadata->getSchemaName());
1172
        self::assertSame('explicit_table', $metadata->getTableName());
1173
    }
1174
1175
    /**
1176
     * @group DDC-2825
1177
     * @group 881
1178
     */
1179
    public function testSchemaDefinitionViaSchemaDefinedInTableNameInTableAnnotationProperty()
1180
    {
1181
        $factory  = $this->createClassMetadataFactory();
1182
        $metadata = $factory->getMetadataFor(SchemaAndTableInTableName::class);
1183
1184
        self::assertSame('implicit_schema', $metadata->getSchemaName());
1185
        self::assertSame('implicit_table', $metadata->getTableName());
1186
    }
1187
1188
    /**
1189
     * @group DDC-514
1190
     * @group DDC-1015
1191
     */
1192
    public function testDiscriminatorColumnDefaultLength()
1193
    {
1194
        if (strpos(get_class($this), 'PHPMappingDriver') !== false) {
1195
            $this->markTestSkipped('PHP Mapping Drivers have no defaults.');
1196
        }
1197
1198
        $class = $this->createClassMetadata(SingleTableEntityNoDiscriminatorColumnMapping::class);
1199
1200
        self::assertEquals(255, $class->discriminatorColumn->getLength());
1201
1202
        $class = $this->createClassMetadata(SingleTableEntityIncompleteDiscriminatorColumnMapping::class);
1203
1204
        self::assertEquals(255, $class->discriminatorColumn->getLength());
1205
    }
1206
1207
    /**
1208
     * @group DDC-514
1209
     * @group DDC-1015
1210
     */
1211
    public function testDiscriminatorColumnDefaultType()
1212
    {
1213
        if (strpos(get_class($this), 'PHPMappingDriver') !== false) {
1214
            $this->markTestSkipped('PHP Mapping Drivers have no defaults.');
1215
        }
1216
1217
        $class = $this->createClassMetadata(SingleTableEntityNoDiscriminatorColumnMapping::class);
1218
1219
        self::assertEquals('string', $class->discriminatorColumn->getTypeName());
1220
1221
        $class = $this->createClassMetadata(SingleTableEntityIncompleteDiscriminatorColumnMapping::class);
1222
1223
        self::assertEquals('string', $class->discriminatorColumn->getTypeName());
1224
    }
1225
1226
    /**
1227
     * @group DDC-514
1228
     * @group DDC-1015
1229
     */
1230
    public function testDiscriminatorColumnDefaultName()
1231
    {
1232
        if (strpos(get_class($this), 'PHPMappingDriver') !== false) {
1233
            $this->markTestSkipped('PHP Mapping Drivers have no defaults.');
1234
        }
1235
1236
        $class = $this->createClassMetadata(SingleTableEntityNoDiscriminatorColumnMapping::class);
1237
1238
        self::assertEquals('dtype', $class->discriminatorColumn->getColumnName());
1239
1240
        $class = $this->createClassMetadata(SingleTableEntityIncompleteDiscriminatorColumnMapping::class);
1241
1242
        self::assertEquals('dtype', $class->discriminatorColumn->getColumnName());
1243
    }
1244
}
1245
1246
/**
1247
 * @ORM\Entity
1248
 * @ORM\HasLifecycleCallbacks
1249
 * @ORM\Table(
1250
 *  name="cms_users",
1251
 *  uniqueConstraints={@ORM\UniqueConstraint(name="search_idx", columns={"name", "user_email"})},
1252
 *  indexes={@ORM\Index(name="name_idx", columns={"name"}), @ORM\Index(columns={"user_email"})},
1253
 *  options={"foo": "bar", "baz": {"key": "val"}}
1254
 * )
1255
 */
1256
class User
1257
{
1258
    /**
1259
     * @ORM\Id
1260
     * @ORM\Column(type="integer", options={"foo": "bar", "unsigned": false})
1261
     * @ORM\GeneratedValue(strategy="AUTO")
1262
     * @ORM\SequenceGenerator(sequenceName="tablename_seq", allocationSize=100)
1263
     */
1264
    public $id;
1265
1266
    /**
1267
     * @ORM\Column(length=50, nullable=true, unique=true, options={"foo": "bar", "baz": {"key": "val"}, "fixed": false})
1268
     */
1269
    public $name;
1270
1271
    /**
1272
     * @ORM\Column(name="user_email", columnDefinition="CHAR(32) NOT NULL")
1273
     */
1274
    public $email;
1275
1276
    /**
1277
     * @ORM\OneToOne(targetEntity=Address::class, cascade={"remove"}, inversedBy="user")
1278
     * @ORM\JoinColumn(onDelete="CASCADE")
1279
     */
1280
    public $address;
1281
1282
    /**
1283
     * @ORM\OneToMany(targetEntity=Phonenumber::class, mappedBy="user", cascade={"persist"}, orphanRemoval=true)
1284
     * @ORM\OrderBy({"number"="ASC"})
1285
     */
1286
    public $phonenumbers;
1287
1288
    /**
1289
     * @ORM\ManyToMany(targetEntity=Group::class, cascade={"all"})
1290
     * @ORM\JoinTable(name="cms_user_groups",
1291
     *    joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=false, unique=false)},
1292
     *    inverseJoinColumns={@ORM\JoinColumn(name="group_id", referencedColumnName="id", columnDefinition="INT NULL")}
1293
     * )
1294
     */
1295
    public $groups;
1296
1297
    /**
1298
     * @ORM\Column(type="integer")
1299
     * @ORM\Version
1300
     */
1301
    public $version;
1302
1303
1304
    /**
1305
     * @ORM\PrePersist
1306
     */
1307
    public function doStuffOnPrePersist()
1308
    {
1309
    }
1310
1311
    /**
1312
     * @ORM\PrePersist
1313
     */
1314
    public function doOtherStuffOnPrePersistToo()
1315
    {
1316
    }
1317
1318
    /**
1319
     * @ORM\PostPersist
1320
     */
1321
    public function doStuffOnPostPersist()
1322
    {
1323
    }
1324
1325
    public static function loadMetadata(ClassMetadata $metadata)
1326
    {
1327
        $tableMetadata = new Mapping\TableMetadata();
1328
1329
        $tableMetadata->setName('cms_users');
1330
        $tableMetadata->addIndex(
1331
            [
1332
                'name'    => 'name_idx',
1333
                'columns' => ['name'],
1334
                'unique'  => false,
1335
                'options' => [],
1336
                'flags'   => [],
1337
            ]
1338
        );
1339
1340
        $tableMetadata->addIndex(
1341
            [
1342
                'name'    => null,
1343
                'columns' => ['user_email'],
1344
                'unique'  => false,
1345
                'options' => [],
1346
                'flags'   => [],
1347
            ]
1348
        );
1349
1350
        $tableMetadata->addUniqueConstraint(
1351
            [
1352
                'name'    => 'search_idx',
1353
                'columns' => ['name', 'user_email'],
1354
                'options' => [],
1355
                'flags'   => [],
1356
            ]
1357
        );
1358
        $tableMetadata->addOption('foo', 'bar');
1359
        $tableMetadata->addOption('baz', ['key' => 'val']);
1360
1361
        $metadata->setTable($tableMetadata);
1362
        $metadata->setInheritanceType(Mapping\InheritanceType::NONE);
0 ignored issues
show
Bug introduced by
Doctrine\ORM\Mapping\InheritanceType::NONE of type string is incompatible with the type integer expected by parameter $type of Doctrine\ORM\Mapping\Cla...a::setInheritanceType(). ( Ignorable by Annotation )

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

1362
        $metadata->setInheritanceType(/** @scrutinizer ignore-type */ Mapping\InheritanceType::NONE);
Loading history...
1363
        $metadata->setChangeTrackingPolicy(Mapping\ChangeTrackingPolicy::DEFERRED_IMPLICIT);
1364
1365
        $metadata->addLifecycleCallback('doStuffOnPrePersist', 'prePersist');
1366
        $metadata->addLifecycleCallback('doOtherStuffOnPrePersistToo', 'prePersist');
1367
        $metadata->addLifecycleCallback('doStuffOnPostPersist', 'postPersist');
1368
1369
        $metadata->setGeneratorDefinition(
0 ignored issues
show
Bug introduced by
The method setGeneratorDefinition() 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

1369
        $metadata->/** @scrutinizer ignore-call */ 
1370
                   setGeneratorDefinition(

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...
1370
            [
1371
                'sequenceName'   => 'tablename_seq',
1372
                'allocationSize' => 100,
1373
            ]
1374
        );
1375
1376
        $metadata->addNamedQuery(
0 ignored issues
show
Bug introduced by
The method addNamedQuery() does not exist on Doctrine\ORM\Mapping\ClassMetadata. Did you maybe mean addNamedNativeQuery()? ( Ignorable by Annotation )

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

1376
        $metadata->/** @scrutinizer ignore-call */ 
1377
                   addNamedQuery(

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...
1377
            [
1378
                'name' => 'all',
1379
                'query' => 'SELECT u FROM __CLASS__ u'
1380
            ]
1381
        );
1382
1383
        $fieldMetadata = new Mapping\FieldMetadata('id');
1384
        $fieldMetadata->setType(Type::getType('integer'));
1385
        $fieldMetadata->setPrimaryKey(true);
1386
        $fieldMetadata->setOptions(['foo' => 'bar', 'unsigned' => false]);
1387
1388
        $metadata->addProperty($fieldMetadata);
1389
1390
        $fieldMetadata = new Mapping\FieldMetadata('name');
1391
        $fieldMetadata->setType(Type::getType('string'));
1392
        $fieldMetadata->setLength(50);
1393
        $fieldMetadata->setNullable(true);
1394
        $fieldMetadata->setUnique(true);
1395
        $fieldMetadata->setOptions(
1396
            [
1397
                'foo' => 'bar',
1398
                'baz' => [
1399
                    'key' => 'val',
1400
                ],
1401
                'fixed' => false,
1402
            ]
1403
        );
1404
1405
        $metadata->addProperty($fieldMetadata);
1406
1407
        $fieldMetadata = new Mapping\FieldMetadata('email');
1408
1409
        $fieldMetadata->setType(Type::getType('string'));
1410
        $fieldMetadata->setColumnName('user_email');
1411
        $fieldMetadata->setColumnDefinition('CHAR(32) NOT NULL');
1412
1413
        $metadata->addProperty($fieldMetadata);
1414
1415
        $fieldMetadata = new Mapping\VersionFieldMetadata('version');
1416
1417
        $fieldMetadata->setType(Type::getType('integer'));
1418
1419
        $metadata->addProperty($fieldMetadata);
1420
        $metadata->setIdGeneratorType(Mapping\GeneratorType::AUTO);
0 ignored issues
show
Bug introduced by
The method setIdGeneratorType() 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

1420
        $metadata->/** @scrutinizer ignore-call */ 
1421
                   setIdGeneratorType(Mapping\GeneratorType::AUTO);

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...
1421
1422
        $joinColumns = [];
1423
1424
        $joinColumn = new Mapping\JoinColumnMetadata();
1425
1426
        $joinColumn->setColumnName('address_id');
1427
        $joinColumn->setReferencedColumnName('id');
1428
        $joinColumn->setOnDelete('CASCADE');
1429
1430
        $joinColumns[] = $joinColumn;
1431
1432
        $association = new Mapping\OneToOneAssociationMetadata('address');
1433
1434
        $association->setJoinColumns($joinColumns);
1435
        $association->setTargetEntity(Address::class);
1436
        $association->setInversedBy('user');
1437
        $association->setCascade(['remove']);
1438
        $association->setOrphanRemoval(false);
1439
1440
        $metadata->addProperty($association);
1441
1442
        $association = new Mapping\OneToManyAssociationMetadata('phonenumbers');
1443
1444
        $association->setTargetEntity(Phonenumber::class);
1445
        $association->setMappedBy('user');
1446
        $association->setCascade(['persist']);
1447
        $association->setOrderBy(['number' => 'ASC']);
1448
        $association->setOrphanRemoval(true);
1449
1450
        $metadata->addProperty($association);
1451
1452
        $joinTable = new Mapping\JoinTableMetadata();
1453
        $joinTable->setName('cms_users_groups');
1454
1455
        $joinColumn = new Mapping\JoinColumnMetadata();
1456
1457
        $joinColumn->setColumnName('user_id');
1458
        $joinColumn->setReferencedColumnName('id');
1459
        $joinColumn->setNullable(false);
1460
        $joinColumn->setUnique(false);
1461
1462
        $joinTable->addJoinColumn($joinColumn);
1463
1464
        $joinColumn = new Mapping\JoinColumnMetadata();
1465
1466
        $joinColumn->setColumnName('group_id');
1467
        $joinColumn->setReferencedColumnName('id');
1468
        $joinColumn->setColumnDefinition('INT NULL');
1469
1470
        $joinTable->addInverseJoinColumn($joinColumn);
1471
1472
        $association = new Mapping\ManyToManyAssociationMetadata('groups');
1473
1474
        $association->setJoinTable($joinTable);
1475
        $association->setTargetEntity(Group::class);
1476
        $association->setCascade(['remove', 'persist', 'refresh']);
1477
1478
        $metadata->addProperty($association);
1479
    }
1480
}
1481
1482
/**
1483
 * @ORM\Entity
1484
 * @ORM\InheritanceType("SINGLE_TABLE")
1485
 * @ORM\DiscriminatorMap({"cat" = Cat::class, "dog" = Dog::class})
1486
 * @ORM\DiscriminatorColumn(name="discr", length=32, type="string")
1487
 */
1488
abstract class Animal
1489
{
1490
    /**
1491
     * @ORM\Id @ORM\Column(type="string") @ORM\GeneratedValue(strategy="CUSTOM")
1492
     * @ORM\CustomIdGenerator(class=stdClass::class)
1493
     */
1494
    public $id;
1495
}
1496
1497
/** @ORM\Entity */
1498
class Cat extends Animal
1499
{
1500
}
1501
1502
/** @ORM\Entity */
1503
class Dog extends Animal
1504
{
1505
}
1506
1507
/**
1508
 * @ORM\Entity
1509
 */
1510
class DDC1170Entity
1511
{
1512
    /**
1513
     * @param string $value
1514
     */
1515
    public function __construct($value = null)
1516
    {
1517
        $this->value = $value;
1518
    }
1519
1520
    /**
1521
     * @ORM\Id
1522
     * @ORM\GeneratedValue(strategy="NONE")
1523
     * @ORM\Column(type="integer", columnDefinition = "INT unsigned NOT NULL")
1524
     */
1525
    private $id;
1526
1527
    /**
1528
     * @ORM\Column(columnDefinition = "VARCHAR(255) NOT NULL")
1529
     */
1530
    private $value;
1531
1532
    /**
1533
     * @return int
1534
     */
1535
    public function getId()
1536
    {
1537
        return $this->id;
1538
    }
1539
1540
    /**
1541
     * @return string
1542
     */
1543
    public function getValue()
1544
    {
1545
        return $this->value;
1546
    }
1547
}
1548
1549
/**
1550
 * @ORM\Entity
1551
 * @ORM\InheritanceType("SINGLE_TABLE")
1552
 * @ORM\DiscriminatorMap({"ONE" = DDC807SubClasse1::class, "TWO" = DDC807SubClasse2::class})
1553
 * @ORM\DiscriminatorColumn(name = "dtype", columnDefinition="ENUM('ONE','TWO')")
1554
 */
1555
class DDC807Entity
1556
{
1557
    /**
1558
     * @ORM\Id
1559
     * @ORM\Column(type="integer")
1560
     * @ORM\GeneratedValue(strategy="NONE")
1561
     */
1562
    public $id;
1563
}
1564
1565
class DDC807SubClasse1 {}
1566
class DDC807SubClasse2 {}
1567
1568
class Address {}
1569
class Phonenumber {}
1570
class Group {}
1571
1572
/**
1573
 * @ORM\Entity
1574
 * @ORM\Table(indexes={@ORM\Index(columns={"content"}, flags={"fulltext"}, options={"where": "content IS NOT NULL"})})
1575
 */
1576
class Comment
1577
{
1578
    /**
1579
     * @ORM\Column(type="text")
1580
     */
1581
    private $content;
0 ignored issues
show
introduced by
The private property $content is not used, and could be removed.
Loading history...
1582
}
1583
1584
/**
1585
 * @ORM\Entity
1586
 * @ORM\InheritanceType("SINGLE_TABLE")
1587
 * @ORM\DiscriminatorMap({
1588
 *     "ONE" = Doctrine\Tests\ORM\Mapping\SingleTableEntityNoDiscriminatorColumnMappingSub1::class,
1589
 *     "TWO" = Doctrine\Tests\ORM\Mapping\SingleTableEntityNoDiscriminatorColumnMappingSub2::class
1590
 * })
1591
 */
1592
class SingleTableEntityNoDiscriminatorColumnMapping
1593
{
1594
    /**
1595
     * @ORM\Id
1596
     * @ORM\Column(type="integer")
1597
     * @ORM\GeneratedValue(strategy="NONE")
1598
     */
1599
    public $id;
1600
}
1601
1602
/**
1603
 * @ORM\Entity
1604
 */
1605
class SingleTableEntityNoDiscriminatorColumnMappingSub1 extends SingleTableEntityNoDiscriminatorColumnMapping {}
1606
1607
/**
1608
 * @ORM\Entity
1609
 */
1610
class SingleTableEntityNoDiscriminatorColumnMappingSub2 extends SingleTableEntityNoDiscriminatorColumnMapping {}
1611
1612
/**
1613
 * @ORM\Entity
1614
 * @ORM\InheritanceType("SINGLE_TABLE")
1615
 * @ORM\DiscriminatorMap({
1616
 *     "ONE" = Doctrine\Tests\ORM\Mapping\SingleTableEntityIncompleteDiscriminatorColumnMappingSub1::class,
1617
 *     "TWO" = Doctrine\Tests\ORM\Mapping\SingleTableEntityIncompleteDiscriminatorColumnMappingSub2::class
1618
 * })
1619
 * @ORM\DiscriminatorColumn(name="dtype")
1620
 */
1621
class SingleTableEntityIncompleteDiscriminatorColumnMapping
1622
{
1623
    /**
1624
     * @ORM\Id
1625
     * @ORM\Column(type="integer")
1626
     * @ORM\GeneratedValue(strategy="NONE")
1627
     */
1628
    public $id;
1629
}
1630
1631
class SingleTableEntityIncompleteDiscriminatorColumnMappingSub1
1632
    extends SingleTableEntityIncompleteDiscriminatorColumnMapping {}
0 ignored issues
show
Coding Style introduced by
The extends keyword must be on the same line as the class name
Loading history...
1633
1634
class SingleTableEntityIncompleteDiscriminatorColumnMappingSub2
1635
    extends SingleTableEntityIncompleteDiscriminatorColumnMapping {}
0 ignored issues
show
Coding Style introduced by
The extends keyword must be on the same line as the class name
Loading history...
1636