Failed Conditions
Push — master ( ee4e26...e98654 )
by Marco
13:06
created

AbstractMappingDriverTest::testNamedQuery()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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

195
            $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...
196
            'No Sequence Definition set on this driver.'
197
        );
198
        self::assertEquals(
199
            [
200
                'sequenceName'   => 'tablename_seq',
201
                'allocationSize' => 100,
202
            ],
203
            $class->getProperty('id')->getValueGenerator()->getDefinition()
204
        );
205
    }
206
207
    public function testEntityCustomGenerator()
208
    {
209
        $class = $this->createClassMetadata(Animal::class);
210
211
        self::assertEquals(Mapping\GeneratorType::CUSTOM, $class->getProperty('id')->getValueGenerator()->getType(), "Generator Type");
212
        self::assertEquals(
213
            [
214
                'class'     => 'stdClass',
215
                'arguments' => [],
216
            ],
217
            $class->getProperty('id')->getValueGenerator()->getDefinition(),
218
            "Generator Definition"
219
        );
220
    }
221
222
223
    /**
224
     * @depends testEntityTableNameAndInheritance
225
     * @param ClassMetadata $class
226
     */
227
    public function testProperties($class)
228
    {
229
        self::assertCount(7, $class->getDeclaredPropertiesIterator());
230
231
        self::assertNotNull($class->getProperty('id'));
232
        self::assertNotNull($class->getProperty('name'));
233
        self::assertNotNull($class->getProperty('email'));
234
        self::assertNotNull($class->getProperty('version'));
235
        self::assertNotNull($class->getProperty('version'));
236
237
        return $class;
238
    }
239
240
    /**
241
     * @depends testProperties
242
     * @param ClassMetadata $class
243
     */
244
    public function testVersionProperty($class)
245
    {
246
        self::assertTrue($class->isVersioned());
247
        self::assertNotNull($class->versionProperty);
248
249
        $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

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

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

282
        self::assertEquals('string', $property->/** @scrutinizer ignore-call */ getTypeName());
Loading history...
283
        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

283
        self::assertEquals(50, $property->/** @scrutinizer ignore-call */ getLength());
Loading history...
284
        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

284
        self::assertTrue($property->/** @scrutinizer ignore-call */ isNullable());
Loading history...
285
        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

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

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

372
        self::assertTrue($association->/** @scrutinizer ignore-call */ isOwningSide());
Loading history...
373
        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

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

375
        self::assertEquals(['remove'], $association->/** @scrutinizer ignore-call */ getCascade());
Loading history...
376
377
        return $class;
378
    }
379
380
    /**
381
     * @depends testOwningOneToOneAssociation
382
     * @param ClassMetadata $class
383
     */
384
    public function testInverseOneToManyAssociation($class)
385
    {
386
        self::assertArrayHasKey('phonenumbers', iterator_to_array($class->getDeclaredPropertiesIterator()));
387
388
        $association = $class->getProperty('phonenumbers');
389
390
        self::assertFalse($association->isOwningSide());
391
        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

391
        self::assertTrue($association->/** @scrutinizer ignore-call */ isOrphanRemoval());
Loading history...
392
393
        // Check cascading
394
        self::assertEquals(['persist', 'remove'], $association->getCascade());
395
396
        // Test Order By
397
        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

397
        self::assertEquals(['number' => 'ASC'], $association->/** @scrutinizer ignore-call */ getOrderBy());
Loading history...
398
399
        return $class;
400
    }
401
402
    /**
403
     * @depends testInverseOneToManyAssociation
404
     * @param ClassMetadata $class
405
     */
406
    public function testManyToManyAssociationWithCascadeAll($class)
407
    {
408
        self::assertArrayHasKey('groups', iterator_to_array($class->getDeclaredPropertiesIterator()));
409
410
        $association = $class->getProperty('groups');
411
412
        self::assertTrue($association->isOwningSide());
413
414
        // Make sure that cascade-all works as expected
415
        self::assertEquals(['remove', 'persist', 'refresh'], $association->getCascade());
416
417
        // Test Order By
418
        self::assertEquals([], $association->getOrderBy());
419
420
        return $class;
421
    }
422
423
    /**
424
     * @depends testManyToManyAssociationWithCascadeAll
425
     * @param ClassMetadata $class
426
     */
427
    public function testLifecycleCallbacks($class)
428
    {
429
        self::assertCount(2, $class->lifecycleCallbacks);
430
        self::assertEquals($class->lifecycleCallbacks['prePersist'][0], 'doStuffOnPrePersist');
431
        self::assertEquals($class->lifecycleCallbacks['postPersist'][0], 'doStuffOnPostPersist');
432
433
        return $class;
434
    }
435
436
    /**
437
     * @depends testManyToManyAssociationWithCascadeAll
438
     * @param ClassMetadata $class
439
     */
440
    public function testLifecycleCallbacksSupportMultipleMethodNames($class)
441
    {
442
        self::assertCount(2, $class->lifecycleCallbacks['prePersist']);
443
        self::assertEquals($class->lifecycleCallbacks['prePersist'][1], 'doOtherStuffOnPrePersistToo');
444
445
        return $class;
446
    }
447
448
    /**
449
     * @depends testLifecycleCallbacksSupportMultipleMethodNames
450
     * @param ClassMetadata $class
451
     */
452
    public function testJoinColumnUniqueAndNullable($class)
453
    {
454
        // Non-Nullability of Join Column
455
        $association = $class->getProperty('groups');
456
        $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

456
        /** @scrutinizer ignore-call */ 
457
        $joinTable   = $association->getJoinTable();
Loading history...
457
        $joinColumns = $joinTable->getJoinColumns();
458
        $joinColumn  = reset($joinColumns);
459
460
        self::assertFalse($joinColumn->isNullable());
461
        self::assertFalse($joinColumn->isUnique());
462
463
        return $class;
464
    }
465
466
    /**
467
     * @depends testJoinColumnUniqueAndNullable
468
     * @param ClassMetadata $class
469
     */
470
    public function testColumnDefinition($class)
471
    {
472
        self::assertNotNull($class->getProperty('email'));
473
474
        $property           = $class->getProperty('email');
475
        $association        = $class->getProperty('groups');
476
        $joinTable          = $association->getJoinTable();
477
        $inverseJoinColumns = $joinTable->getInverseJoinColumns();
478
        $inverseJoinColumn  = reset($inverseJoinColumns);
479
480
        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

480
        self::assertEquals("CHAR(32) NOT NULL", $property->/** @scrutinizer ignore-call */ getColumnDefinition());
Loading history...
481
        self::assertEquals("INT NULL", $inverseJoinColumn->getColumnDefinition());
482
483
        return $class;
484
    }
485
486
    /**
487
     * @depends testColumnDefinition
488
     * @param ClassMetadata $class
489
     */
490
    public function testJoinColumnOnDelete($class)
491
    {
492
        $association = $class->getProperty('address');
493
        $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

493
        /** @scrutinizer ignore-call */ 
494
        $joinColumns = $association->getJoinColumns();
Loading history...
494
        $joinColumn  = reset($joinColumns);
495
496
        self::assertEquals('CASCADE', $joinColumn->getOnDelete());
497
498
        return $class;
499
    }
