Failed Conditions
Push — master ( 695edb...6e4daa )
by Marco
17:25 queued 06:57
created

testManyToOneBidirectional()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 14
rs 9.4285
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\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 testOneToOneUnidirectional() : 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
373
    public function testOneToOneBidirectional() : void
374
    {
375
        // One to One owning / One To One inverse
376
        $addressClass    = $this->createClassMetadata(Quote\Address::class);
377
        $userAssociation = $addressClass->getProperty('user');
378
379
        self::assertInstanceOf(Mapping\OneToOneAssociationMetadata::class, $userAssociation);
380
        self::assertTrue($userAssociation->isOwningSide());
381
382
        $userClass          = $this->createClassMetadata(Quote\User::class);
383
        $addressAssociation = $userClass->getProperty('address');
384
385
        self::assertInstanceOf(Mapping\OneToOneAssociationMetadata::class, $addressAssociation);
386
        self::assertFalse($addressAssociation->isOwningSide());
387
    }
388
389
    public function testManyToOneUnidirectional() : void
390
    {
391
        // Many to One owning
392
        $groupClass       = $this->createClassMetadata(Quote\Group::class);
393
        $groupAssociation = $groupClass->getProperty('parent');
394
395
        self::assertInstanceOf(Mapping\ManyToOneAssociationMetadata::class, $groupAssociation);
396
        self::assertTrue($groupAssociation->isOwningSide());
397
    }
398
399
    public function testManyToOneBidirectional() : void
400
    {
401
        // Many To One owning / One To Many inverse
402
        $phoneClass      = $this->createClassMetadata(Quote\Phone::class);
403
        $userAssociation = $phoneClass->getProperty('user');
404
405
        self::assertInstanceOf(Mapping\ManyToOneAssociationMetadata::class, $userAssociation);
406
        self::assertTrue($userAssociation->isOwningSide());
407
408
        $userClass        = $this->createClassMetadata(Quote\User::class);
409
        $phoneAssociation = $userClass->getProperty('phones');
410
411
        self::assertInstanceOf(Mapping\OneToManyAssociationMetadata::class, $phoneAssociation);
412
        self::assertFalse($phoneAssociation->isOwningSide());
413
    }
414
415
    public function testManyToManyBidirectional() : void
416
    {
417
        // Many to Many owning / Many to Many inverse
418
        $userClass        = $this->createClassMetadata(Quote\User::class);
419
        $groupAssociation = $userClass->getProperty('groups');
420
421
        self::assertInstanceOf(Mapping\ManyToManyAssociationMetadata::class, $groupAssociation);
422
        self::assertTrue($groupAssociation->isOwningSide());
423
424
        $groupClass      = $this->createClassMetadata(Quote\Group::class);
425
        $userAssociation = $groupClass->getProperty('users');
426
427
        self::assertInstanceOf(Mapping\ManyToManyAssociationMetadata::class, $userAssociation);
428
        self::assertFalse($userAssociation->isOwningSide());
429
    }
430
431
    /**
432
     * @depends testProperties
433
     * @param ClassMetadata $class
434
     */
435
    public function testOwningOneToOneAssociation($class)
436
    {
437
        self::assertArrayHasKey('address', iterator_to_array($class->getDeclaredPropertiesIterator()));
438
439
        $association = $class->getProperty('address');
440
441
        self::assertTrue($association->isOwningSide());
442
        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

442
        self::assertEquals('user', $association->/** @scrutinizer ignore-call */ getInversedBy());
Loading history...
443
        // Check cascading
444
        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

444
        self::assertEquals(['remove'], $association->/** @scrutinizer ignore-call */ getCascade());
Loading history...
445
446
        return $class;
447
    }
448
449
    /**
450
     * @depends testOwningOneToOneAssociation
451
     * @param ClassMetadata $class
452
     */
453
    public function testInverseOneToManyAssociation($class)
454
    {
455
        self::assertArrayHasKey('phonenumbers', iterator_to_array($class->getDeclaredPropertiesIterator()));
456
457
        $association = $class->getProperty('phonenumbers');
458
459
        self::assertFalse($association->isOwningSide());
460
        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

460
        self::assertTrue($association->/** @scrutinizer ignore-call */ isOrphanRemoval());
Loading history...
461
462
        // Check cascading
463
        self::assertEquals(['persist', 'remove'], $association->getCascade());
464
465
        // Test Order By
466
        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

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

525
        /** @scrutinizer ignore-call */ 
526
        $joinTable   = $association->getJoinTable();
Loading history...
526
        $joinColumns = $joinTable->getJoinColumns();
527
        $joinColumn  = reset($joinColumns);
528
529
        self::assertFalse($joinColumn->isNullable());
530
        self::assertFalse($joinColumn->isUnique());
531
532
        return $class;
533
    }
