Completed
Pull Request — master (#5938)
by Maximilian
10:06
created

AbstractMappingDriverTest::testIdentifier()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 5
nc 1
nop 1
1
<?php
2
3
namespace Doctrine\Tests\ORM\Mapping;
4
5
use Doctrine\Common\Persistence\Mapping\RuntimeReflectionService;
6
use Doctrine\ORM\EntityManager;
7
use Doctrine\ORM\Events;
8
use Doctrine\ORM\Mapping\ClassMetadataFactory;
9
use Doctrine\ORM\Mapping\DiscriminatorColumn;
10
use Doctrine\ORM\Mapping\Id;
11
use Doctrine\ORM\Mapping\MappingException;
12
use Doctrine\ORM\Mapping\UnderscoreNamingStrategy;
13
use Doctrine\Tests\Models\Cache\City;
14
use Doctrine\ORM\Mapping\ClassMetadata;
15
use Doctrine\ORM\Mapping\ClassMetadataInfo;
16
use Doctrine\Tests\Models\DDC2825\ExplicitSchemaAndTable;
17
use Doctrine\Tests\Models\DDC2825\SchemaAndTableInTableName;
18
use Doctrine\Tests\OrmTestCase;
19
20
abstract class AbstractMappingDriverTest extends OrmTestCase
21
{
22
    abstract protected function _loadDriver();
23
24
    public function createClassMetadata($entityClassName)
25
    {
26
        $mappingDriver = $this->_loadDriver();
27
28
        $class = new ClassMetadata($entityClassName);
29
        $class->initializeReflection(new RuntimeReflectionService());
30
        $mappingDriver->loadMetadataForClass($entityClassName, $class);
31
32
        return $class;
33
    }
34
35
    /**
36
     * @param \Doctrine\ORM\EntityManager $entityClassName
0 ignored issues
show
Bug introduced by
There is no parameter named $entityClassName. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
37
     * @return \Doctrine\ORM\Mapping\ClassMetadataFactory
38
     */
39
    protected function createClassMetadataFactory(EntityManager $em = null)
40
    {
41
        $driver     = $this->_loadDriver();
42
        $em         = $em ?: $this->_getTestEntityManager();
43
        $factory    = new ClassMetadataFactory();
44
        $em->getConfiguration()->setMetadataDriverImpl($driver);
45
        $factory->setEntityManager($em);
46
47
        return $factory;
48
    }
49
50
    public function testLoadMapping()
51
    {
52
        $entityClassName = 'Doctrine\Tests\ORM\Mapping\User';
53
        return $this->createClassMetadata($entityClassName);
54
    }
55
56
    /**
57
     * @depends testLoadMapping
58
     * @param ClassMetadata $class
59
     */
60
    public function testEntityTableNameAndInheritance($class)
61
    {
62
        $this->assertEquals('cms_users', $class->getTableName());
63
        $this->assertEquals(ClassMetadata::INHERITANCE_TYPE_NONE, $class->inheritanceType);
64
65
        return $class;
66
    }
67
68
    /**
69
     * @depends testEntityTableNameAndInheritance
70
     * @param ClassMetadata $class
71
     */
72
    public function testEntityIndexes($class)
73
    {
74
        $this->assertArrayHasKey('indexes', $class->table, 'ClassMetadata should have indexes key in table property.');
75
        $this->assertEquals(array(
76
            'name_idx' => array('columns' => array('name')),
77
            0 => array('columns' => array('user_email'))
78
        ), $class->table['indexes']);
79
80
        return $class;
81
    }
82
83
    public function testEntityIndexFlagsAndPartialIndexes()
84
    {
85
        $class = $this->createClassMetadata('Doctrine\Tests\ORM\Mapping\Comment');
86
87
        $this->assertEquals(array(
88
            0 => array(
89
                'columns' => array('content'),
90
                'flags' => array('fulltext'),
91
                'options' => array('where' => 'content IS NOT NULL'),
92
            )
93
        ), $class->table['indexes']);
94
    }
95
96
    /**
97
     * @depends testEntityTableNameAndInheritance
98
     * @param ClassMetadata $class
99
     */
100
    public function testEntityUniqueConstraints($class)
101
    {
102
        $this->assertArrayHasKey('uniqueConstraints', $class->table,
103
            'ClassMetadata should have uniqueConstraints key in table property when Unique Constraints are set.');
104
105
        $this->assertEquals(array(
106
            "search_idx" => array("columns" => array("name", "user_email"), 'options' => array('where' => 'name IS NOT NULL'))
107
        ), $class->table['uniqueConstraints']);
108
109
        return $class;
110
    }
111
112
    /**
113
     * @depends testEntityTableNameAndInheritance
114
     * @param ClassMetadata $class
115
     */
116
    public function testEntityOptions($class)
117
    {
118
        $this->assertArrayHasKey('options', $class->table, 'ClassMetadata should have options key in table property.');
119
120
        $this->assertEquals(array(
121
            'foo' => 'bar', 'baz' => array('key' => 'val')
122
        ), $class->table['options']);
123
124
        return $class;
125
    }
126
127
    /**
128
     * @depends testEntityOptions
129
     * @param ClassMetadata $class
130
     */
131
    public function testEntitySequence($class)
132
    {
133
        $this->assertInternalType('array', $class->sequenceGeneratorDefinition, 'No Sequence Definition set on this driver.');
134
        $this->assertEquals(
135
            array(
136
                'sequenceName' => 'tablename_seq',
137
                'allocationSize' => 100,
138
                'initialValue' => 1,
139
            ),
140
            $class->sequenceGeneratorDefinition
141
        );
142
    }
143
144
    public function testEntityCustomGenerator()
145
    {
146
        $class = $this->createClassMetadata('Doctrine\Tests\ORM\Mapping\Animal');
147
148
        $this->assertEquals(ClassMetadata::GENERATOR_TYPE_CUSTOM,
149
            $class->generatorType, "Generator Type");
150
        $this->assertEquals(
151
            array("class" => "stdClass"),
152
            $class->customGeneratorDefinition,
153
            "Custom Generator Definition");
154
    }
155
156
157
    /**
158
     * @depends testEntityTableNameAndInheritance
159
     * @param ClassMetadata $class
160
     */
161
    public function testFieldMappings($class)
162
    {
163
        $this->assertEquals(4, count($class->fieldMappings));
164
        $this->assertTrue(isset($class->fieldMappings['id']));
165
        $this->assertTrue(isset($class->fieldMappings['name']));
166
        $this->assertTrue(isset($class->fieldMappings['email']));
167
        $this->assertTrue(isset($class->fieldMappings['version']));
168
169
        return $class;
170
    }
171
172
    /**
173
     * @depends testFieldMappings
174
     * @param ClassMetadata $class
175
     */
176
    public function testVersionedField($class)
177
    {
178
        $this->assertTrue($class->isVersioned);
179
        $this->assertEquals("version", $class->versionField);
180
181
        $this->assertFalse(isset($class->fieldMappings['version']['version']));
182
    }
183
184
    /**
185
     * @depends testEntityTableNameAndInheritance
186
     * @param ClassMetadata $class
187
     */
188
    public function testFieldMappingsColumnNames($class)
189
    {
190
        $this->assertEquals("id", $class->fieldMappings['id']['columnName']);
191
        $this->assertEquals("name", $class->fieldMappings['name']['columnName']);
192
        $this->assertEquals("user_email", $class->fieldMappings['email']['columnName']);
193
194
        return $class;
195
    }
196
197
    /**
198
     * @depends testEntityTableNameAndInheritance
199
     * @param ClassMetadata $class
200
     */
201
    public function testStringFieldMappings($class)
202
    {
203
        $this->assertEquals('string', $class->fieldMappings['name']['type']);
204
        $this->assertEquals(50, $class->fieldMappings['name']['length']);
205
        $this->assertTrue($class->fieldMappings['name']['nullable']);
206
        $this->assertTrue($class->fieldMappings['name']['unique']);
207
208
        return $class;
209
    }
210
211
    /**
212
     * @depends testEntityTableNameAndInheritance
213
     * @param ClassMetadata $class
214
     */
215
    public function testFieldOptions($class)
216
    {
217
        $expected = array('foo' => 'bar', 'baz' => array('key' => 'val'));
218
        $this->assertEquals($expected, $class->fieldMappings['name']['options']);
219
220
        return $class;
221
    }
222
223
    /**
224
     * @depends testEntityTableNameAndInheritance
225
     * @param ClassMetadata $class
226
     */
227
    public function testIdFieldOptions($class)
228
    {
229
        $this->assertEquals(array('foo' => 'bar'), $class->fieldMappings['id']['options']);
230
231
        return $class;
232
    }
233
234
    /**
235
     * @depends testFieldMappings
236
     * @param ClassMetadata $class
237
     */
238
    public function testIdentifier($class)
239
    {
240
        $this->assertEquals(array('id'), $class->identifier);
241
        $this->assertEquals('integer', $class->fieldMappings['id']['type']);
242
        $this->assertEquals(ClassMetadata::GENERATOR_TYPE_AUTO, $class->generatorType, "ID-Generator is not ClassMetadata::GENERATOR_TYPE_AUTO");
243
244
        return $class;
245
    }
246
247
    /**
248
     * @depends testIdentifier
249
     * @param ClassMetadata $class
250
     */
251
    public function testAssociations($class)
252
    {
253
        $this->assertEquals(3, count($class->associationMappings));
254
255
        return $class;
256
    }
257
258
    /**
259
     * @depends testAssociations
260
     * @param ClassMetadata $class
261
     */
262
    public function testOwningOneToOneAssociation($class)
263
    {
264
        $this->assertTrue(isset($class->associationMappings['address']));
265
        $this->assertTrue($class->associationMappings['address']['isOwningSide']);
266
        $this->assertEquals('user', $class->associationMappings['address']['inversedBy']);
267
        // Check cascading
268
        $this->assertTrue($class->associationMappings['address']['isCascadeRemove']);
269
        $this->assertFalse($class->associationMappings['address']['isCascadePersist']);
270
        $this->assertFalse($class->associationMappings['address']['isCascadeRefresh']);
271
        $this->assertFalse($class->associationMappings['address']['isCascadeDetach']);
272
        $this->assertFalse($class->associationMappings['address']['isCascadeMerge']);
273
274
        return $class;
275
    }
276
277
    /**
278
     * @depends testOwningOneToOneAssociation
279
     * @param ClassMetadata $class
280
     */
281
    public function testInverseOneToManyAssociation($class)
282
    {
283
        $this->assertTrue(isset($class->associationMappings['phonenumbers']));
284
        $this->assertFalse($class->associationMappings['phonenumbers']['isOwningSide']);
285
        $this->assertTrue($class->associationMappings['phonenumbers']['isCascadePersist']);
286
        $this->assertTrue($class->associationMappings['phonenumbers']['isCascadeRemove']);
287
        $this->assertFalse($class->associationMappings['phonenumbers']['isCascadeRefresh']);
288
        $this->assertFalse($class->associationMappings['phonenumbers']['isCascadeDetach']);
289
        $this->assertFalse($class->associationMappings['phonenumbers']['isCascadeMerge']);
290
        $this->assertTrue($class->associationMappings['phonenumbers']['orphanRemoval']);
291
292
        // Test Order By
293
        $this->assertEquals(array('number' => 'ASC'), $class->associationMappings['phonenumbers']['orderBy']);
294
295
        return $class;
296
    }
297
298
    /**
299
     * @depends testInverseOneToManyAssociation
300
     * @param ClassMetadata $class
301
     */
302
    public function testManyToManyAssociationWithCascadeAll($class)
303
    {
304
        $this->assertTrue(isset($class->associationMappings['groups']));
305
        $this->assertTrue($class->associationMappings['groups']['isOwningSide']);
306
        // Make sure that cascade-all works as expected
307
        $this->assertTrue($class->associationMappings['groups']['isCascadeRemove']);
308
        $this->assertTrue($class->associationMappings['groups']['isCascadePersist']);
309
        $this->assertTrue($class->associationMappings['groups']['isCascadeRefresh']);
310
        $this->assertTrue($class->associationMappings['groups']['isCascadeDetach']);
311
        $this->assertTrue($class->associationMappings['groups']['isCascadeMerge']);
312
313
        $this->assertFalse(isset($class->associationMappings['groups']['orderBy']));
314
315
        return $class;
316
    }
317
318
    /**
319
     * @depends testManyToManyAssociationWithCascadeAll
320
     * @param ClassMetadata $class
321
     */
322
    public function testLifecycleCallbacks($class)
323
    {
324
        $this->assertEquals(count($class->lifecycleCallbacks), 2);
325
        $this->assertEquals($class->lifecycleCallbacks['prePersist'][0], 'doStuffOnPrePersist');
326
        $this->assertEquals($class->lifecycleCallbacks['postPersist'][0], 'doStuffOnPostPersist');
327
328
        return $class;
329
    }
330
331
    /**
332
     * @depends testManyToManyAssociationWithCascadeAll
333
     * @param ClassMetadata $class
334
     */
335
    public function testLifecycleCallbacksSupportMultipleMethodNames($class)
336
    {
337
        $this->assertEquals(count($class->lifecycleCallbacks['prePersist']), 2);
338
        $this->assertEquals($class->lifecycleCallbacks['prePersist'][1], 'doOtherStuffOnPrePersistToo');
339
340
        return $class;
341
    }
342
343
    /**
344
     * @depends testLifecycleCallbacksSupportMultipleMethodNames
345
     * @param ClassMetadata $class
346
     */
347
    public function testJoinColumnUniqueAndNullable($class)
348
    {
349
        // Non-Nullability of Join Column
350
        $this->assertFalse($class->associationMappings['groups']['joinTable']['joinColumns'][0]['nullable']);
351
        $this->assertFalse($class->associationMappings['groups']['joinTable']['joinColumns'][0]['unique']);
352
353
        return $class;
354
    }
355
356
    /**
357
     * @depends testJoinColumnUniqueAndNullable
358
     * @param ClassMetadata $class
359
     */
360
    public function testColumnDefinition($class)
361
    {
362
        $this->assertEquals("CHAR(32) NOT NULL", $class->fieldMappings['email']['columnDefinition']);
363
        $this->assertEquals("INT NULL", $class->associationMappings['groups']['joinTable']['inverseJoinColumns'][0]['columnDefinition']);
364
365
        return $class;
366
    }
367
368
    /**
369
     * @depends testColumnDefinition
370
     * @param ClassMetadata $class
371
     */
372
    public function testJoinColumnOnDelete($class)
373
    {
374
        $this->assertEquals('CASCADE', $class->associationMappings['address']['joinColumns'][0]['onDelete']);
375
376
        return $class;
377
    }
378
379
    /**
380
     * @group DDC-514
381
     */
382
    public function testDiscriminatorColumnDefaults()
383
    {
384
        if (strpos(get_class($this), 'PHPMappingDriver') !== false) {
385
            $this->markTestSkipped('PHP Mapping Drivers have no defaults.');
386
        }
387
388
        $class = $this->createClassMetadata('Doctrine\Tests\ORM\Mapping\Animal');
389
390
        $this->assertEquals(
391
            array('name' => 'discr', 'type' => 'string', 'length' => '32', 'fieldName' => 'discr', 'columnDefinition' => null),
392
            $class->discriminatorColumn
393
        );
394
    }
395
396
    /**
397
     * @group DDC-869
398
     */
399
    public function testMappedSuperclassWithRepository()
400
    {
401
        $em         = $this->_getTestEntityManager();
402
        $factory    = $this->createClassMetadataFactory($em);
403
404
405
        $class = $factory->getMetadataFor('Doctrine\Tests\Models\DDC869\DDC869CreditCardPayment');
406
407
        $this->assertTrue(isset($class->fieldMappings['id']));
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
408
        $this->assertTrue(isset($class->fieldMappings['value']));
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
409
        $this->assertTrue(isset($class->fieldMappings['creditCardNumber']));
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
410
        $this->assertEquals($class->customRepositoryClassName, "Doctrine\Tests\Models\DDC869\DDC869PaymentRepository");
0 ignored issues
show
Bug introduced by
Accessing customRepositoryClassName on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
411
        $this->assertInstanceOf("Doctrine\Tests\Models\DDC869\DDC869PaymentRepository",
412
             $em->getRepository("Doctrine\Tests\Models\DDC869\DDC869CreditCardPayment"));
413
        $this->assertTrue($em->getRepository("Doctrine\Tests\Models\DDC869\DDC869ChequePayment")->isTrue());
0 ignored issues
show
Documentation Bug introduced by
The method isTrue does not exist on object<Doctrine\ORM\EntityRepository>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
414
415
416
417
        $class = $factory->getMetadataFor('Doctrine\Tests\Models\DDC869\DDC869ChequePayment');
418
419
        $this->assertTrue(isset($class->fieldMappings['id']));
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
420
        $this->assertTrue(isset($class->fieldMappings['value']));
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
421
        $this->assertTrue(isset($class->fieldMappings['serialNumber']));
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
422
        $this->assertEquals($class->customRepositoryClassName, "Doctrine\Tests\Models\DDC869\DDC869PaymentRepository");
0 ignored issues
show
Bug introduced by
Accessing customRepositoryClassName on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
423
        $this->assertInstanceOf("Doctrine\Tests\Models\DDC869\DDC869PaymentRepository",
424
             $em->getRepository("Doctrine\Tests\Models\DDC869\DDC869ChequePayment"));
425
        $this->assertTrue($em->getRepository("Doctrine\Tests\Models\DDC869\DDC869ChequePayment")->isTrue());
0 ignored issues
show
Documentation Bug introduced by
The method isTrue does not exist on object<Doctrine\ORM\EntityRepository>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
426
    }
427
428
    /**
429
     * @group DDC-1476
430
     */
431
    public function testDefaultFieldType()
432
    {
433
        $factory    = $this->createClassMetadataFactory();
434
        $class      = $factory->getMetadataFor('Doctrine\Tests\Models\DDC1476\DDC1476EntityWithDefaultFieldType');
435
436
437
        $this->assertArrayHasKey('id', $class->fieldMappings);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
438
        $this->assertArrayHasKey('name', $class->fieldMappings);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
439
440
441
        $this->assertArrayHasKey('type', $class->fieldMappings['id']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
442
        $this->assertArrayHasKey('type', $class->fieldMappings['name']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
443
444
        $this->assertEquals('string', $class->fieldMappings['id']['type']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
445
        $this->assertEquals('string', $class->fieldMappings['name']['type']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
446
447
448
449
        $this->assertArrayHasKey('fieldName', $class->fieldMappings['id']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
450
        $this->assertArrayHasKey('fieldName', $class->fieldMappings['name']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
451
452
        $this->assertEquals('id', $class->fieldMappings['id']['fieldName']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
453
        $this->assertEquals('name', $class->fieldMappings['name']['fieldName']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
454
455
456
457
        $this->assertArrayHasKey('columnName', $class->fieldMappings['id']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
458
        $this->assertArrayHasKey('columnName', $class->fieldMappings['name']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
459
460
        $this->assertEquals('id', $class->fieldMappings['id']['columnName']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
461
        $this->assertEquals('name', $class->fieldMappings['name']['columnName']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
462
463
        $this->assertEquals(ClassMetadataInfo::GENERATOR_TYPE_NONE, $class->generatorType);
0 ignored issues
show
Bug introduced by
Accessing generatorType on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
464
    }
465
466
    /**
467
     * @group DDC-1170
468
     */
469
    public function testIdentifierColumnDefinition()
470
    {
471
        $class = $this->createClassMetadata(__NAMESPACE__ . '\DDC1170Entity');
472
473
474
        $this->assertArrayHasKey('id', $class->fieldMappings);
475
        $this->assertArrayHasKey('value', $class->fieldMappings);
476
477
        $this->assertArrayHasKey('columnDefinition', $class->fieldMappings['id']);
478
        $this->assertArrayHasKey('columnDefinition', $class->fieldMappings['value']);
479
480
        $this->assertEquals("INT unsigned NOT NULL", $class->fieldMappings['id']['columnDefinition']);
481
        $this->assertEquals("VARCHAR(255) NOT NULL", $class->fieldMappings['value']['columnDefinition']);
482
    }
483
484
    /**
485
     * @group DDC-559
486
     */
487
    public function testNamingStrategy()
488
    {
489
        $em         = $this->_getTestEntityManager();
490
        $factory    = $this->createClassMetadataFactory($em);
491
492
493
        $this->assertInstanceOf('Doctrine\ORM\Mapping\DefaultNamingStrategy', $em->getConfiguration()->getNamingStrategy());
494
        $em->getConfiguration()->setNamingStrategy(new UnderscoreNamingStrategy(CASE_UPPER));
495
        $this->assertInstanceOf('Doctrine\ORM\Mapping\UnderscoreNamingStrategy', $em->getConfiguration()->getNamingStrategy());
496
497
        $class = $factory->getMetadataFor('Doctrine\Tests\Models\DDC1476\DDC1476EntityWithDefaultFieldType');
498
499
        $this->assertEquals('ID', $class->getColumnName('id'));
500
        $this->assertEquals('NAME', $class->getColumnName('name'));
501
        $this->assertEquals('DDC1476ENTITY_WITH_DEFAULT_FIELD_TYPE', $class->table['name']);
0 ignored issues
show
Bug introduced by
Accessing table on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
502
    }
503
504
    /**
505
     * @group DDC-807
506
     * @group DDC-553
507
     */
508
    public function testDiscriminatorColumnDefinition()
509
    {
510
        $class = $this->createClassMetadata(__NAMESPACE__ . '\DDC807Entity');
511
512
        $this->assertArrayHasKey('columnDefinition', $class->discriminatorColumn);
513
        $this->assertArrayHasKey('name', $class->discriminatorColumn);
514
515
        $this->assertEquals("ENUM('ONE','TWO')", $class->discriminatorColumn['columnDefinition']);
516
        $this->assertEquals("dtype", $class->discriminatorColumn['name']);
517
    }
518
519
    /**
520
     * @group DDC-889
521
     */
522
    public function testInvalidEntityOrMappedSuperClassShouldMentionParentClasses()
523
    {
524
        $this->expectException(MappingException::class);
525
        $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.');
526
527
        $this->createClassMetadata('Doctrine\Tests\Models\DDC889\DDC889Class');
528
    }
529
530
    /**
531
     * @group DDC-889
532
     */
533
    public function testIdentifierRequiredShouldMentionParentClasses()
534
    {
535
        $factory = $this->createClassMetadataFactory();
536
537
        $this->expectException(MappingException::class);
538
        $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.');
539
540
        $factory->getMetadataFor('Doctrine\Tests\Models\DDC889\DDC889Entity');
541
    }
542
543
    public function testNamedQuery()
544
    {
545
        $driver = $this->_loadDriver();
546
        $class = $this->createClassMetadata(__NAMESPACE__.'\User');
547
548
        $this->assertCount(1, $class->getNamedQueries(), sprintf("Named queries not processed correctly by driver %s", get_class($driver)));
549
    }
550
551
    /**
552
     * @group DDC-1663
553
     */
554
    public function testNamedNativeQuery()
555
    {
556
557
        $class = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress');
558
559
        //named native query
560
        $this->assertCount(3, $class->namedNativeQueries);
561
        $this->assertArrayHasKey('find-all', $class->namedNativeQueries);
562
        $this->assertArrayHasKey('find-by-id', $class->namedNativeQueries);
563
564
565
        $findAllQuery = $class->getNamedNativeQuery('find-all');
566
        $this->assertEquals('find-all', $findAllQuery['name']);
567
        $this->assertEquals('mapping-find-all', $findAllQuery['resultSetMapping']);
568
        $this->assertEquals('SELECT id, country, city FROM cms_addresses', $findAllQuery['query']);
569
570
        $findByIdQuery = $class->getNamedNativeQuery('find-by-id');
571
        $this->assertEquals('find-by-id', $findByIdQuery['name']);
572
        $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddress',$findByIdQuery['resultClass']);
573
        $this->assertEquals('SELECT * FROM cms_addresses WHERE id = ?',  $findByIdQuery['query']);
574
575
        $countQuery = $class->getNamedNativeQuery('count');
576
        $this->assertEquals('count', $countQuery['name']);
577
        $this->assertEquals('mapping-count', $countQuery['resultSetMapping']);
578
        $this->assertEquals('SELECT COUNT(*) AS count FROM cms_addresses',  $countQuery['query']);
579
580
        // result set mapping
581
        $this->assertCount(3, $class->sqlResultSetMappings);
582
        $this->assertArrayHasKey('mapping-count', $class->sqlResultSetMappings);
583
        $this->assertArrayHasKey('mapping-find-all', $class->sqlResultSetMappings);
584
        $this->assertArrayHasKey('mapping-without-fields', $class->sqlResultSetMappings);
585
586
        $findAllMapping = $class->getSqlResultSetMapping('mapping-find-all');
587
        $this->assertEquals('mapping-find-all', $findAllMapping['name']);
588
        $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddress', $findAllMapping['entities'][0]['entityClass']);
589
        $this->assertEquals(array('name'=>'id','column'=>'id'), $findAllMapping['entities'][0]['fields'][0]);
590
        $this->assertEquals(array('name'=>'city','column'=>'city'), $findAllMapping['entities'][0]['fields'][1]);
591
        $this->assertEquals(array('name'=>'country','column'=>'country'), $findAllMapping['entities'][0]['fields'][2]);
592
593
        $withoutFieldsMapping = $class->getSqlResultSetMapping('mapping-without-fields');
594
        $this->assertEquals('mapping-without-fields', $withoutFieldsMapping['name']);
595
        $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddress', $withoutFieldsMapping['entities'][0]['entityClass']);
596
        $this->assertEquals(array(), $withoutFieldsMapping['entities'][0]['fields']);
597
598
        $countMapping = $class->getSqlResultSetMapping('mapping-count');
599
        $this->assertEquals('mapping-count', $countMapping['name']);
600
        $this->assertEquals(array('name'=>'count'), $countMapping['columns'][0]);
601
602
    }
603
604
    /**
605
     * @group DDC-1663
606
     */
607
    public function testSqlResultSetMapping()
608
    {
609
610
        $userMetadata   = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');
611
        $personMetadata = $this->createClassMetadata('Doctrine\Tests\Models\Company\CompanyPerson');
612
613
        // user asserts
614
        $this->assertCount(4, $userMetadata->getSqlResultSetMappings());
615
616
        $mapping = $userMetadata->getSqlResultSetMapping('mappingJoinedAddress');
617
        $this->assertEquals(array(),$mapping['columns']);
618
        $this->assertEquals('mappingJoinedAddress', $mapping['name']);
619
        $this->assertNull($mapping['entities'][0]['discriminatorColumn']);
620
        $this->assertEquals(array('name'=>'id','column'=>'id'),                     $mapping['entities'][0]['fields'][0]);
621
        $this->assertEquals(array('name'=>'name','column'=>'name'),                 $mapping['entities'][0]['fields'][1]);
622
        $this->assertEquals(array('name'=>'status','column'=>'status'),             $mapping['entities'][0]['fields'][2]);
623
        $this->assertEquals(array('name'=>'address.zip','column'=>'zip'),           $mapping['entities'][0]['fields'][3]);
624
        $this->assertEquals(array('name'=>'address.city','column'=>'city'),         $mapping['entities'][0]['fields'][4]);
625
        $this->assertEquals(array('name'=>'address.country','column'=>'country'),   $mapping['entities'][0]['fields'][5]);
626
        $this->assertEquals(array('name'=>'address.id','column'=>'a_id'),           $mapping['entities'][0]['fields'][6]);
627
        $this->assertEquals($userMetadata->name,                                    $mapping['entities'][0]['entityClass']);
628
629
630
        $mapping = $userMetadata->getSqlResultSetMapping('mappingJoinedPhonenumber');
631
        $this->assertEquals(array(),$mapping['columns']);
632
        $this->assertEquals('mappingJoinedPhonenumber', $mapping['name']);
633
        $this->assertNull($mapping['entities'][0]['discriminatorColumn']);
634
        $this->assertEquals(array('name'=>'id','column'=>'id'),                             $mapping['entities'][0]['fields'][0]);
635
        $this->assertEquals(array('name'=>'name','column'=>'name'),                         $mapping['entities'][0]['fields'][1]);
636
        $this->assertEquals(array('name'=>'status','column'=>'status'),                     $mapping['entities'][0]['fields'][2]);
637
        $this->assertEquals(array('name'=>'phonenumbers.phonenumber','column'=>'number'),   $mapping['entities'][0]['fields'][3]);
638
        $this->assertEquals($userMetadata->name,                                            $mapping['entities'][0]['entityClass']);
639
640
        $mapping = $userMetadata->getSqlResultSetMapping('mappingUserPhonenumberCount');
641
        $this->assertEquals(array('name'=>'numphones'),$mapping['columns'][0]);
642
        $this->assertEquals('mappingUserPhonenumberCount', $mapping['name']);
643
        $this->assertNull($mapping['entities'][0]['discriminatorColumn']);
644
        $this->assertEquals(array('name'=>'id','column'=>'id'),         $mapping['entities'][0]['fields'][0]);
645
        $this->assertEquals(array('name'=>'name','column'=>'name'),     $mapping['entities'][0]['fields'][1]);
646
        $this->assertEquals(array('name'=>'status','column'=>'status'), $mapping['entities'][0]['fields'][2]);
647
        $this->assertEquals($userMetadata->name,                        $mapping['entities'][0]['entityClass']);
648
649
        $mapping = $userMetadata->getSqlResultSetMapping('mappingMultipleJoinsEntityResults');
650
        $this->assertEquals(array('name'=>'numphones'),$mapping['columns'][0]);
651
        $this->assertEquals('mappingMultipleJoinsEntityResults', $mapping['name']);
652
        $this->assertNull($mapping['entities'][0]['discriminatorColumn']);
653
        $this->assertEquals(array('name'=>'id','column'=>'u_id'),           $mapping['entities'][0]['fields'][0]);
654
        $this->assertEquals(array('name'=>'name','column'=>'u_name'),       $mapping['entities'][0]['fields'][1]);
655
        $this->assertEquals(array('name'=>'status','column'=>'u_status'),   $mapping['entities'][0]['fields'][2]);
656
        $this->assertEquals($userMetadata->name,                            $mapping['entities'][0]['entityClass']);
657
        $this->assertNull($mapping['entities'][1]['discriminatorColumn']);
658
        $this->assertEquals(array('name'=>'id','column'=>'a_id'),           $mapping['entities'][1]['fields'][0]);
659
        $this->assertEquals(array('name'=>'zip','column'=>'a_zip'),         $mapping['entities'][1]['fields'][1]);
660
        $this->assertEquals(array('name'=>'country','column'=>'a_country'), $mapping['entities'][1]['fields'][2]);
661
        $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddress',         $mapping['entities'][1]['entityClass']);
662
663
        //person asserts
664
        $this->assertCount(1, $personMetadata->getSqlResultSetMappings());
665
666
        $mapping = $personMetadata->getSqlResultSetMapping('mappingFetchAll');
667
        $this->assertEquals(array(),$mapping['columns']);
668
        $this->assertEquals('mappingFetchAll', $mapping['name']);
669
        $this->assertEquals('discriminator',                            $mapping['entities'][0]['discriminatorColumn']);
670
        $this->assertEquals(array('name'=>'id','column'=>'id'),         $mapping['entities'][0]['fields'][0]);
671
        $this->assertEquals(array('name'=>'name','column'=>'name'),     $mapping['entities'][0]['fields'][1]);
672
        $this->assertEquals($personMetadata->name,                      $mapping['entities'][0]['entityClass']);
673
    }
674
675
    /*
676
     * @group DDC-964
677
     */
678
    public function testAssociationOverridesMapping()
679
    {
680
681
        $factory        = $this->createClassMetadataFactory();
682
        $adminMetadata  = $factory->getMetadataFor('Doctrine\Tests\Models\DDC964\DDC964Admin');
683
        $guestMetadata  = $factory->getMetadataFor('Doctrine\Tests\Models\DDC964\DDC964Guest');
684
685
686
        // assert groups association mappings
687
        $this->assertArrayHasKey('groups', $guestMetadata->associationMappings);
0 ignored issues
show
Bug introduced by
Accessing associationMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
688
        $this->assertArrayHasKey('groups', $adminMetadata->associationMappings);
0 ignored issues
show
Bug introduced by
Accessing associationMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
689
690
        $guestGroups = $guestMetadata->associationMappings['groups'];
0 ignored issues
show
Bug introduced by
Accessing associationMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
691
        $adminGroups = $adminMetadata->associationMappings['groups'];
0 ignored issues
show
Bug introduced by
Accessing associationMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
692
693
        // assert not override attributes
694
        $this->assertEquals($guestGroups['fieldName'], $adminGroups['fieldName']);
695
        $this->assertEquals($guestGroups['type'], $adminGroups['type']);
696
        $this->assertEquals($guestGroups['mappedBy'], $adminGroups['mappedBy']);
697
        $this->assertEquals($guestGroups['inversedBy'], $adminGroups['inversedBy']);
698
        $this->assertEquals($guestGroups['isOwningSide'], $adminGroups['isOwningSide']);
699
        $this->assertEquals($guestGroups['fetch'], $adminGroups['fetch']);
700
        $this->assertEquals($guestGroups['isCascadeRemove'], $adminGroups['isCascadeRemove']);
701
        $this->assertEquals($guestGroups['isCascadePersist'], $adminGroups['isCascadePersist']);
702
        $this->assertEquals($guestGroups['isCascadeRefresh'], $adminGroups['isCascadeRefresh']);
703
        $this->assertEquals($guestGroups['isCascadeMerge'], $adminGroups['isCascadeMerge']);
704
        $this->assertEquals($guestGroups['isCascadeDetach'], $adminGroups['isCascadeDetach']);
705
706
         // assert not override attributes
707
        $this->assertEquals('ddc964_users_groups', $guestGroups['joinTable']['name']);
708
        $this->assertEquals('user_id', $guestGroups['joinTable']['joinColumns'][0]['name']);
709
        $this->assertEquals('group_id', $guestGroups['joinTable']['inverseJoinColumns'][0]['name']);
710
711
        $this->assertEquals(array('user_id'=>'id'), $guestGroups['relationToSourceKeyColumns']);
712
        $this->assertEquals(array('group_id'=>'id'), $guestGroups['relationToTargetKeyColumns']);
713
        $this->assertEquals(array('user_id','group_id'), $guestGroups['joinTableColumns']);
714
715
716
        $this->assertEquals('ddc964_users_admingroups', $adminGroups['joinTable']['name']);
717
        $this->assertEquals('adminuser_id', $adminGroups['joinTable']['joinColumns'][0]['name']);
718
        $this->assertEquals('admingroup_id', $adminGroups['joinTable']['inverseJoinColumns'][0]['name']);
719
720
        $this->assertEquals(array('adminuser_id'=>'id'), $adminGroups['relationToSourceKeyColumns']);
721
        $this->assertEquals(array('admingroup_id'=>'id'), $adminGroups['relationToTargetKeyColumns']);
722
        $this->assertEquals(array('adminuser_id','admingroup_id'), $adminGroups['joinTableColumns']);
723
724
725
        // assert address association mappings
726
        $this->assertArrayHasKey('address', $guestMetadata->associationMappings);
0 ignored issues
show
Bug introduced by
Accessing associationMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
727
        $this->assertArrayHasKey('address', $adminMetadata->associationMappings);
0 ignored issues
show
Bug introduced by
Accessing associationMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
728
729
        $guestAddress = $guestMetadata->associationMappings['address'];
0 ignored issues
show
Bug introduced by
Accessing associationMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
730
        $adminAddress = $adminMetadata->associationMappings['address'];
0 ignored issues
show
Bug introduced by
Accessing associationMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
731
732
        // assert not override attributes
733
        $this->assertEquals($guestAddress['fieldName'], $adminAddress['fieldName']);
734
        $this->assertEquals($guestAddress['type'], $adminAddress['type']);
735
        $this->assertEquals($guestAddress['mappedBy'], $adminAddress['mappedBy']);
736
        $this->assertEquals($guestAddress['inversedBy'], $adminAddress['inversedBy']);
737
        $this->assertEquals($guestAddress['isOwningSide'], $adminAddress['isOwningSide']);
738
        $this->assertEquals($guestAddress['fetch'], $adminAddress['fetch']);
739
        $this->assertEquals($guestAddress['isCascadeRemove'], $adminAddress['isCascadeRemove']);
740
        $this->assertEquals($guestAddress['isCascadePersist'], $adminAddress['isCascadePersist']);
741
        $this->assertEquals($guestAddress['isCascadeRefresh'], $adminAddress['isCascadeRefresh']);
742
        $this->assertEquals($guestAddress['isCascadeMerge'], $adminAddress['isCascadeMerge']);
743
        $this->assertEquals($guestAddress['isCascadeDetach'], $adminAddress['isCascadeDetach']);
744
745
        // assert override
746
        $this->assertEquals('address_id', $guestAddress['joinColumns'][0]['name']);
747
        $this->assertEquals(array('address_id'=>'id'), $guestAddress['sourceToTargetKeyColumns']);
748
        $this->assertEquals(array('address_id'=>'address_id'), $guestAddress['joinColumnFieldNames']);
749
        $this->assertEquals(array('id'=>'address_id'), $guestAddress['targetToSourceKeyColumns']);
750
751
752
        $this->assertEquals('adminaddress_id', $adminAddress['joinColumns'][0]['name']);
753
        $this->assertEquals(array('adminaddress_id'=>'id'), $adminAddress['sourceToTargetKeyColumns']);
754
        $this->assertEquals(array('adminaddress_id'=>'adminaddress_id'), $adminAddress['joinColumnFieldNames']);
755
        $this->assertEquals(array('id'=>'adminaddress_id'), $adminAddress['targetToSourceKeyColumns']);
756
    }
757
758
    /*
759
     * @group DDC-3579
760
     */
761
    public function testInversedByOverrideMapping()
762
    {
763
764
        $factory        = $this->createClassMetadataFactory();
765
        $adminMetadata  = $factory->getMetadataFor('Doctrine\Tests\Models\DDC3579\DDC3579Admin');
766
767
        // assert groups association mappings
768
        $this->assertArrayHasKey('groups', $adminMetadata->associationMappings);
0 ignored issues
show
Bug introduced by
Accessing associationMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
769
        $adminGroups = $adminMetadata->associationMappings['groups'];
0 ignored issues
show
Bug introduced by
Accessing associationMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
770
771
        // assert override
772
        $this->assertEquals('admins', $adminGroups['inversedBy']);
773
    }
774
775
    /**
776
     * @group DDC-5934
777
     */
778
    public function testFetchOverrideMapping()
779
    {
780
        // check override metadata
781
        $contractMetadata = $this->createClassMetadataFactory()->getMetadataFor('Doctrine\Tests\Models\DDC5934\DDC5934Contract');
782
783
        $this->assertArrayHasKey('members', $contractMetadata->associationMappings);
0 ignored issues
show
Bug introduced by
Accessing associationMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
784
        $this->assertSame('EXTRA_LAZY', $contractMetadata->associationMappings['members']['fetch']);
0 ignored issues
show
Bug introduced by
Accessing associationMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
785
    }
786
787
    /**
788
     * @group DDC-964
789
     */
790
    public function testAttributeOverridesMapping()
791
    {
792
793
        $factory       = $this->createClassMetadataFactory();
794
        $guestMetadata = $factory->getMetadataFor('Doctrine\Tests\Models\DDC964\DDC964Guest');
795
        $adminMetadata = $factory->getMetadataFor('Doctrine\Tests\Models\DDC964\DDC964Admin');
796
797
        $this->assertTrue($adminMetadata->fieldMappings['id']['id']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
798
        $this->assertEquals('id', $adminMetadata->fieldMappings['id']['fieldName']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
799
        $this->assertEquals('user_id', $adminMetadata->fieldMappings['id']['columnName']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
800
        $this->assertEquals(array('user_id'=>'id','user_name'=>'name'), $adminMetadata->fieldNames);
0 ignored issues
show
Bug introduced by
Accessing fieldNames on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
801
        $this->assertEquals(array('id'=>'user_id','name'=>'user_name'), $adminMetadata->columnNames);
0 ignored issues
show
Bug introduced by
Accessing columnNames on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
802
        $this->assertEquals(150, $adminMetadata->fieldMappings['id']['length']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
803
804
805
        $this->assertEquals('name', $adminMetadata->fieldMappings['name']['fieldName']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
806
        $this->assertEquals('user_name', $adminMetadata->fieldMappings['name']['columnName']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
807
        $this->assertEquals(250, $adminMetadata->fieldMappings['name']['length']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
808
        $this->assertTrue($adminMetadata->fieldMappings['name']['nullable']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
809
        $this->assertFalse($adminMetadata->fieldMappings['name']['unique']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
810
811
812
        $this->assertTrue($guestMetadata->fieldMappings['id']['id']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
813
        $this->assertEquals('guest_id', $guestMetadata->fieldMappings['id']['columnName']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
814
        $this->assertEquals('id', $guestMetadata->fieldMappings['id']['fieldName']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
815
        $this->assertEquals(array('guest_id'=>'id','guest_name'=>'name'), $guestMetadata->fieldNames);
0 ignored issues
show
Bug introduced by
Accessing fieldNames on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
816
        $this->assertEquals(array('id'=>'guest_id','name'=>'guest_name'), $guestMetadata->columnNames);
0 ignored issues
show
Bug introduced by
Accessing columnNames on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
817
        $this->assertEquals(140, $guestMetadata->fieldMappings['id']['length']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
818
819
        $this->assertEquals('name', $guestMetadata->fieldMappings['name']['fieldName']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
820
        $this->assertEquals('guest_name', $guestMetadata->fieldMappings['name']['columnName']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
821
        $this->assertEquals(240, $guestMetadata->fieldMappings['name']['length']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
822
        $this->assertFalse($guestMetadata->fieldMappings['name']['nullable']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
823
        $this->assertTrue($guestMetadata->fieldMappings['name']['unique']);
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
824
    }
825
826
    /**
827
     * @group DDC-1955
828
     */
829
    public function testEntityListeners()
830
    {
831
        $em         = $this->_getTestEntityManager();
832
        $factory    = $this->createClassMetadataFactory($em);
833
        $superClass = $factory->getMetadataFor('Doctrine\Tests\Models\Company\CompanyContract');
834
        $flexClass  = $factory->getMetadataFor('Doctrine\Tests\Models\Company\CompanyFixContract');
835
        $fixClass   = $factory->getMetadataFor('Doctrine\Tests\Models\Company\CompanyFlexContract');
836
        $ultraClass = $factory->getMetadataFor('Doctrine\Tests\Models\Company\CompanyFlexUltraContract');
0 ignored issues
show
Unused Code introduced by
$ultraClass is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
837
838
        $this->assertArrayHasKey(Events::prePersist, $superClass->entityListeners);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
839
        $this->assertArrayHasKey(Events::postPersist, $superClass->entityListeners);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
840
841
        $this->assertCount(1, $superClass->entityListeners[Events::prePersist]);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
842
        $this->assertCount(1, $superClass->entityListeners[Events::postPersist]);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
843
844
        $postPersist = $superClass->entityListeners[Events::postPersist][0];
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
845
        $prePersist  = $superClass->entityListeners[Events::prePersist][0];
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
846
847
        $this->assertEquals('Doctrine\Tests\Models\Company\CompanyContractListener', $postPersist['class']);
848
        $this->assertEquals('Doctrine\Tests\Models\Company\CompanyContractListener', $prePersist['class']);
849
        $this->assertEquals('postPersistHandler', $postPersist['method']);
850
        $this->assertEquals('prePersistHandler', $prePersist['method']);
851
852
        //Inherited listeners
853
        $this->assertEquals($fixClass->entityListeners, $superClass->entityListeners);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
854
        $this->assertEquals($flexClass->entityListeners, $superClass->entityListeners);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
855
    }
856
857
    /**
858
     * @group DDC-1955
859
     */
860
    public function testEntityListenersOverride()
861
    {
862
        $em         = $this->_getTestEntityManager();
863
        $factory    = $this->createClassMetadataFactory($em);
864
        $ultraClass = $factory->getMetadataFor('Doctrine\Tests\Models\Company\CompanyFlexUltraContract');
865
866
        //overridden listeners
867
        $this->assertArrayHasKey(Events::postPersist, $ultraClass->entityListeners);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
868
        $this->assertArrayHasKey(Events::prePersist, $ultraClass->entityListeners);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
869
870
        $this->assertCount(1, $ultraClass->entityListeners[Events::postPersist]);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
871
        $this->assertCount(3, $ultraClass->entityListeners[Events::prePersist]);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
872
873
        $postPersist = $ultraClass->entityListeners[Events::postPersist][0];
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
874
        $prePersist  = $ultraClass->entityListeners[Events::prePersist][0];
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
875
876
        $this->assertEquals('Doctrine\Tests\Models\Company\CompanyContractListener', $postPersist['class']);
877
        $this->assertEquals('Doctrine\Tests\Models\Company\CompanyContractListener', $prePersist['class']);
878
        $this->assertEquals('postPersistHandler', $postPersist['method']);
879
        $this->assertEquals('prePersistHandler', $prePersist['method']);
880
881
        $prePersist = $ultraClass->entityListeners[Events::prePersist][1];
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
882
        $this->assertEquals('Doctrine\Tests\Models\Company\CompanyFlexUltraContractListener', $prePersist['class']);
883
        $this->assertEquals('prePersistHandler1', $prePersist['method']);
884
885
        $prePersist = $ultraClass->entityListeners[Events::prePersist][2];
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
886
        $this->assertEquals('Doctrine\Tests\Models\Company\CompanyFlexUltraContractListener', $prePersist['class']);
887
        $this->assertEquals('prePersistHandler2', $prePersist['method']);
888
    }
889
890
891
    /**
892
     * @group DDC-1955
893
     */
894
    public function testEntityListenersNamingConvention()
895
    {
896
        $em         = $this->_getTestEntityManager();
897
        $factory    = $this->createClassMetadataFactory($em);
898
        $metadata   = $factory->getMetadataFor('Doctrine\Tests\Models\CMS\CmsAddress');
899
900
        $this->assertArrayHasKey(Events::postPersist, $metadata->entityListeners);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
901
        $this->assertArrayHasKey(Events::prePersist, $metadata->entityListeners);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
902
        $this->assertArrayHasKey(Events::postUpdate, $metadata->entityListeners);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
903
        $this->assertArrayHasKey(Events::preUpdate, $metadata->entityListeners);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
904
        $this->assertArrayHasKey(Events::postRemove, $metadata->entityListeners);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
905
        $this->assertArrayHasKey(Events::preRemove, $metadata->entityListeners);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
906
        $this->assertArrayHasKey(Events::postLoad, $metadata->entityListeners);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
907
        $this->assertArrayHasKey(Events::preFlush, $metadata->entityListeners);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
908
909
        $this->assertCount(1, $metadata->entityListeners[Events::postPersist]);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
910
        $this->assertCount(1, $metadata->entityListeners[Events::prePersist]);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
911
        $this->assertCount(1, $metadata->entityListeners[Events::postUpdate]);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
912
        $this->assertCount(1, $metadata->entityListeners[Events::preUpdate]);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
913
        $this->assertCount(1, $metadata->entityListeners[Events::postRemove]);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
914
        $this->assertCount(1, $metadata->entityListeners[Events::preRemove]);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
915
        $this->assertCount(1, $metadata->entityListeners[Events::postLoad]);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
916
        $this->assertCount(1, $metadata->entityListeners[Events::preFlush]);
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
917
918
        $postPersist = $metadata->entityListeners[Events::postPersist][0];
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
919
        $prePersist  = $metadata->entityListeners[Events::prePersist][0];
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
920
        $postUpdate  = $metadata->entityListeners[Events::postUpdate][0];
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
921
        $preUpdate   = $metadata->entityListeners[Events::preUpdate][0];
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
922
        $postRemove  = $metadata->entityListeners[Events::postRemove][0];
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
923
        $preRemove   = $metadata->entityListeners[Events::preRemove][0];
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
924
        $postLoad    = $metadata->entityListeners[Events::postLoad][0];
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
925
        $preFlush    = $metadata->entityListeners[Events::preFlush][0];
0 ignored issues
show
Bug introduced by
Accessing entityListeners on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
926
927
928
        $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddressListener', $postPersist['class']);
929
        $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddressListener', $prePersist['class']);
930
        $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddressListener', $postUpdate['class']);
931
        $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddressListener', $preUpdate['class']);
932
        $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddressListener', $postRemove['class']);
933
        $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddressListener', $preRemove['class']);
934
        $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddressListener', $postLoad['class']);
935
        $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddressListener', $preFlush['class']);
936
937
        $this->assertEquals(Events::postPersist, $postPersist['method']);
938
        $this->assertEquals(Events::prePersist, $prePersist['method']);
939
        $this->assertEquals(Events::postUpdate, $postUpdate['method']);
940
        $this->assertEquals(Events::preUpdate, $preUpdate['method']);
941
        $this->assertEquals(Events::postRemove, $postRemove['method']);
942
        $this->assertEquals(Events::preRemove, $preRemove['method']);
943
        $this->assertEquals(Events::postLoad, $postLoad['method']);
944
        $this->assertEquals(Events::preFlush, $preFlush['method']);
945
    }
946
947
    /**
948
     * @group DDC-2183
949
     */
950
    public function testSecondLevelCacheMapping()
951
    {
952
        $em      = $this->_getTestEntityManager();
953
        $factory = $this->createClassMetadataFactory($em);
954
        $class   = $factory->getMetadataFor(City::CLASSNAME);
955
        $this->assertArrayHasKey('usage', $class->cache);
0 ignored issues
show
Bug introduced by
Accessing cache on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
956
        $this->assertArrayHasKey('region', $class->cache);
0 ignored issues
show
Bug introduced by
Accessing cache on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
957
        $this->assertEquals(ClassMetadata::CACHE_USAGE_READ_ONLY, $class->cache['usage']);
0 ignored issues
show
Bug introduced by
Accessing cache on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
958
        $this->assertEquals('doctrine_tests_models_cache_city', $class->cache['region']);
0 ignored issues
show
Bug introduced by
Accessing cache on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
959
960
        $this->assertArrayHasKey('state', $class->associationMappings);
0 ignored issues
show
Bug introduced by
Accessing associationMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
961
        $this->assertArrayHasKey('cache', $class->associationMappings['state']);
0 ignored issues
show
Bug introduced by
Accessing associationMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
962
        $this->assertArrayHasKey('usage', $class->associationMappings['state']['cache']);
0 ignored issues
show
Bug introduced by
Accessing associationMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
963
        $this->assertArrayHasKey('region', $class->associationMappings['state']['cache']);
0 ignored issues
show
Bug introduced by
Accessing associationMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
964
        $this->assertEquals(ClassMetadata::CACHE_USAGE_READ_ONLY, $class->associationMappings['state']['cache']['usage']);
0 ignored issues
show
Bug introduced by
Accessing associationMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
965
        $this->assertEquals('doctrine_tests_models_cache_city__state', $class->associationMappings['state']['cache']['region']);
0 ignored issues
show
Bug introduced by
Accessing associationMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
966
967
        $this->assertArrayHasKey('attractions', $class->associationMappings);
0 ignored issues
show
Bug introduced by
Accessing associationMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
968
        $this->assertArrayHasKey('cache', $class->associationMappings['attractions']);
0 ignored issues
show
Bug introduced by
Accessing associationMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
969
        $this->assertArrayHasKey('usage', $class->associationMappings['attractions']['cache']);
0 ignored issues
show
Bug introduced by
Accessing associationMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
970
        $this->assertArrayHasKey('region', $class->associationMappings['attractions']['cache']);
0 ignored issues
show
Bug introduced by
Accessing associationMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
971
        $this->assertEquals(ClassMetadata::CACHE_USAGE_READ_ONLY, $class->associationMappings['attractions']['cache']['usage']);
0 ignored issues
show
Bug introduced by
Accessing associationMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
972
        $this->assertEquals('doctrine_tests_models_cache_city__attractions', $class->associationMappings['attractions']['cache']['region']);
0 ignored issues
show
Bug introduced by
Accessing associationMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
973
    }
974
975
    /**
976
     * @group DDC-2825
977
     * @group 881
978
     */
979
    public function testSchemaDefinitionViaExplicitTableSchemaAnnotationProperty()
980
    {
981
        /* @var $metadata \Doctrine\ORM\Mapping\ClassMetadata */
982
        $metadata = $this->createClassMetadataFactory()->getMetadataFor(ExplicitSchemaAndTable::CLASSNAME);
983
984
        $this->assertSame('explicit_schema', $metadata->getSchemaName());
985
        $this->assertSame('explicit_table', $metadata->getTableName());
986
    }
987
988
    /**
989
     * @group DDC-2825
990
     * @group 881
991
     */
992
    public function testSchemaDefinitionViaSchemaDefinedInTableNameInTableAnnotationProperty()
993
    {
994
        /* @var $metadata \Doctrine\ORM\Mapping\ClassMetadata */
995
        $metadata = $this->createClassMetadataFactory()->getMetadataFor(SchemaAndTableInTableName::CLASSNAME);
996
997
        $this->assertSame('implicit_schema', $metadata->getSchemaName());
998
        $this->assertSame('implicit_table', $metadata->getTableName());
999
    }
1000
1001
    /**
1002
     * @group DDC-514
1003
     * @group DDC-1015
1004
     */
1005
    public function testDiscriminatorColumnDefaultLength()
1006
    {
1007
        if (strpos(get_class($this), 'PHPMappingDriver') !== false) {
1008
            $this->markTestSkipped('PHP Mapping Drivers have no defaults.');
1009
        }
1010
        $class = $this->createClassMetadata(__NAMESPACE__ . '\SingleTableEntityNoDiscriminatorColumnMapping');
1011
        $this->assertEquals(255, $class->discriminatorColumn['length']);
1012
        $class = $this->createClassMetadata(__NAMESPACE__ . '\SingleTableEntityIncompleteDiscriminatorColumnMapping');
1013
        $this->assertEquals(255, $class->discriminatorColumn['length']);
1014
    }
1015
1016
    /**
1017
     * @group DDC-514
1018
     * @group DDC-1015
1019
     */
1020
    public function testDiscriminatorColumnDefaultType()
1021
    {
1022
        if (strpos(get_class($this), 'PHPMappingDriver') !== false) {
1023
            $this->markTestSkipped('PHP Mapping Drivers have no defaults.');
1024
        }
1025
        $class = $this->createClassMetadata(__NAMESPACE__ . '\SingleTableEntityNoDiscriminatorColumnMapping');
1026
        $this->assertEquals('string', $class->discriminatorColumn['type']);
1027
        $class = $this->createClassMetadata(__NAMESPACE__ . '\SingleTableEntityIncompleteDiscriminatorColumnMapping');
1028
        $this->assertEquals('string', $class->discriminatorColumn['type']);
1029
    }
1030
1031
    /**
1032
     * @group DDC-514
1033
     * @group DDC-1015
1034
     */
1035
    public function testDiscriminatorColumnDefaultName()
1036
    {
1037
        if (strpos(get_class($this), 'PHPMappingDriver') !== false) {
1038
            $this->markTestSkipped('PHP Mapping Drivers have no defaults.');
1039
        }
1040
        $class = $this->createClassMetadata(__NAMESPACE__ . '\SingleTableEntityNoDiscriminatorColumnMapping');
1041
        $this->assertEquals('dtype', $class->discriminatorColumn['name']);
1042
        $class = $this->createClassMetadata(__NAMESPACE__ . '\SingleTableEntityIncompleteDiscriminatorColumnMapping');
1043
        $this->assertEquals('dtype', $class->discriminatorColumn['name']);
1044
    }
1045
1046
}
1047
1048
/**
1049
 * @Entity
1050
 * @HasLifecycleCallbacks
1051
 * @Table(
1052
 *  name="cms_users",
1053
 *  uniqueConstraints={@UniqueConstraint(name="search_idx", columns={"name", "user_email"}, options={"where": "name IS NOT NULL"})},
1054
 *  indexes={@Index(name="name_idx", columns={"name"}), @Index(name="0", columns={"user_email"})},
1055
 *  options={"foo": "bar", "baz": {"key": "val"}}
1056
 * )
1057
 * @NamedQueries({@NamedQuery(name="all", query="SELECT u FROM __CLASS__ u")})
1058
 */
1059
class User
1060
{
1061
    /**
1062
     * @Id
1063
     * @Column(type="integer", options={"foo": "bar"})
1064
     * @generatedValue(strategy="AUTO")
1065
     * @SequenceGenerator(sequenceName="tablename_seq", initialValue=1, allocationSize=100)
1066
     **/
1067
    public $id;
1068
1069
    /**
1070
     * @Column(length=50, nullable=true, unique=true, options={"foo": "bar", "baz": {"key": "val"}})
1071
     */
1072
    public $name;
1073
1074
    /**
1075
     * @Column(name="user_email", columnDefinition="CHAR(32) NOT NULL")
1076
     */
1077
    public $email;
1078
1079
    /**
1080
     * @OneToOne(targetEntity="Address", cascade={"remove"}, inversedBy="user")
1081
     * @JoinColumn(onDelete="CASCADE")
1082
     */
1083
    public $address;
1084
1085
    /**
1086
     * @OneToMany(targetEntity="Phonenumber", mappedBy="user", cascade={"persist"}, orphanRemoval=true)
1087
     * @OrderBy({"number"="ASC"})
1088
     */
1089
    public $phonenumbers;
1090
1091
    /**
1092
     * @ManyToMany(targetEntity="Group", cascade={"all"})
1093
     * @JoinTable(name="cms_user_groups",
1094
     *    joinColumns={@JoinColumn(name="user_id", referencedColumnName="id", nullable=false, unique=false)},
1095
     *    inverseJoinColumns={@JoinColumn(name="group_id", referencedColumnName="id", columnDefinition="INT NULL")}
1096
     * )
1097
     */
1098
    public $groups;
1099
1100
    /**
1101
     * @Column(type="integer")
1102
     * @Version
1103
     */
1104
    public $version;
1105
1106
1107
    /**
1108
     * @PrePersist
1109
     */
1110
    public function doStuffOnPrePersist()
1111
    {
1112
    }
1113
1114
    /**
1115
     * @PrePersist
1116
     */
1117
    public function doOtherStuffOnPrePersistToo() {
1118
    }
1119
1120
    /**
1121
     * @PostPersist
1122
     */
1123
    public function doStuffOnPostPersist()
1124
    {
1125
1126
    }
1127
1128
    public static function loadMetadata(ClassMetadataInfo $metadata)
1129
    {
1130
        $metadata->setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_NONE);
1131
        $metadata->setPrimaryTable(array(
1132
           'name' => 'cms_users',
1133
           'options' => array('foo' => 'bar', 'baz' => array('key' => 'val')),
1134
          ));
1135
        $metadata->setChangeTrackingPolicy(ClassMetadataInfo::CHANGETRACKING_DEFERRED_IMPLICIT);
1136
        $metadata->addLifecycleCallback('doStuffOnPrePersist', 'prePersist');
1137
        $metadata->addLifecycleCallback('doOtherStuffOnPrePersistToo', 'prePersist');
1138
        $metadata->addLifecycleCallback('doStuffOnPostPersist', 'postPersist');
1139
        $metadata->mapField(array(
1140
           'id' => true,
1141
           'fieldName' => 'id',
1142
           'type' => 'integer',
1143
           'columnName' => 'id',
1144
           'options' => array('foo' => 'bar'),
1145
          ));
1146
        $metadata->mapField(array(
1147
           'fieldName' => 'name',
1148
           'type' => 'string',
1149
           'length' => 50,
1150
           'unique' => true,
1151
           'nullable' => true,
1152
           'columnName' => 'name',
1153
           'options' => array('foo' => 'bar', 'baz' => array('key' => 'val')),
1154
          ));
1155
        $metadata->mapField(array(
1156
           'fieldName' => 'email',
1157
           'type' => 'string',
1158
           'columnName' => 'user_email',
1159
           'columnDefinition' => 'CHAR(32) NOT NULL',
1160
          ));
1161
        $mapping = array('fieldName' => 'version', 'type' => 'integer');
1162
        $metadata->setVersionMapping($mapping);
1163
        $metadata->mapField($mapping);
1164
        $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO);
1165
        $metadata->mapOneToOne(array(
1166
           'fieldName' => 'address',
1167
           'targetEntity' => 'Doctrine\\Tests\\ORM\\Mapping\\Address',
1168
           'cascade' =>
1169
           array(
1170
           0 => 'remove',
1171
           ),
1172
           'mappedBy' => NULL,
1173
           'inversedBy' => 'user',
1174
           'joinColumns' =>
1175
           array(
1176
           0 =>
1177
           array(
1178
            'name' => 'address_id',
1179
            'referencedColumnName' => 'id',
1180
            'onDelete' => 'CASCADE',
1181
           ),
1182
           ),
1183
           'orphanRemoval' => false,
1184
          ));
1185
        $metadata->mapOneToMany(array(
1186
           'fieldName' => 'phonenumbers',
1187
           'targetEntity' => 'Doctrine\\Tests\\ORM\\Mapping\\Phonenumber',
1188
           'cascade' =>
1189
           array(
1190
           1 => 'persist',
1191
           ),
1192
           'mappedBy' => 'user',
1193
           'orphanRemoval' => true,
1194
           'orderBy' =>
1195
           array(
1196
           'number' => 'ASC',
1197
           ),
1198
          ));
1199
        $metadata->mapManyToMany(array(
1200
           'fieldName' => 'groups',
1201
           'targetEntity' => 'Doctrine\\Tests\\ORM\\Mapping\\Group',
1202
           'cascade' =>
1203
           array(
1204
           0 => 'remove',
1205
           1 => 'persist',
1206
           2 => 'refresh',
1207
           3 => 'merge',
1208
           4 => 'detach',
1209
           ),
1210
           'mappedBy' => NULL,
1211
           'joinTable' =>
1212
           array(
1213
           'name' => 'cms_users_groups',
1214
           'joinColumns' =>
1215
           array(
1216
            0 =>
1217
            array(
1218
            'name' => 'user_id',
1219
            'referencedColumnName' => 'id',
1220
            'unique' => false,
1221
            'nullable' => false,
1222
            ),
1223
           ),
1224
           'inverseJoinColumns' =>
1225
           array(
1226
            0 =>
1227
            array(
1228
            'name' => 'group_id',
1229
            'referencedColumnName' => 'id',
1230
            'columnDefinition' => 'INT NULL',
1231
            ),
1232
           ),
1233
           ),
1234
           'orderBy' => NULL,
1235
          ));
1236
        $metadata->table['uniqueConstraints'] = array(
1237
            'search_idx' => array('columns' => array('name', 'user_email'), 'options'=> array('where' => 'name IS NOT NULL')),
1238
        );
1239
        $metadata->table['indexes'] = array(
1240
            'name_idx' => array('columns' => array('name')), 0 => array('columns' => array('user_email'))
1241
        );
1242
        $metadata->setSequenceGeneratorDefinition(array(
1243
                'sequenceName' => 'tablename_seq',
1244
                'allocationSize' => 100,
1245
                'initialValue' => 1,
1246
            ));
1247
        $metadata->addNamedQuery(array(
1248
                'name' => 'all',
1249
                'query' => 'SELECT u FROM __CLASS__ u'
1250
            ));
1251
    }
1252
}
1253
1254
/**
1255
 * @Entity
1256
 * @InheritanceType("SINGLE_TABLE")
1257
 * @DiscriminatorMap({"cat" = "Cat", "dog" = "Dog"})
1258
 * @DiscriminatorColumn(name="discr", length=32, type="string")
1259
 */
1260
abstract class Animal
1261
{
1262
    /**
1263
     * @Id @Column(type="string") @GeneratedValue(strategy="CUSTOM")
1264
     * @CustomIdGenerator(class="stdClass")
1265
     */
1266
    public $id;
1267
1268
    public static function loadMetadata(ClassMetadataInfo $metadata)
1269
    {
1270
        $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_CUSTOM);
1271
        $metadata->setCustomGeneratorDefinition(array("class" => "stdClass"));
1272
    }
1273
}
1274
1275
/** @Entity */
1276
class Cat extends Animal
1277
{
1278
    public static function loadMetadata(ClassMetadataInfo $metadata)
1279
    {
1280
1281
    }
1282
}
1283
1284
/** @Entity */
1285
class Dog extends Animal
1286
{
1287
    public static function loadMetadata(ClassMetadataInfo $metadata)
1288
    {
1289
1290
    }
1291
}
1292
1293
1294
/**
1295
 * @Entity
1296
 */
1297
class DDC1170Entity
1298
{
1299
1300
    /**
1301
     * @param string $value
1302
     */
1303
    function __construct($value = null)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1304
    {
1305
        $this->value = $value;
1306
    }
1307
1308
    /**
1309
     * @Id
1310
     * @GeneratedValue(strategy="NONE")
1311
     * @Column(type="integer", columnDefinition = "INT unsigned NOT NULL")
1312
     **/
1313
    private $id;
1314
1315
    /**
1316
     * @Column(columnDefinition = "VARCHAR(255) NOT NULL")
1317
     */
1318
    private $value;
1319
1320
    /**
1321
     * @return int
1322
     */
1323
    public function getId()
1324
    {
1325
        return $this->id;
1326
    }
1327
1328
    /**
1329
     * @return string
1330
     */
1331
    public function getValue()
1332
    {
1333
        return $this->value;
1334
    }
1335
1336
    public static function loadMetadata(ClassMetadataInfo $metadata)
1337
    {
1338
        $metadata->mapField(array(
1339
           'id'                 => true,
1340
           'fieldName'          => 'id',
1341
           'columnDefinition'   => 'INT unsigned NOT NULL',
1342
        ));
1343
1344
        $metadata->mapField(array(
1345
            'fieldName'         => 'value',
1346
            'columnDefinition'  => 'VARCHAR(255) NOT NULL'
1347
        ));
1348
1349
        $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_NONE);
1350
    }
1351
1352
}
1353
1354
/**
1355
 * @Entity
1356
 * @InheritanceType("SINGLE_TABLE")
1357
 * @DiscriminatorMap({"ONE" = "DDC807SubClasse1", "TWO" = "DDC807SubClasse2"})
1358
 * @DiscriminatorColumn(name = "dtype", columnDefinition="ENUM('ONE','TWO')")
1359
 */
1360
class DDC807Entity
1361
{
1362
    /**
1363
     * @Id
1364
     * @Column(type="integer")
1365
     * @GeneratedValue(strategy="NONE")
1366
     **/
1367
   public $id;
1368
1369
   public static function loadMetadata(ClassMetadataInfo $metadata)
1370
    {
1371
         $metadata->mapField(array(
1372
           'id'                 => true,
1373
           'fieldName'          => 'id',
1374
        ));
1375
1376
        $metadata->setDiscriminatorColumn(array(
1377
            'name'              => "dtype",
1378
            'type'              => "string",
1379
            'columnDefinition'  => "ENUM('ONE','TWO')"
1380
        ));
1381
1382
        $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_NONE);
1383
    }
1384
}
1385
1386
class DDC807SubClasse1 {}
1387
class DDC807SubClasse2 {}
1388
1389
class Address {}
1390
class Phonenumber {}
1391
class Group {}
1392
1393
/**
1394
 * @Entity
1395
 * @Table(indexes={@Index(columns={"content"}, flags={"fulltext"}, options={"where": "content IS NOT NULL"})})
1396
 */
1397
class Comment
1398
{
1399
    /**
1400
     * @Column(type="text")
1401
     */
1402
    private $content;
1403
1404
    public static function loadMetadata(ClassMetadataInfo $metadata)
1405
    {
1406
        $metadata->setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_NONE);
1407
        $metadata->setPrimaryTable(array(
1408
            'indexes' => array(
1409
                array('columns' => array('content'), 'flags' => array('fulltext'), 'options' => array('where' => 'content IS NOT NULL'))
1410
            )
1411
        ));
1412
1413
        $metadata->mapField(array(
1414
            'fieldName' => 'content',
1415
            'type' => 'text',
1416
            'scale' => 0,
1417
            'length' => NULL,
1418
            'unique' => false,
1419
            'nullable' => false,
1420
            'precision' => 0,
1421
            'columnName' => 'content',
1422
        ));
1423
    }
1424
}
1425
1426
/**
1427
 * @Entity
1428
 * @InheritanceType("SINGLE_TABLE")
1429
 * @DiscriminatorMap({
1430
 *     "ONE" = "SingleTableEntityNoDiscriminatorColumnMappingSub1",
1431
 *     "TWO" = "SingleTableEntityNoDiscriminatorColumnMappingSub2"
1432
 * })
1433
 */
1434
class SingleTableEntityNoDiscriminatorColumnMapping
1435
{
1436
    /**
1437
     * @Id
1438
     * @Column(type="integer")
1439
     * @GeneratedValue(strategy="NONE")
1440
     */
1441
    public $id;
1442
1443
    public static function loadMetadata(ClassMetadataInfo $metadata)
1444
    {
1445
        $metadata->mapField(array(
1446
            'id' => true,
1447
            'fieldName' => 'id',
1448
        ));
1449
1450
        $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_NONE);
1451
    }
1452
}
1453
1454
class SingleTableEntityNoDiscriminatorColumnMappingSub1 extends SingleTableEntityNoDiscriminatorColumnMapping {}
1455
class SingleTableEntityNoDiscriminatorColumnMappingSub2 extends SingleTableEntityNoDiscriminatorColumnMapping {}
1456
1457
/**
1458
 * @Entity
1459
 * @InheritanceType("SINGLE_TABLE")
1460
 * @DiscriminatorMap({
1461
 *     "ONE" = "SingleTableEntityIncompleteDiscriminatorColumnMappingSub1",
1462
 *     "TWO" = "SingleTableEntityIncompleteDiscriminatorColumnMappingSub2"
1463
 * })
1464
 * @DiscriminatorColumn(name="dtype")
1465
 */
1466
class SingleTableEntityIncompleteDiscriminatorColumnMapping
1467
{
1468
    /**
1469
     * @Id
1470
     * @Column(type="integer")
1471
     * @GeneratedValue(strategy="NONE")
1472
     */
1473
    public $id;
1474
1475
    public static function loadMetadata(ClassMetadataInfo $metadata)
1476
    {
1477
        $metadata->mapField(array(
1478
            'id' => true,
1479
            'fieldName' => 'id',
1480
        ));
1481
1482
        $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_NONE);
1483
    }
1484
}
1485
1486
class SingleTableEntityIncompleteDiscriminatorColumnMappingSub1
1487
    extends SingleTableEntityIncompleteDiscriminatorColumnMapping {}
1488
class SingleTableEntityIncompleteDiscriminatorColumnMappingSub2
1489
    extends SingleTableEntityIncompleteDiscriminatorColumnMapping {}