500
501
    /**
502
     * @group DDC-514
503
     */
504
    public function testDiscriminatorColumnDefaults()
505
    {
506
        if (strpos(get_class($this), 'PHPMappingDriver') !== false) {
507
            $this->markTestSkipped('PHP Mapping Drivers have no defaults.');
508
        }
509
510
        $class = $this->createClassMetadata(Animal::class);
511
512
        self::assertNotNull($class->discriminatorColumn);
513
514
        $discrColumn = $class->discriminatorColumn;
515
516
        self::assertEquals('Animal', $discrColumn->getTableName());
517
        self::assertEquals('discr', $discrColumn->getColumnName());
518
        self::assertEquals('string', $discrColumn->getTypeName());
519
        self::assertEquals(32, $discrColumn->getLength());
520
        self::assertNull($discrColumn->getColumnDefinition());
521
    }
522
523
    /**
524
     * @group DDC-869
525
     */
526
    public function testMappedSuperclassWithRepository()
527
    {
528
        $em      = $this->getTestEntityManager();
529
        $factory = $this->createClassMetadataFactory($em);
530
        $class   = $factory->getMetadataFor(DDC869CreditCardPayment::class);
531
532
        self::assertNotNull($class->getProperty('id'));
533
        self::assertNotNull($class->getProperty('value'));
534
        self::assertNotNull($class->getProperty('creditCardNumber'));
535
        self::assertEquals($class->getCustomRepositoryClassName(), DDC869PaymentRepository::class);
536
        self::assertInstanceOf(DDC869PaymentRepository::class, $em->getRepository(DDC869CreditCardPayment::class));
537
        self::assertTrue($em->getRepository(DDC869ChequePayment::class)->isTrue());
538
539
        $class = $factory->getMetadataFor(DDC869ChequePayment::class);
540
541
        self::assertNotNull($class->getProperty('id'));
542
        self::assertNotNull($class->getProperty('value'));
543
        self::assertNotNull($class->getProperty('serialNumber'));
544
        self::assertEquals($class->getCustomRepositoryClassName(), DDC869PaymentRepository::class);
545
        self::assertInstanceOf(DDC869PaymentRepository::class, $em->getRepository(DDC869ChequePayment::class));
546
        self::assertTrue($em->getRepository(DDC869ChequePayment::class)->isTrue());
547
    }
548
549
    /**
550
     * @group DDC-1476
551
     */
552
    public function testDefaultFieldType()
553
    {
554
        $factory = $this->createClassMetadataFactory();
555
        $class   = $factory->getMetadataFor(DDC1476EntityWithDefaultFieldType::class);
556
557
        self::assertNotNull($class->getProperty('id'));
558
        self::assertNotNull($class->getProperty('name'));
559
560
        $idProperty = $class->getProperty('id');
561
        $nameProperty = $class->getProperty('name');
562
563
        self::assertInstanceOf(Mapping\FieldMetadata::class, $idProperty);
564
        self::assertInstanceOf(Mapping\FieldMetadata::class, $nameProperty);
565
566
        self::assertEquals('string', $idProperty->getTypeName());
567
        self::assertEquals('string', $nameProperty->getTypeName());
568
569
        self::assertEquals('id', $idProperty->getName());
570
        self::assertEquals('name', $nameProperty->getName());
571
572
        self::assertEquals('id', $idProperty->getColumnName());
573
        self::assertEquals('name', $nameProperty->getColumnName());
574
575
        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

575
        self::assertFalse($idProperty->/** @scrutinizer ignore-call */ hasValueGenerator());
Loading history...
576
    }
577
578
    /**
579
     * @group DDC-1170
580
     */
581
    public function testIdentifierColumnDefinition()
582
    {
583
        $class = $this->createClassMetadata(DDC1170Entity::class);
584
585
        self::assertNotNull($class->getProperty('id'));
586
        self::assertNotNull($class->getProperty('value'));
587
588
        self::assertEquals("INT unsigned NOT NULL", $class->getProperty('id')->getColumnDefinition());
589
        self::assertEquals("VARCHAR(255) NOT NULL", $class->getProperty('value')->getColumnDefinition());
590
    }
591
592
    /**
593
     * @group DDC-559
594
     */
595
    public function testNamingStrategy()
596
    {
597
        $em      = $this->getTestEntityManager();
598
        $factory = $this->createClassMetadataFactory($em);
599
600
        self::assertInstanceOf(DefaultNamingStrategy::class, $em->getConfiguration()->getNamingStrategy());
601
        $em->getConfiguration()->setNamingStrategy(new UnderscoreNamingStrategy(CASE_UPPER));
602
        self::assertInstanceOf(UnderscoreNamingStrategy::class, $em->getConfiguration()->getNamingStrategy());
603
604
        $class        = $factory->getMetadataFor(DDC1476EntityWithDefaultFieldType::class);
605
        $idProperty   = $class->getProperty('id');
606
        $nameProperty = $class->getProperty('name');
607
608
        self::assertEquals('ID', $idProperty->getColumnName());
609
        self::assertEquals('NAME', $nameProperty->getColumnName());
610
        self::assertEquals('DDC1476ENTITY_WITH_DEFAULT_FIELD_TYPE', $class->table->getName());
611
    }
612
613
    /**
614
     * @group DDC-807
615
     * @group DDC-553
616
     */
617
    public function testDiscriminatorColumnDefinition()
618
    {
619
        $class = $this->createClassMetadata(DDC807Entity::class);
620
621
        self::assertNotNull($class->discriminatorColumn);
622
623
        $discrColumn = $class->discriminatorColumn;
624
625
        self::assertEquals('dtype', $discrColumn->getColumnName());
626
        self::assertEquals("ENUM('ONE','TWO')", $discrColumn->getColumnDefinition());
627
    }
628
629
    /**
630
     * @group DDC-889
631
     */
632
    public function testInvalidEntityOrMappedSuperClassShouldMentionParentClasses()
633
    {
634
        $this->expectException(MappingException::class);
635
        $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.');
636
637
        $this->createClassMetadata(DDC889Class::class);
638
    }
639
640
    /**
641
     * @group DDC-889
642
     */
643
    public function testIdentifierRequiredShouldMentionParentClasses()
644
    {
645
        $factory = $this->createClassMetadataFactory();
646
647
        $this->expectException(MappingException::class);
648
        $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.');
649
650
        $factory->getMetadataFor(DDC889Entity::class);
651
    }
652
653
    /**
654
     * @group DDC-1663
655
     */
656
    public function testNamedNativeQuery()