534
535
    /**
536
     * @depends testJoinColumnUniqueAndNullable
537
     * @param ClassMetadata $class
538
     */
539
    public function testColumnDefinition($class)
540
    {
541
        self::assertNotNull($class->getProperty('email'));
542
543
        $property           = $class->getProperty('email');
544
        $association        = $class->getProperty('groups');
545
        $joinTable          = $association->getJoinTable();
546
        $inverseJoinColumns = $joinTable->getInverseJoinColumns();
547
        $inverseJoinColumn  = reset($inverseJoinColumns);
548
549
        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

549
        self::assertEquals("CHAR(32) NOT NULL", $property->/** @scrutinizer ignore-call */ getColumnDefinition());
Loading history...
550
        self::assertEquals("INT NULL", $inverseJoinColumn->getColumnDefinition());
551
552
        return $class;
553
    }
554
555
    /**
556
     * @depends testColumnDefinition
557
     * @param ClassMetadata $class
558
     */
559
    public function testJoinColumnOnDelete($class)
560
    {
561
        $association = $class->getProperty('address');
562
        $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

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

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

877
        self::assertEquals($guestGroups->/** @scrutinizer ignore-call */ getMappedBy(), $adminGroups->getMappedBy());
Loading history...
878
        self::assertEquals($guestGroups->getInversedBy(), $adminGroups->getInversedBy());
879
        self::assertEquals($guestGroups->isOwningSide(), $adminGroups->isOwningSide());
880
        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

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

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

1374
        $metadata->setInheritanceType(/** @scrutinizer ignore-type */ Mapping\InheritanceType::NONE);
Loading history...
1375
        $metadata->setChangeTrackingPolicy(Mapping\ChangeTrackingPolicy::DEFERRED_IMPLICIT);
1376
1377
        $metadata->addLifecycleCallback('doStuffOnPrePersist', 'prePersist');
1378
        $metadata->addLifecycleCallback('doOtherStuffOnPrePersistToo', 'prePersist');
1379
        $metadata->addLifecycleCallback('doStuffOnPostPersist', 'postPersist');
1380
1381
        $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

1381
        $metadata->/** @scrutinizer ignore-call */ 
1382
                   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...
1382
            [
1383
                'sequenceName'   => 'tablename_seq',
1384
                'allocationSize' => 100,
1385
            ]
1386
        );
1387
1388
        $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

1388
        $metadata->/** @scrutinizer ignore-call */ 
1389
                   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...
1389
            [
1390
                'name' => 'all',
1391
                'query' => 'SELECT u FROM __CLASS__ u'
1392
            ]
1393
        );
1394
1395
        $fieldMetadata = new Mapping\FieldMetadata('id');
1396
        $fieldMetadata->setType(Type::getType('integer'));
1397
        $fieldMetadata->setPrimaryKey(true);
1398
        $fieldMetadata->setOptions(['foo' => 'bar', 'unsigned' => false]);
1399
1400
        $metadata->addProperty($fieldMetadata);
1401
1402
        $fieldMetadata = new Mapping\FieldMetadata('name');
1403
        $fieldMetadata->setType(Type::getType('string'));
1404
        $fieldMetadata->setLength(50);
1405
        $fieldMetadata->setNullable(true);
1406
        $fieldMetadata->setUnique(true);
1407
        $fieldMetadata->setOptions(
1408
            [
1409
                'foo' => 'bar',
1410
                'baz' => [
1411
                    'key' => 'val',
1412
                ],
1413
                'fixed' => false,
1414
            ]
1415
        );
1416
1417
        $metadata->addProperty($fieldMetadata);
1418
1419
        $fieldMetadata = new Mapping\FieldMetadata('email');
1420
1421
        $fieldMetadata->setType(Type::getType('string'));
1422
        $fieldMetadata->setColumnName('user_email');
1423
        $fieldMetadata->setColumnDefinition('CHAR(32) NOT NULL');
1424
1425
        $metadata->addProperty($fieldMetadata);
1426
1427
        $fieldMetadata = new Mapping\VersionFieldMetadata('version');
1428
1429
        $fieldMetadata->setType(Type::getType('integer'));
1430
1431
        $metadata->addProperty($fieldMetadata);
1432
        $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

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