657
    {
658
        $class = $this->createClassMetadata(CmsAddress::class);
659
660
        // named native query
661
        self::assertCount(3, $class->namedNativeQueries);
662
        self::assertArrayHasKey('find-all', $class->namedNativeQueries);
663
        self::assertArrayHasKey('find-by-id', $class->namedNativeQueries);
664
665
        $findAllQuery = $class->getNamedNativeQuery('find-all');
666
667
        self::assertEquals('mapping-find-all', $findAllQuery['resultSetMapping']);
668
        self::assertEquals('SELECT id, country, city FROM cms_addresses', $findAllQuery['query']);
669
670
        $findByIdQuery = $class->getNamedNativeQuery('find-by-id');
671
672
        self::assertEquals(CmsAddress::class, $findByIdQuery['resultClass']);
673
        self::assertEquals('SELECT * FROM cms_addresses WHERE id = ?',  $findByIdQuery['query']);
674
675
        $countQuery = $class->getNamedNativeQuery('count');
676
677
        self::assertEquals('mapping-count', $countQuery['resultSetMapping']);
678
        self::assertEquals('SELECT COUNT(*) AS count FROM cms_addresses',  $countQuery['query']);
679
680
        // result set mapping
681
        self::assertCount(3, $class->sqlResultSetMappings);
682
        self::assertArrayHasKey('mapping-count', $class->sqlResultSetMappings);
683
        self::assertArrayHasKey('mapping-find-all', $class->sqlResultSetMappings);
684
        self::assertArrayHasKey('mapping-without-fields', $class->sqlResultSetMappings);
685
686
        $findAllMapping = $class->getSqlResultSetMapping('mapping-find-all');
687
688
        self::assertEquals(CmsAddress::class, $findAllMapping['entities'][0]['entityClass']);
689
        self::assertEquals(['name'=>'id','column'=>'id'], $findAllMapping['entities'][0]['fields'][0]);
690
        self::assertEquals(['name'=>'city','column'=>'city'], $findAllMapping['entities'][0]['fields'][1]);
691
        self::assertEquals(['name'=>'country','column'=>'country'], $findAllMapping['entities'][0]['fields'][2]);
692
693
        $withoutFieldsMapping = $class->getSqlResultSetMapping('mapping-without-fields');
694
695
        self::assertEquals('__CLASS__', $withoutFieldsMapping['entities'][0]['entityClass']);
696
        self::assertEquals([], $withoutFieldsMapping['entities'][0]['fields']);
697
698
        $countMapping = $class->getSqlResultSetMapping('mapping-count');
699
700
        self::assertEquals(['name'=>'count'], $countMapping['columns'][0]);
701
    }
702
703
    /**
704
     * @group DDC-1663
705
     */
706
    public function testSqlResultSetMapping()
707
    {
708
        $userMetadata   = $this->createClassMetadata(CmsUser::class);
709
        $personMetadata = $this->createClassMetadata(CompanyPerson::class);
710
711
        // user asserts
712
        self::assertCount(4, $userMetadata->getSqlResultSetMappings());
713
714
        $mapping = $userMetadata->getSqlResultSetMapping('mappingJoinedAddress');
715
716
        self::assertEquals([], $mapping['columns']);
717
        self::assertEquals('mappingJoinedAddress', $mapping['name']);
718
719
        self::assertNull($mapping['entities'][0]['discriminatorColumn']);
720
721
        self::assertEquals(['name'=>'id','column'=>'id'],                   $mapping['entities'][0]['fields'][0]);
722
        self::assertEquals(['name'=>'name','column'=>'name'],               $mapping['entities'][0]['fields'][1]);
723
        self::assertEquals(['name'=>'status','column'=>'status'],           $mapping['entities'][0]['fields'][2]);
724
        self::assertEquals(['name'=>'address.zip','column'=>'zip'],         $mapping['entities'][0]['fields'][3]);
725
        self::assertEquals(['name'=>'address.city','column'=>'city'],       $mapping['entities'][0]['fields'][4]);
726
        self::assertEquals(['name'=>'address.country','column'=>'country'], $mapping['entities'][0]['fields'][5]);
727
        self::assertEquals(['name'=>'address.id','column'=>'a_id'],         $mapping['entities'][0]['fields'][6]);
728
        self::assertEquals('__CLASS__',                            $mapping['entities'][0]['entityClass']);
729
730
        $mapping = $userMetadata->getSqlResultSetMapping('mappingJoinedPhonenumber');
731
732
        self::assertEquals([], $mapping['columns']);
733
        self::assertEquals('mappingJoinedPhonenumber', $mapping['name']);
734
735
        self::assertNull($mapping['entities'][0]['discriminatorColumn']);
736
737
        self::assertEquals(['name'=>'id','column'=>'id'],                             $mapping['entities'][0]['fields'][0]);
738
        self::assertEquals(['name'=>'name','column'=>'name'],                         $mapping['entities'][0]['fields'][1]);
739
        self::assertEquals(['name'=>'status','column'=>'status'],                     $mapping['entities'][0]['fields'][2]);
740
        self::assertEquals(['name'=>'phonenumbers.phonenumber','column'=>'number'],   $mapping['entities'][0]['fields'][3]);
741
        self::assertEquals($userMetadata->getClassName(),                             $mapping['entities'][0]['entityClass']);
742
743
        $mapping = $userMetadata->getSqlResultSetMapping('mappingUserPhonenumberCount');
744
745
        self::assertEquals(['name'=>'numphones'], $mapping['columns'][0]);
746
        self::assertEquals('mappingUserPhonenumberCount', $mapping['name']);
747
748
        self::assertNull($mapping['entities'][0]['discriminatorColumn']);
749
750
        self::assertEquals(['name'=>'id','column'=>'id'],         $mapping['entities'][0]['fields'][0]);
751
        self::assertEquals(['name'=>'name','column'=>'name'],     $mapping['entities'][0]['fields'][1]);
752
        self::assertEquals(['name'=>'status','column'=>'status'], $mapping['entities'][0]['fields'][2]);
753
        self::assertEquals($userMetadata->getClassName(),         $mapping['entities'][0]['entityClass']);
754
755
        $mapping = $userMetadata->getSqlResultSetMapping('mappingMultipleJoinsEntityResults');
756
757
        self::assertEquals(['name'=>'numphones'], $mapping['columns'][0]);
758
        self::assertEquals('mappingMultipleJoinsEntityResults', $mapping['name']);
759
760
        self::assertNull($mapping['entities'][0]['discriminatorColumn']);
761
762
        self::assertEquals(['name'=>'id','column'=>'u_id'],           $mapping['entities'][0]['fields'][0]);
763
        self::assertEquals(['name'=>'name','column'=>'u_name'],       $mapping['entities'][0]['fields'][1]);
764
        self::assertEquals(['name'=>'status','column'=>'u_status'],   $mapping['entities'][0]['fields'][2]);
765
        self::assertEquals('__CLASS__',                      $mapping['entities'][0]['entityClass']);
766
767
        self::assertNull($mapping['entities'][1]['discriminatorColumn']);
768
769
        self::assertEquals(['name'=>'id','column'=>'a_id'],           $mapping['entities'][1]['fields'][0]);
770
        self::assertEquals(['name'=>'zip','column'=>'a_zip'],         $mapping['entities'][1]['fields'][1]);
771
        self::assertEquals(['name'=>'country','column'=>'a_country'], $mapping['entities'][1]['fields'][2]);
772
        self::assertEquals(CmsAddress::class,                $mapping['entities'][1]['entityClass']);
773
774
        //person asserts
775
        self::assertCount(1, $personMetadata->getSqlResultSetMappings());
776
777
        $mapping = $personMetadata->getSqlResultSetMapping('mappingFetchAll');
778
779
        self::assertEquals([], $mapping['columns']);
780
        self::assertEquals('mappingFetchAll', $mapping['name']);
781
782
        self::assertEquals('discriminator', $mapping['entities'][0]['discriminatorColumn']);
783
784
        self::assertEquals(['name'=>'id','column'=>'id'],     $mapping['entities'][0]['fields'][0]);
785
        self::assertEquals(['name'=>'name','column'=>'name'], $mapping['entities'][0]['fields'][1]);
786
        self::assertEquals('__CLASS__',              $mapping['entities'][0]['entityClass']);
787
    }
788
789
    /*
790
     * @group DDC-964
791
     */
792
    public function testAssociationOverridesMapping()
793
    {
794
        $factory        = $this->createClassMetadataFactory();
795
        $adminMetadata  = $factory->getMetadataFor(DDC964Admin::class);
796
        $guestMetadata  = $factory->getMetadataFor(DDC964Guest::class);
797
798
        // assert groups association mappings
799
        self::assertArrayHasKey('groups', iterator_to_array($guestMetadata->getDeclaredPropertiesIterator()));
800
        self::assertArrayHasKey('groups', iterator_to_array($adminMetadata->getDeclaredPropertiesIterator()));
801
802
        $guestGroups = $guestMetadata->getProperty('groups');
803
        $adminGroups = $adminMetadata->getProperty('groups');
804
805
        // assert not override attributes
806
        self::assertEquals($guestGroups->getName(), $adminGroups->getName());
807
        self::assertEquals(get_class($guestGroups), get_class($adminGroups));
808
        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

808
        self::assertEquals($guestGroups->/** @scrutinizer ignore-call */ getMappedBy(), $adminGroups->getMappedBy());
Loading history...
809
        self::assertEquals($guestGroups->getInversedBy(), $adminGroups->getInversedBy());
810
        self::assertEquals($guestGroups->isOwningSide(), $adminGroups->isOwningSide());
811
        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

811
        self::assertEquals($guestGroups->/** @scrutinizer ignore-call */ getFetchMode(), $adminGroups->getFetchMode());
Loading history...
812
        self::assertEquals($guestGroups->getCascade(), $adminGroups->getCascade());
813
814
        // assert not override attributes
815
        $guestGroupsJoinTable          = $guestGroups->getJoinTable();
816
        $guestGroupsJoinColumns        = $guestGroupsJoinTable->getJoinColumns();
817
        $guestGroupsJoinColumn         = reset($guestGroupsJoinColumns);
818
        $guestGroupsInverseJoinColumns = $guestGroupsJoinTable->getInverseJoinColumns();
819
        $guestGroupsInverseJoinColumn  = reset($guestGroupsInverseJoinColumns);
820
821
        self::assertEquals('ddc964_users_groups', $guestGroupsJoinTable->getName());
822
        self::assertEquals('user_id', $guestGroupsJoinColumn->getColumnName());
823
        self::assertEquals('group_id', $guestGroupsInverseJoinColumn->getColumnName());
824
825
        $adminGroupsJoinTable          = $adminGroups->getJoinTable();
826
        $adminGroupsJoinColumns        = $adminGroupsJoinTable->getJoinColumns();
827
        $adminGroupsJoinColumn         = reset($adminGroupsJoinColumns);
828
        $adminGroupsInverseJoinColumns = $adminGroupsJoinTable->getInverseJoinColumns();
829
        $adminGroupsInverseJoinColumn  = reset($adminGroupsInverseJoinColumns);
830
831
        self::assertEquals('ddc964_users_admingroups', $adminGroupsJoinTable->getName());
832
        self::assertEquals('adminuser_id', $adminGroupsJoinColumn->getColumnName());
833
        self::assertEquals('admingroup_id', $adminGroupsInverseJoinColumn->getColumnName());
834
835
        // assert address association mappings
836
        self::assertArrayHasKey('address', iterator_to_array($guestMetadata->getDeclaredPropertiesIterator()));
837
        self::assertArrayHasKey('address', iterator_to_array($adminMetadata->getDeclaredPropertiesIterator()));
838
839
        $guestAddress = $guestMetadata->getProperty('address');
840
        $adminAddress = $adminMetadata->getProperty('address');
841
842
        // assert not override attributes
843
        self::assertEquals($guestAddress->getName(), $adminAddress->getName());
844
        self::assertEquals(get_class($guestAddress), get_class($adminAddress));
845
        self::assertEquals($guestAddress->getMappedBy(), $adminAddress->getMappedBy());
846
        self::assertEquals($guestAddress->getInversedBy(), $adminAddress->getInversedBy());
847
        self::assertEquals($guestAddress->isOwningSide(), $adminAddress->isOwningSide());
848
        self::assertEquals($guestAddress->getFetchMode(), $adminAddress->getFetchMode());
849
        self::assertEquals($guestAddress->getCascade(), $adminAddress->getCascade());
850
851
        // assert override
852
        $guestAddressJoinColumns = $guestAddress->getJoinColumns();
853
        $guestAddressJoinColumn  = reset($guestAddressJoinColumns);
854
855
        self::assertEquals('address_id', $guestAddressJoinColumn->getColumnName());
856
857
        $adminAddressJoinColumns = $adminAddress->getJoinColumns();
858
        $adminAddressJoinColumn  = reset($adminAddressJoinColumns);
859
860
        self::assertEquals('adminaddress_id', $adminAddressJoinColumn->getColumnName());
861
    }
862
863
    /*
864
     * @group DDC-3579
865
     */
866
    public function testInversedByOverrideMapping()
867
    {
868
        $factory        = $this->createClassMetadataFactory();
869
        $adminMetadata  = $factory->getMetadataFor(DDC3579Admin::class);
870
871
        // assert groups association mappings
872
        self::assertArrayHasKey('groups', iterator_to_array($adminMetadata->getDeclaredPropertiesIterator()));
873
874
        $adminGroups = $adminMetadata->getProperty('groups');
875
876
        // assert override
877
        self::assertEquals('admins', $adminGroups->getInversedBy());
878
    }
879
880
    /**
881
     * @group DDC-5934
882
     */
883
    public function testFetchOverrideMapping()
884
    {
885
        // check override metadata
886
        $contractMetadata = $this->createClassMetadataFactory()->getMetadataFor(DDC5934Contract::class);
887
888
        self::assertArrayHasKey('members', iterator_to_array($contractMetadata->getDeclaredPropertiesIterator()));
889
890
        $contractMembers = $contractMetadata->getProperty('members');
891
892
        self::assertSame(Mapping\FetchMode::EXTRA_LAZY, $contractMembers->getFetchMode());
893
    }
894
895
    /**
896
     * @group DDC-964
897
     */
898
    public function testAttributeOverridesMapping()
899
    {
900
        $factory       = $this->createClassMetadataFactory();
901
        $adminMetadata = $factory->getMetadataFor(DDC964Admin::class);
902
903
        self::assertEquals(
904
            [
905
                'user_id' => 'id',
906
                'user_name' => 'name',
907
                'adminaddress_id' => 'address',
908
            ],
909
            $adminMetadata->fieldNames
910
        );
911
912
        self::assertNotNull($adminMetadata->getProperty('id'));
913
914
        $idProperty = $adminMetadata->getProperty('id');
915
916
        self::assertTrue($idProperty->isPrimaryKey());
917
        self::assertEquals('id', $idProperty->getName());
918
        self::assertEquals('user_id', $idProperty->getColumnName());
919
920
        self::assertNotNull($adminMetadata->getProperty('name'));
921
922
        $nameProperty = $adminMetadata->getProperty('name');
923
924
        self::assertEquals('name', $nameProperty->getName());
925
        self::assertEquals('user_name', $nameProperty->getColumnName());
926
        self::assertEquals(250, $nameProperty->getLength());
927
        self::assertTrue($nameProperty->isNullable());
928
        self::assertFalse($nameProperty->isUnique());
929
930
        $guestMetadata = $factory->getMetadataFor(DDC964Guest::class);
931
932
        self::assertEquals(
933
            [
934
                'guest_id' => 'id',
935
                'guest_name' => 'name',
936
                'address_id' => 'address',
937
            ],
938
            $guestMetadata->fieldNames
939
        );
940
941
        self::assertNotNull($guestMetadata->getProperty('id'));
942
943
        $idProperty = $guestMetadata->getProperty('id');
944
945
        self::assertTrue($idProperty->isPrimaryKey());
946
        self::assertEquals('id', $idProperty->getName());
947
        self::assertEquals('guest_id', $idProperty->getColumnName());
948
949
        self::assertNotNull($guestMetadata->getProperty('name'));
950
951
        $nameProperty = $guestMetadata->getProperty('name');
952
953
        self::assertEquals('name', $nameProperty->getName());
954
        self::assertEquals('guest_name', $nameProperty->getColumnName());
955
        self::assertEquals(240, $nameProperty->getLength());
956
        self::assertFalse($nameProperty->isNullable());
957
        self::assertTrue($nameProperty->isUnique());
958
    }
959
960
    /**
961
     * @group DDC-1955
962
     */
963
    public function testEntityListeners()
964
    {
965
        $factory    = $this->createClassMetadataFactory();
966
        $superClass = $factory->getMetadataFor(CompanyContract::class);
967
        $flexClass  = $factory->getMetadataFor(CompanyFixContract::class);
968
        $fixClass   = $factory->getMetadataFor(CompanyFlexContract::class);
969
970
        self::assertArrayHasKey(Events::prePersist, $superClass->entityListeners);
971
        self::assertArrayHasKey(Events::postPersist, $superClass->entityListeners);
972
973
        self::assertCount(1, $superClass->entityListeners[Events::prePersist]);
974
        self::assertCount(1, $superClass->entityListeners[Events::postPersist]);
975
976
        $postPersist = $superClass->entityListeners[Events::postPersist][0];
977
        $prePersist  = $superClass->entityListeners[Events::prePersist][0];
978
979
        self::assertEquals(CompanyContractListener::class, $postPersist['class']);
980
        self::assertEquals(CompanyContractListener::class, $prePersist['class']);
981
        self::assertEquals('postPersistHandler', $postPersist['method']);
982
        self::assertEquals('prePersistHandler', $prePersist['method']);
983
984
        //Inherited listeners
985
        self::assertEquals($fixClass->entityListeners, $superClass->entityListeners);
986
        self::assertEquals($flexClass->entityListeners, $superClass->entityListeners);
987
    }
988
989
    /**
990
     * @group DDC-1955
991
     */
992
    public function testEntityListenersOverride()
993
    {
994
        $factory    = $this->createClassMetadataFactory();
995
        $ultraClass = $factory->getMetadataFor(CompanyFlexUltraContract::class);
996
997
        //overridden listeners
998
        self::assertArrayHasKey(Events::postPersist, $ultraClass->entityListeners);
999
        self::assertArrayHasKey(Events::prePersist, $ultraClass->entityListeners);
1000
1001
        self::assertCount(1, $ultraClass->entityListeners[Events::postPersist]);
1002
        self::assertCount(3, $ultraClass->entityListeners[Events::prePersist]);
1003
1004
        $postPersist = $ultraClass->entityListeners[Events::postPersist][0];
1005
        $prePersist  = $ultraClass->entityListeners[Events::prePersist][0];
1006
1007
        self::assertEquals(CompanyContractListener::class, $postPersist['class']);
1008
        self::assertEquals(CompanyContractListener::class, $prePersist['class']);
1009
        self::assertEquals('postPersistHandler', $postPersist['method']);
1010
        self::assertEquals('prePersistHandler', $prePersist['method']);
1011
1012
        $prePersist = $ultraClass->entityListeners[Events::prePersist][1];
1013
        self::assertEquals(CompanyFlexUltraContractListener::class, $prePersist['class']);
1014
        self::assertEquals('prePersistHandler1', $prePersist['method']);
1015
1016
        $prePersist = $ultraClass->entityListeners[Events::prePersist][2];
1017
        self::assertEquals(CompanyFlexUltraContractListener::class, $prePersist['class']);
1018
        self::assertEquals('prePersistHandler2', $prePersist['method']);
1019
    }
1020
1021
1022
    /**
1023
     * @group DDC-1955
1024
     */
1025
    public function testEntityListenersNamingConvention()
1026
    {
1027
        $factory  = $this->createClassMetadataFactory();
1028
        $metadata = $factory->getMetadataFor(CmsAddress::class);
1029
1030
        self::assertArrayHasKey(Events::postPersist, $metadata->entityListeners);
1031
        self::assertArrayHasKey(Events::prePersist, $metadata->entityListeners);
1032
        self::assertArrayHasKey(Events::postUpdate, $metadata->entityListeners);
1033
        self::assertArrayHasKey(Events::preUpdate, $metadata->entityListeners);
1034
        self::assertArrayHasKey(Events::postRemove, $metadata->entityListeners);
1035
        self::assertArrayHasKey(Events::preRemove, $metadata->entityListeners);
1036
        self::assertArrayHasKey(Events::postLoad, $metadata->entityListeners);
1037
        self::assertArrayHasKey(Events::preFlush, $metadata->entityListeners);
1038
1039
        self::assertCount(1, $metadata->entityListeners[Events::postPersist]);
1040
        self::assertCount(1, $metadata->entityListeners[Events::prePersist]);
1041
        self::assertCount(1, $metadata->entityListeners[Events::postUpdate]);
1042
        self::assertCount(1, $metadata->entityListeners[Events::preUpdate]);
1043
        self::assertCount(1, $metadata->entityListeners[Events::postRemove]);
1044
        self::assertCount(1, $metadata->entityListeners[Events::preRemove]);
1045
        self::assertCount(1, $metadata->entityListeners[Events::postLoad]);
1046
        self::assertCount(1, $metadata->entityListeners[Events::preFlush]);
1047
1048
        $postPersist = $metadata->entityListeners[Events::postPersist][0];
1049
        $prePersist  = $metadata->entityListeners[Events::prePersist][0];
1050
        $postUpdate  = $metadata->entityListeners[Events::postUpdate][0];
1051
        $preUpdate   = $metadata->entityListeners[Events::preUpdate][0];
1052
        $postRemove  = $metadata->entityListeners[Events::postRemove][0];
1053
        $preRemove   = $metadata->entityListeners[Events::preRemove][0];
1054
        $postLoad    = $metadata->entityListeners[Events::postLoad][0];
1055
        $preFlush    = $metadata->entityListeners[Events::preFlush][0];
1056
1057
        self::assertEquals(CmsAddressListener::class, $postPersist['class']);
1058
        self::assertEquals(CmsAddressListener::class, $prePersist['class']);
1059
        self::assertEquals(CmsAddressListener::class, $postUpdate['class']);
1060
        self::assertEquals(CmsAddressListener::class, $preUpdate['class']);
1061
        self::assertEquals(CmsAddressListener::class, $postRemove['class']);
1062
        self::assertEquals(CmsAddressListener::class, $preRemove['class']);
1063
        self::assertEquals(CmsAddressListener::class, $postLoad['class']);
1064
        self::assertEquals(CmsAddressListener::class, $preFlush['class']);
1065
1066
        self::assertEquals(Events::postPersist, $postPersist['method']);
1067
        self::assertEquals(Events::prePersist, $prePersist['method']);
1068
        self::assertEquals(Events::postUpdate, $postUpdate['method']);
1069
        self::assertEquals(Events::preUpdate, $preUpdate['method']);
1070
        self::assertEquals(Events::postRemove, $postRemove['method']);
1071
        self::assertEquals(Events::preRemove, $preRemove['method']);
1072
        self::assertEquals(Events::postLoad, $postLoad['method']);
1073
        self::assertEquals(Events::preFlush, $preFlush['method']);
1074
    }
1075
1076
    /**
1077
     * @group DDC-2183
1078
     */
1079
    public function testSecondLevelCacheMapping()
1080
    {
1081
        $factory = $this->createClassMetadataFactory();
1082
        $class   = $factory->getMetadataFor(City::class);
1083
1084
        self::assertNotNull($class->getCache());
1085
        self::assertEquals(Mapping\CacheUsage::READ_ONLY, $class->getCache()->getUsage());
1086
        self::assertEquals('doctrine_tests_models_cache_city', $class->getCache()->getRegion());
1087
1088
        self::assertArrayHasKey('state', iterator_to_array($class->getDeclaredPropertiesIterator()));
1089
1090
        $stateAssociation = $class->getProperty('state');
1091
1092
        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

1092
        self::assertNotNull($stateAssociation->/** @scrutinizer ignore-call */ getCache());
Loading history...
1093
        self::assertEquals(Mapping\CacheUsage::READ_ONLY, $stateAssociation->getCache()->getUsage());
1094
        self::assertEquals('doctrine_tests_models_cache_city__state', $stateAssociation->getCache()->getRegion());
1095
1096
        self::assertArrayHasKey('attractions', iterator_to_array($class->getDeclaredPropertiesIterator()));
1097
1098
        $attractionsAssociation = $class->getProperty('attractions');
1099
1100
        self::assertNotNull($attractionsAssociation->getCache());
1101
        self::assertEquals(Mapping\CacheUsage::READ_ONLY, $attractionsAssociation->getCache()->getUsage());
1102
        self::assertEquals('doctrine_tests_models_cache_city__attractions', $attractionsAssociation->getCache()->getRegion());
1103
    }
1104
1105
    /**
1106
     * @group DDC-2825
1107
     * @group 881
1108
     */
1109
    public function testSchemaDefinitionViaExplicitTableSchemaAnnotationProperty()
1110
    {
1111
        $factory  = $this->createClassMetadataFactory();
1112
        $metadata = $factory->getMetadataFor(ExplicitSchemaAndTable::class);
1113
1114
        self::assertSame('explicit_schema', $metadata->getSchemaName());
1115
        self::assertSame('explicit_table', $metadata->getTableName());
1116
    }
1117
1118
    /**
1119
     * @group DDC-2825
1120
     * @group 881
1121
     */
1122
    public function testSchemaDefinitionViaSchemaDefinedInTableNameInTableAnnotationProperty()
1123
    {
1124
        $factory  = $this->createClassMetadataFactory();
1125
        $metadata = $factory->getMetadataFor(SchemaAndTableInTableName::class);
1126
1127
        self::assertSame('implicit_schema', $metadata->getSchemaName());
1128
        self::assertSame('implicit_table', $metadata->getTableName());
1129
    }
1130
1131
    /**
1132
     * @group DDC-514
1133
     * @group DDC-1015
1134
     */
1135
    public function testDiscriminatorColumnDefaultLength()
1136
    {
1137
        if (strpos(get_class($this), 'PHPMappingDriver') !== false) {
1138
            $this->markTestSkipped('PHP Mapping Drivers have no defaults.');
1139
        }
1140
1141
        $class = $this->createClassMetadata(SingleTableEntityNoDiscriminatorColumnMapping::class);
1142
1143
        self::assertEquals(255, $class->discriminatorColumn->getLength());
1144
1145
        $class = $this->createClassMetadata(SingleTableEntityIncompleteDiscriminatorColumnMapping::class);
1146
1147
        self::assertEquals(255, $class->discriminatorColumn->getLength());
1148
    }
1149
1150
    /**
1151
     * @group DDC-514
1152
     * @group DDC-1015
1153
     */
1154
    public function testDiscriminatorColumnDefaultType()
1155
    {
1156
        if (strpos(get_class($this), 'PHPMappingDriver') !== false) {
1157
            $this->markTestSkipped('PHP Mapping Drivers have no defaults.');
1158
        }
1159
1160
        $class = $this->createClassMetadata(SingleTableEntityNoDiscriminatorColumnMapping::class);
1161
1162
        self::assertEquals('string', $class->discriminatorColumn->getTypeName());
1163
1164
        $class = $this->createClassMetadata(SingleTableEntityIncompleteDiscriminatorColumnMapping::class);
1165
1166
        self::assertEquals('string', $class->discriminatorColumn->getTypeName());
1167
    }
1168
1169
    /**
1170
     * @group DDC-514
1171
     * @group DDC-1015
1172
     */
1173
    public function testDiscriminatorColumnDefaultName()
1174
    {
1175
        if (strpos(get_class($this), 'PHPMappingDriver') !== false) {
1176
            $this->markTestSkipped('PHP Mapping Drivers have no defaults.');
1177
        }
1178
1179
        $class = $this->createClassMetadata(SingleTableEntityNoDiscriminatorColumnMapping::class);
1180
1181
        self::assertEquals('dtype', $class->discriminatorColumn->getColumnName());
1182
1183
        $class = $this->createClassMetadata(SingleTableEntityIncompleteDiscriminatorColumnMapping::class);
1184
1185
        self::assertEquals('dtype', $class->discriminatorColumn->getColumnName());
1186
    }
1187
}
1188
1189
/**
1190
 * @ORM\Entity
1191
 * @ORM\HasLifecycleCallbacks
1192
 * @ORM\Table(
1193
 *  name="cms_users",
1194
 *  uniqueConstraints={@ORM\UniqueConstraint(name="search_idx", columns={"name", "user_email"})},
1195
 *  indexes={@ORM\Index(name="name_idx", columns={"name"}), @ORM\Index(columns={"user_email"})},
1196
 *  options={"foo": "bar", "baz": {"key": "val"}}
1197
 * )
1198
 */
1199
class User
1200
{
1201
    /**
1202
     * @ORM\Id
1203
     * @ORM\Column(type="integer", options={"foo": "bar", "unsigned": false})
1204
     * @ORM\GeneratedValue(strategy="AUTO")
1205
     * @ORM\SequenceGenerator(sequenceName="tablename_seq", allocationSize=100)
1206
     */
1207
    public $id;
1208
1209
    /**
1210
     * @ORM\Column(length=50, nullable=true, unique=true, options={"foo": "bar", "baz": {"key": "val"}, "fixed": false})
1211
     */
1212
    public $name;
1213
1214
    /**
1215
     * @ORM\Column(name="user_email", columnDefinition="CHAR(32) NOT NULL")
1216
     */
1217
    public $email;
1218
1219
    /**
1220
     * @ORM\OneToOne(targetEntity=Address::class, cascade={"remove"}, inversedBy="user")
1221
     * @ORM\JoinColumn(onDelete="CASCADE")
1222
     */
1223
    public $address;
1224
1225
    /**
1226
     * @ORM\OneToMany(targetEntity=Phonenumber::class, mappedBy="user", cascade={"persist"}, orphanRemoval=true)
1227
     * @ORM\OrderBy({"number"="ASC"})
1228
     */
1229
    public $phonenumbers;
1230
1231
    /**
1232
     * @ORM\ManyToMany(targetEntity=Group::class, cascade={"all"})
1233
     * @ORM\JoinTable(name="cms_user_groups",
1234
     *    joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=false, unique=false)},
1235
     *    inverseJoinColumns={@ORM\JoinColumn(name="group_id", referencedColumnName="id", columnDefinition="INT NULL")}
1236
     * )
1237
     */
1238
    public $groups;
1239
1240
    /**
1241
     * @ORM\Column(type="integer")
1242
     * @ORM\Version
1243
     */
1244
    public $version;
1245
1246
1247
    /**
1248
     * @ORM\PrePersist
1249
     */
1250
    public function doStuffOnPrePersist()
1251
    {
1252
    }
1253
1254
    /**
1255
     * @ORM\PrePersist
1256
     */
1257
    public function doOtherStuffOnPrePersistToo()
1258
    {
1259
    }
1260
1261
    /**
1262
     * @ORM\PostPersist
1263
     */
1264
    public function doStuffOnPostPersist()
1265
    {
1266
    }
1267
1268
    public static function loadMetadata(ClassMetadata $metadata)
1269
    {
1270
        $tableMetadata = new Mapping\TableMetadata();
1271
1272
        $tableMetadata->setName('cms_users');
1273
        $tableMetadata->addIndex(
1274
            [
1275
                'name'    => 'name_idx',
1276
                'columns' => ['name'],
1277
                'unique'  => false,
1278
                'options' => [],
1279
                'flags'   => [],
1280
            ]
1281
        );
1282
1283
        $tableMetadata->addIndex(
1284
            [
1285
                'name'    => null,
1286
                'columns' => ['user_email'],
1287
                'unique'  => false,
1288
                'options' => [],
1289
                'flags'   => [],
1290
            ]
1291
        );
1292
1293
        $tableMetadata->addUniqueConstraint(
1294
            [
1295
                'name'    => 'search_idx',
1296
                'columns' => ['name', 'user_email'],
1297
                'options' => [],
1298
                'flags'   => [],
1299
            ]
1300
        );
1301
        $tableMetadata->addOption('foo', 'bar');
1302
        $tableMetadata->addOption('baz', ['key' => 'val']);
1303
1304
        $metadata->setTable($tableMetadata);
1305
        $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

1305
        $metadata->setInheritanceType(/** @scrutinizer ignore-type */ Mapping\InheritanceType::NONE);
Loading history...
1306
        $metadata->setChangeTrackingPolicy(Mapping\ChangeTrackingPolicy::DEFERRED_IMPLICIT);
1307
1308
        $metadata->addLifecycleCallback('doStuffOnPrePersist', 'prePersist');
1309
        $metadata->addLifecycleCallback('doOtherStuffOnPrePersistToo', 'prePersist');
1310
        $metadata->addLifecycleCallback('doStuffOnPostPersist', 'postPersist');
1311
1312
        $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

1312
        $metadata->/** @scrutinizer ignore-call */ 
1313
                   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...
1313
            [
1314
                'sequenceName'   => 'tablename_seq',
1315
                'allocationSize' => 100,
1316
            ]
1317
        );
1318
1319
        $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

1319
        $metadata->/** @scrutinizer ignore-call */ 
1320
                   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...
1320
            [
1321
                'name' => 'all',
1322
                'query' => 'SELECT u FROM __CLASS__ u'
1323
            ]
1324
        );
1325
1326
        $fieldMetadata = new Mapping\FieldMetadata('id');
1327
        $fieldMetadata->setType(Type::getType('integer'));
1328
        $fieldMetadata->setPrimaryKey(true);
1329
        $fieldMetadata->setOptions(['foo' => 'bar', 'unsigned' => false]);
1330
1331
        $metadata->addProperty($fieldMetadata);
1332
1333
        $fieldMetadata = new Mapping\FieldMetadata('name');
1334
        $fieldMetadata->setType(Type::getType('string'));
1335
        $fieldMetadata->setLength(50);
1336
        $fieldMetadata->setNullable(true);
1337
        $fieldMetadata->setUnique(true);
1338
        $fieldMetadata->setOptions(
1339
            [
1340
                'foo' => 'bar',
1341
                'baz' => [
1342
                    'key' => 'val',
1343
                ],
1344
                'fixed' => false,
1345
            ]
1346
        );
1347
1348
        $metadata->addProperty($fieldMetadata);
1349
1350
        $fieldMetadata = new Mapping\FieldMetadata('email');
1351
1352
        $fieldMetadata->setType(Type::getType('string'));
1353
        $fieldMetadata->setColumnName('user_email');
1354
        $fieldMetadata->setColumnDefinition('CHAR(32) NOT NULL');
1355
1356
        $metadata->addProperty($fieldMetadata);
1357
1358
        $fieldMetadata = new Mapping\VersionFieldMetadata('version');
1359
1360
        $fieldMetadata->setType(Type::getType('integer'));
1361
1362
        $metadata->addProperty($fieldMetadata);
1363
        $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

1363
        $metadata->/** @scrutinizer ignore-call */ 
1364
                   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...
1364
1365
        $joinColumns = [];
1366
1367
        $joinColumn = new Mapping\JoinColumnMetadata();
1368
1369
        $joinColumn->setColumnName('address_id');
1370
        $joinColumn->setReferencedColumnName('id');
1371
        $joinColumn->setOnDelete('CASCADE');
1372
1373
        $joinColumns[] = $joinColumn;
1374
1375
        $association = new Mapping\OneToOneAssociationMetadata('address');
1376
1377
        $association->setJoinColumns($joinColumns);
1378
        $association->setTargetEntity(Address::class);
1379
        $association->setInversedBy('user');
1380
        $association->setCascade(['remove']);
1381
        $association->setOrphanRemoval(false);
1382
1383
        $metadata->addProperty($association);
1384
1385
        $association = new Mapping\OneToManyAssociationMetadata('phonenumbers');
1386
1387
        $association->setTargetEntity(Phonenumber::class);
1388
        $association->setMappedBy('user');
1389
        $association->setCascade(['persist']);
1390
        $association->setOrderBy(['number' => 'ASC']);
1391
        $association->setOrphanRemoval(true);
1392
1393
        $metadata->addProperty($association);
1394
1395
        $joinTable = new Mapping\JoinTableMetadata();
1396
        $joinTable->setName('cms_users_groups');
1397
1398
        $joinColumn = new Mapping\JoinColumnMetadata();
1399
1400
        $joinColumn->setColumnName('user_id');
1401
        $joinColumn->setReferencedColumnName('id');
1402
        $joinColumn->setNullable(false);
1403
        $joinColumn->setUnique(false);
1404
1405
        $joinTable->addJoinColumn($joinColumn);
1406
1407
        $joinColumn = new Mapping\JoinColumnMetadata();
1408
1409
        $joinColumn->setColumnName('group_id');
1410
        $joinColumn->setReferencedColumnName('id');
1411
        $joinColumn->setColumnDefinition('INT NULL');
1412
1413
        $joinTable->addInverseJoinColumn($joinColumn);
1414
1415
        $association = new Mapping\ManyToManyAssociationMetadata('groups');
1416
1417
        $association->setJoinTable($joinTable);
1418
        $association->setTargetEntity(Group::class);
1419
        $association->setCascade(['remove', 'persist', 'refresh']);
1420
1421
        $metadata->addProperty($association);
1422
    }
1423
}
1424
1425
/**
1426
 * @ORM\Entity
1427
 * @ORM\InheritanceType("SINGLE_TABLE")
1428
 * @ORM\DiscriminatorMap({"cat" = Cat::class, "dog" = Dog::class})
1429
 * @ORM\DiscriminatorColumn(name="discr", length=32, type="string")
1430
 */
1431
abstract class Animal
1432
{
1433
    /**
1434
     * @ORM\Id @ORM\Column(type="string") @ORM\GeneratedValue(strategy="CUSTOM")
1435
     * @ORM\CustomIdGenerator(class=stdClass::class)
1436
     */
1437
    public $id;
1438
}
1439
1440
/** @ORM\Entity */
1441
class Cat extends Animal
1442
{
1443
}
1444
1445
/** @ORM\Entity */
1446
class Dog extends Animal
1447
{
1448
}
1449
1450
/**
1451
 * @ORM\Entity
1452
 */
1453
class DDC1170Entity
1454
{
1455
    /**
1456
     * @param string $value
1457
     */
1458
    public function __construct($value = null)
1459
    {
1460
        $this->value = $value;
1461
    }
1462
1463
    /**
1464
     * @ORM\Id
1465
     * @ORM\GeneratedValue(strategy="NONE")
1466
     * @ORM\Column(type="integer", columnDefinition = "INT unsigned NOT NULL")
1467
     */
1468
    private $id;
1469
1470
    /**
1471
     * @ORM\Column(columnDefinition = "VARCHAR(255) NOT NULL")
1472
     */
1473
    private $value;
1474
1475
    /**
1476
     * @return int
1477
     */
1478
    public function getId()
1479
    {
1480
        return $this->id;
1481
    }
1482
1483
    /**
1484
     * @return string
1485
     */
1486
    public function getValue()
1487
    {
1488
        return $this->value;
1489
    }
1490
}
1491
1492
/**
1493
 * @ORM\Entity
1494
 * @ORM\InheritanceType("SINGLE_TABLE")
1495
 * @ORM\DiscriminatorMap({"ONE" = DDC807SubClasse1::class, "TWO" = DDC807SubClasse2::class})
1496
 * @ORM\DiscriminatorColumn(name = "dtype", columnDefinition="ENUM('ONE','TWO')")
1497
 */
1498
class DDC807Entity
1499
{
1500
    /**
1501
     * @ORM\Id
1502
     * @ORM\Column(type="integer")
1503
     * @ORM\GeneratedValue(strategy="NONE")
1504
     */
1505
    public $id;
1506
}
1507
1508
class DDC807SubClasse1 {}
1509
class DDC807SubClasse2 {}
1510
1511
class Address {}
1512
class Phonenumber {}
1513
class Group {}
1514
1515
/**
1516
 * @ORM\Entity
1517
 * @ORM\Table(indexes={@ORM\Index(columns={"content"}, flags={"fulltext"}, options={"where": "content IS NOT NULL"})})
1518
 */
1519
class Comment
1520
{
1521
    /**
1522
     * @ORM\Column(type="text")
1523
     */
1524
    private $content;
0 ignored issues
show
introduced by
The private property $content is not used, and could be removed.
Loading history...
1525
}
1526
1527
/**
1528
 * @ORM\Entity
1529
 * @ORM\InheritanceType("SINGLE_TABLE")
1530
 * @ORM\DiscriminatorMap({
1531
 *     "ONE" = Doctrine\Tests\ORM\Mapping\SingleTableEntityNoDiscriminatorColumnMappingSub1::class,
1532
 *     "TWO" = Doctrine\Tests\ORM\Mapping\SingleTableEntityNoDiscriminatorColumnMappingSub2::class
1533
 * })
1534
 */
1535
class SingleTableEntityNoDiscriminatorColumnMapping
1536
{
1537
    /**
1538
     * @ORM\Id
1539
     * @ORM\Column(type="integer")
1540
     * @ORM\GeneratedValue(strategy="NONE")
1541
     */
1542
    public $id;
1543
}
1544
1545
/**
1546
 * @ORM\Entity
1547
 */
1548
class SingleTableEntityNoDiscriminatorColumnMappingSub1 extends SingleTableEntityNoDiscriminatorColumnMapping {}
1549
1550
/**
1551
 * @ORM\Entity
1552
 */
1553
class SingleTableEntityNoDiscriminatorColumnMappingSub2 extends SingleTableEntityNoDiscriminatorColumnMapping {}
1554
1555
/**
1556
 * @ORM\Entity
1557
 * @ORM\InheritanceType("SINGLE_TABLE")
1558
 * @ORM\DiscriminatorMap({
1559
 *     "ONE" = Doctrine\Tests\ORM\Mapping\SingleTableEntityIncompleteDiscriminatorColumnMappingSub1::class,
1560
 *     "TWO" = Doctrine\Tests\ORM\Mapping\SingleTableEntityIncompleteDiscriminatorColumnMappingSub2::class
1561
 * })
1562
 * @ORM\DiscriminatorColumn(name="dtype")
1563
 */
1564
class SingleTableEntityIncompleteDiscriminatorColumnMapping
1565
{
1566
    /**
1567
     * @ORM\Id
1568
     * @ORM\Column(type="integer")
1569
     * @ORM\GeneratedValue(strategy="NONE")
1570
     */
1571
    public $id;
1572
}
1573
1574
class SingleTableEntityIncompleteDiscriminatorColumnMappingSub1
1575
    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...
1576
1577
class SingleTableEntityIncompleteDiscriminatorColumnMappingSub2
1578
    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...
1579