Completed
Pull Request — 3.x (#912)
by Christian
01:45
created

ModelManagerTest::testGetVersion()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 9.552
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\DoctrineORMAdminBundle\Tests\Model;
15
16
use Doctrine\Common\Collections\ArrayCollection;
17
use Doctrine\Common\Persistence\ObjectManager;
18
use Doctrine\DBAL\Connection;
19
use Doctrine\DBAL\DBALException;
20
use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
21
use Doctrine\DBAL\Types\Type;
22
use Doctrine\ORM\Configuration;
23
use Doctrine\ORM\EntityManager;
24
use Doctrine\ORM\Mapping\ClassMetadata;
25
use Doctrine\ORM\Mapping\ClassMetadataFactory;
26
use Doctrine\ORM\OptimisticLockException;
27
use Doctrine\ORM\Query;
28
use Doctrine\ORM\QueryBuilder;
29
use Doctrine\ORM\Version;
30
use PHPUnit\Framework\TestCase;
31
use Sonata\AdminBundle\Datagrid\Datagrid;
32
use Sonata\AdminBundle\Datagrid\DatagridInterface;
33
use Sonata\AdminBundle\Exception\LockException;
34
use Sonata\AdminBundle\Exception\ModelManagerException;
35
use Sonata\AdminBundle\Filter\FilterInterface;
36
use Sonata\DoctrineORMAdminBundle\Admin\FieldDescription;
37
use Sonata\DoctrineORMAdminBundle\Datagrid\OrderByToSelectWalker;
38
use Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQuery;
39
use Sonata\DoctrineORMAdminBundle\Model\ModelManager;
40
use Sonata\DoctrineORMAdminBundle\Tests\Fixtures\DoctrineType\UuidType;
41
use Sonata\DoctrineORMAdminBundle\Tests\Fixtures\Entity\AbstractEntity;
42
use Sonata\DoctrineORMAdminBundle\Tests\Fixtures\Entity\AssociatedEntity;
43
use Sonata\DoctrineORMAdminBundle\Tests\Fixtures\Entity\ContainerEntity;
44
use Sonata\DoctrineORMAdminBundle\Tests\Fixtures\Entity\Embeddable\EmbeddedEntity;
45
use Sonata\DoctrineORMAdminBundle\Tests\Fixtures\Entity\Embeddable\SubEmbeddedEntity;
46
use Sonata\DoctrineORMAdminBundle\Tests\Fixtures\Entity\ProtectedEntity;
47
use Sonata\DoctrineORMAdminBundle\Tests\Fixtures\Entity\SimpleEntity;
48
use Sonata\DoctrineORMAdminBundle\Tests\Fixtures\Entity\UuidEntity;
49
use Sonata\DoctrineORMAdminBundle\Tests\Fixtures\Entity\VersionedEntity;
50
use Sonata\DoctrineORMAdminBundle\Tests\Fixtures\Util\ClassWithToStringSupport;
51
use Sonata\DoctrineORMAdminBundle\Tests\Fixtures\Util\NonIntegerIdentifierTestClass;
52
use Symfony\Bridge\Doctrine\RegistryInterface;
53
54
class ModelManagerTest extends TestCase
55
{
56
    public static function setUpBeforeClass(): void
57
    {
58
        if (!Type::hasType('uuid')) {
59
            Type::addType('uuid', UuidType::class);
60
        }
61
    }
62
63
    public function testSortParameters(): void
64
    {
65
        $registry = $this->createMock(RegistryInterface::class);
66
67
        $manager = new ModelManager($registry);
0 ignored issues
show
Documentation introduced by
$registry is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Bridge\Doctrine\RegistryInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
68
69
        $datagrid1 = $this->createMock(Datagrid::class);
70
        $datagrid2 = $this->createMock(Datagrid::class);
71
72
        $field1 = new FieldDescription();
73
        $field1->setName('field1');
74
75
        $field2 = new FieldDescription();
76
        $field2->setName('field2');
77
78
        $field3 = new FieldDescription();
79
        $field3->setName('field3');
80
        $field3->setOption('sortable', 'field3sortBy');
81
82
        $datagrid1
83
            ->expects($this->any())
84
            ->method('getValues')
85
            ->will($this->returnValue([
86
                '_sort_by' => $field1,
87
                '_sort_order' => 'ASC',
88
            ]));
89
90
        $datagrid2
91
            ->expects($this->any())
92
            ->method('getValues')
93
            ->will($this->returnValue([
94
                '_sort_by' => $field3,
95
                '_sort_order' => 'ASC',
96
            ]));
97
98
        $parameters = $manager->getSortParameters($field1, $datagrid1);
0 ignored issues
show
Documentation introduced by
$datagrid1 is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Sonata\AdminBundl...grid\DatagridInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
99
100
        $this->assertSame('DESC', $parameters['filter']['_sort_order']);
101
        $this->assertSame('field1', $parameters['filter']['_sort_by']);
102
103
        $parameters = $manager->getSortParameters($field2, $datagrid1);
0 ignored issues
show
Documentation introduced by
$datagrid1 is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Sonata\AdminBundl...grid\DatagridInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
104
105
        $this->assertSame('ASC', $parameters['filter']['_sort_order']);
106
        $this->assertSame('field2', $parameters['filter']['_sort_by']);
107
108
        $parameters = $manager->getSortParameters($field3, $datagrid1);
0 ignored issues
show
Documentation introduced by
$datagrid1 is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Sonata\AdminBundl...grid\DatagridInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
109
110
        $this->assertSame('ASC', $parameters['filter']['_sort_order']);
111
        $this->assertSame('field3sortBy', $parameters['filter']['_sort_by']);
112
113
        $parameters = $manager->getSortParameters($field3, $datagrid2);
0 ignored issues
show
Documentation introduced by
$datagrid2 is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Sonata\AdminBundl...grid\DatagridInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
114
115
        $this->assertSame('DESC', $parameters['filter']['_sort_order']);
116
        $this->assertSame('field3sortBy', $parameters['filter']['_sort_by']);
117
    }
118
119
    public function getVersionDataProvider()
120
    {
121
        return [
122
            [true],
123
            [false],
124
        ];
125
    }
126
127
    /**
128
     * @dataProvider getVersionDataProvider
129
     */
130
    public function testGetVersion($isVersioned): void
131
    {
132
        $object = new VersionedEntity();
133
134
        $modelManager = $this->getMockBuilder(ModelManager::class)
135
            ->disableOriginalConstructor()
136
            ->setMethods(['getMetadata'])
137
            ->getMock();
138
139
        $metadata = $this->getMetadata(\get_class($object), $isVersioned);
140
141
        $modelManager->expects($this->any())
142
            ->method('getMetadata')
143
            ->will($this->returnValue($metadata));
144
145
        if ($isVersioned) {
146
            $object->version = 123;
147
148
            $this->assertNotNull($modelManager->getLockVersion($object));
149
        } else {
150
            $this->assertNull($modelManager->getLockVersion($object));
151
        }
152
    }
153
154
    public function lockDataProvider()
155
    {
156
        return [
157
            [true,  false],
158
            [true,  true],
159
            [false, false],
160
        ];
161
    }
162
163
    /**
164
     * @dataProvider lockDataProvider
165
     */
166
    public function testLock($isVersioned, $expectsException): void
167
    {
168
        $object = new VersionedEntity();
169
170
        $em = $this->getMockBuilder(EntityManager::class)
171
            ->disableOriginalConstructor()
172
            ->setMethods(['lock'])
173
            ->getMock();
174
175
        $modelManager = $this->getMockBuilder(ModelManager::class)
176
            ->disableOriginalConstructor()
177
            ->setMethods(['getMetadata', 'getEntityManager'])
178
            ->getMock();
179
180
        $modelManager->expects($this->any())
181
            ->method('getEntityManager')
182
            ->will($this->returnValue($em));
183
184
        $metadata = $this->getMetadata(\get_class($object), $isVersioned);
185
186
        $modelManager->expects($this->any())
187
            ->method('getMetadata')
188
            ->will($this->returnValue($metadata));
189
190
        $em->expects($isVersioned ? $this->once() : $this->never())
191
            ->method('lock');
192
193
        if ($expectsException) {
194
            $em->expects($this->once())
195
                ->method('lock')
196
                ->will($this->throwException(OptimisticLockException::lockFailed($object)));
197
198
            $this->expectException(LockException::class);
199
        }
200
201
        $modelManager->lock($object, 123);
202
    }
203
204
    public function testGetParentMetadataForProperty(): void
205
    {
206
        if (version_compare(Version::VERSION, '2.5') < 0) {
207
            $this->markTestSkipped('Test for embeddables needs to run on Doctrine >= 2.5');
208
209
            return;
210
        }
211
212
        $containerEntityClass = ContainerEntity::class;
213
        $associatedEntityClass = AssociatedEntity::class;
214
        $embeddedEntityClass = EmbeddedEntity::class;
215
        $modelManagerClass = ModelManager::class;
216
217
        $em = $this->createMock(EntityManager::class);
218
219
        /** @var \PHPUnit_Framework_MockObject_MockObject|ModelManager $modelManager */
220
        $modelManager = $this->getMockBuilder($modelManagerClass)
221
            ->disableOriginalConstructor()
222
            ->setMethods(['getMetadata', 'getEntityManager'])
223
            ->getMock();
224
225
        $modelManager->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Sonata\DoctrineORMAdminBundle\Model\ModelManager.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
226
            ->method('getEntityManager')
227
            ->will($this->returnValue($em));
228
229
        $containerEntityMetadata = $this->getMetadataForContainerEntity();
230
        $associatedEntityMetadata = $this->getMetadataForAssociatedEntity();
231
        $embeddedEntityMetadata = $this->getMetadataForEmbeddedEntity();
232
233
        $modelManager->expects($this->any())->method('getMetadata')
234
            ->will(
235
                $this->returnValueMap(
236
                    [
237
                        [$containerEntityClass, $containerEntityMetadata],
238
                        [$embeddedEntityClass, $embeddedEntityMetadata],
239
                        [$associatedEntityClass, $associatedEntityMetadata],
240
                    ]
241
                )
242
            );
243
244
        /** @var ClassMetadata $metadata */
245
        list($metadata, $lastPropertyName) = $modelManager
0 ignored issues
show
Bug introduced by
The method getParentMetadataForProperty does only exist in Sonata\DoctrineORMAdminBundle\Model\ModelManager, but not in PHPUnit_Framework_MockObject_MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
246
            ->getParentMetadataForProperty($containerEntityClass, 'plainField');
247
        $this->assertSame($metadata->fieldMappings[$lastPropertyName]['type'], 'integer');
248
249
        list($metadata, $lastPropertyName) = $modelManager
250
            ->getParentMetadataForProperty($containerEntityClass, 'associatedEntity.plainField');
251
        $this->assertSame($metadata->fieldMappings[$lastPropertyName]['type'], 'string');
252
253
        list($metadata, $lastPropertyName) = $modelManager
254
            ->getParentMetadataForProperty($containerEntityClass, 'embeddedEntity.plainField');
255
        $this->assertSame($metadata->fieldMappings[$lastPropertyName]['type'], 'boolean');
256
257
        list($metadata, $lastPropertyName) = $modelManager
258
            ->getParentMetadataForProperty($containerEntityClass, 'associatedEntity.embeddedEntity.plainField');
259
        $this->assertSame($metadata->fieldMappings[$lastPropertyName]['type'], 'boolean');
260
261
        list($metadata, $lastPropertyName) = $modelManager
262
            ->getParentMetadataForProperty(
263
                $containerEntityClass,
264
                'associatedEntity.embeddedEntity.subEmbeddedEntity.plainField'
265
            );
266
        $this->assertSame($metadata->fieldMappings[$lastPropertyName]['type'], 'boolean');
267
    }
268
269
    public function getMetadataForEmbeddedEntity()
270
    {
271
        $metadata = new ClassMetadata(EmbeddedEntity::class);
272
273
        $metadata->fieldMappings = [
274
            'plainField' => [
275
                'fieldName' => 'plainField',
276
                'columnName' => 'plainField',
277
                'type' => 'boolean',
278
            ],
279
        ];
280
281
        return $metadata;
282
    }
283
284
    public function getMetadataForSubEmbeddedEntity()
285
    {
286
        $metadata = new ClassMetadata(SubEmbeddedEntity::class);
287
288
        $metadata->fieldMappings = [
289
            'plainField' => [
290
                'fieldName' => 'plainField',
291
                'columnName' => 'plainField',
292
                'type' => 'boolean',
293
            ],
294
        ];
295
296
        return $metadata;
297
    }
298
299
    public function getMetadataForAssociatedEntity()
300
    {
301
        $embeddedEntityClass = EmbeddedEntity::class;
302
        $subEmbeddedEntityClass = SubEmbeddedEntity::class;
303
304
        $metadata = new ClassMetadata(AssociatedEntity::class);
305
306
        $metadata->fieldMappings = [
307
            'plainField' => [
308
                'fieldName' => 'plainField',
309
                'columnName' => 'plainField',
310
                'type' => 'string',
311
            ],
312
        ];
313
314
        $metadata->embeddedClasses['embeddedEntity'] = [
315
            'class' => $embeddedEntityClass,
316
            'columnPrefix' => 'embedded_entity_',
317
        ];
318
        $metadata->embeddedClasses['embeddedEntity.subEmbeddedEntity'] = [
319
            'class' => $subEmbeddedEntityClass,
320
            'columnPrefix' => 'embedded_entity_sub_embedded_entity_',
321
            'declaredField' => 'embeddedEntity',
322
            'originalField' => 'subEmbeddedEntity',
323
        ];
324
325
        $metadata->inlineEmbeddable('embeddedEntity', $this->getMetadataForEmbeddedEntity());
326
        $metadata->inlineEmbeddable('embeddedEntity.subEmbeddedEntity', $this->getMetadataForSubEmbeddedEntity());
327
328
        return $metadata;
329
    }
330
331
    public function getMetadataForContainerEntity()
332
    {
333
        $containerEntityClass = ContainerEntity::class;
334
        $associatedEntityClass = AssociatedEntity::class;
335
        $embeddedEntityClass = EmbeddedEntity::class;
336
        $subEmbeddedEntityClass = SubEmbeddedEntity::class;
337
338
        $metadata = new ClassMetadata($containerEntityClass);
339
340
        $metadata->fieldMappings = [
341
            'plainField' => [
342
                'fieldName' => 'plainField',
343
                'columnName' => 'plainField',
344
                'type' => 'integer',
345
            ],
346
        ];
347
348
        $metadata->associationMappings['associatedEntity'] = [
349
            'fieldName' => 'associatedEntity',
350
            'targetEntity' => $associatedEntityClass,
351
            'sourceEntity' => $containerEntityClass,
352
        ];
353
354
        $metadata->embeddedClasses['embeddedEntity'] = [
355
            'class' => $embeddedEntityClass,
356
            'columnPrefix' => 'embeddedEntity',
357
        ];
358
        $metadata->embeddedClasses['embeddedEntity.subEmbeddedEntity'] = [
359
            'class' => $subEmbeddedEntityClass,
360
            'columnPrefix' => 'embedded_entity_sub_embedded_entity_',
361
            'declaredField' => 'embeddedEntity',
362
            'originalField' => 'subEmbeddedEntity',
363
        ];
364
365
        $metadata->inlineEmbeddable('embeddedEntity', $this->getMetadataForEmbeddedEntity());
366
        $metadata->inlineEmbeddable('embeddedEntity.subEmbeddedEntity', $this->getMetadataForSubEmbeddedEntity());
367
368
        return $metadata;
369
    }
370
371
    public function testGetIdentifierValuesForIdInObjectTypeWithToStringSupport(): void
372
    {
373
        $entityId = new ClassWithToStringSupport('to-string-id');
374
375
        $entity = new \stdClass();
376
377
        $meta = $this->createMock(ClassMetadata::class);
378
        $meta->expects($this->any())
379
            ->method('getIdentifierValues')
380
            ->willReturn([$entityId]);
381
382
        $mf = $this->createMock(ClassMetadataFactory::class);
383
        $mf->expects($this->any())
384
            ->method('getMetadataFor')
385
            ->willReturn($meta);
386
387
        $platform = $this->createMock(PostgreSqlPlatform::class);
388
389
        $conn = $this->createMock(Connection::class);
390
        $conn->expects($this->any())
391
            ->method('getDatabasePlatform')
392
            ->willReturn($platform);
393
394
        $em = $this->createMock(EntityManager::class);
395
        $em->expects($this->any())
396
            ->method('getMetadataFactory')
397
            ->willReturn($mf);
398
        $em->expects($this->any())
399
            ->method('getConnection')
400
            ->willReturn($conn);
401
402
        $registry = $this->createMock(RegistryInterface::class);
403
        $registry->expects($this->any())
404
            ->method('getManagerForClass')
405
            ->willReturn($em);
406
407
        $manager = new ModelManager($registry);
0 ignored issues
show
Documentation introduced by
$registry is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Bridge\Doctrine\RegistryInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
408
        $result = $manager->getIdentifierValues($entity);
409
410
        $this->assertSame('to-string-id', $result[0]);
411
    }
412
413
    public function testNonIntegerIdentifierType(): void
414
    {
415
        $uuid = new NonIntegerIdentifierTestClass('efbcfc4b-8c43-4d42-aa4c-d707e55151ac');
416
        $entity = new UuidEntity($uuid);
417
418
        $meta = $this->createMock(ClassMetadata::class);
419
        $meta->expects($this->any())
420
            ->method('getIdentifierValues')
421
            ->willReturn([$entity->getId()]);
422
        $meta->expects($this->any())
423
            ->method('getTypeOfField')
424
            ->willReturn(UuidType::NAME);
425
426
        $mf = $this->createMock(ClassMetadataFactory::class);
427
        $mf->expects($this->any())
428
            ->method('getMetadataFor')
429
            ->willReturn($meta);
430
431
        $platform = $this->createMock(PostgreSqlPlatform::class);
432
433
        $conn = $this->createMock(Connection::class);
434
        $conn->expects($this->any())
435
            ->method('getDatabasePlatform')
436
            ->willReturn($platform);
437
438
        $em = $this->createMock(EntityManager::class);
439
        $em->expects($this->any())
440
            ->method('getMetadataFactory')
441
            ->willReturn($mf);
442
        $em->expects($this->any())
443
            ->method('getConnection')
444
            ->willReturn($conn);
445
446
        $registry = $this->createMock(RegistryInterface::class);
447
        $registry->expects($this->any())
448
            ->method('getManagerForClass')
449
            ->willReturn($em);
450
451
        $manager = new ModelManager($registry);
0 ignored issues
show
Documentation introduced by
$registry is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Bridge\Doctrine\RegistryInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
452
        $result = $manager->getIdentifierValues($entity);
453
454
        $this->assertSame($entity->getId()->toString(), $result[0]);
455
    }
456
457
    public function testAssociationIdentifierType(): void
458
    {
459
        $entity = new ContainerEntity(new AssociatedEntity(42, new EmbeddedEntity()), new EmbeddedEntity());
460
461
        $meta = $this->createMock(ClassMetadata::class);
462
        $meta->expects($this->any())
463
            ->method('getIdentifierValues')
464
            ->willReturn([$entity->getAssociatedEntity()->getPlainField()]);
465
        $meta->expects($this->any())
466
            ->method('getTypeOfField')
467
            ->willReturn(null);
468
469
        $mf = $this->createMock(ClassMetadataFactory::class);
470
        $mf->expects($this->any())
471
            ->method('getMetadataFor')
472
            ->willReturn($meta);
473
474
        $platform = $this->createMock(PostgreSqlPlatform::class);
475
476
        $conn = $this->createMock(Connection::class);
477
        $conn->expects($this->any())
478
            ->method('getDatabasePlatform')
479
            ->willReturn($platform);
480
481
        $em = $this->createMock(EntityManager::class);
482
        $em->expects($this->any())
483
            ->method('getMetadataFactory')
484
            ->willReturn($mf);
485
        $em->expects($this->any())
486
            ->method('getConnection')
487
            ->willReturn($conn);
488
489
        $registry = $this->createMock(RegistryInterface::class);
490
        $registry->expects($this->any())
491
            ->method('getManagerForClass')
492
            ->willReturn($em);
493
494
        $manager = new ModelManager($registry);
0 ignored issues
show
Documentation introduced by
$registry is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Bridge\Doctrine\RegistryInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
495
        $result = $manager->getIdentifierValues($entity);
496
497
        $this->assertSame(42, $result[0]);
498
    }
499
500
    /**
501
     * [sortBy, sortOrder, isAddOrderBy].
502
     *
503
     * @return array
504
     */
505
    public function getSortableInDataSourceIteratorDataProvider()
506
    {
507
        return [
508
            [null, null, false],
509
            ['', 'ASC', false],
510
            ['field', 'ASC', true],
511
            ['field', null, true],
512
        ];
513
    }
514
515
    /**
516
     * @dataProvider getSortableInDataSourceIteratorDataProvider
517
     *
518
     * @param string|null $sortBy
519
     * @param string|null $sortOrder
520
     * @param bool        $isAddOrderBy
521
     */
522
    public function testSortableInDataSourceIterator($sortBy, $sortOrder, $isAddOrderBy): void
523
    {
524
        $datagrid = $this->getMockForAbstractClass(DatagridInterface::class);
525
        $configuration = $this->getMockBuilder(Configuration::class)->getMock();
526
        $configuration->expects($this->any())
527
            ->method('getDefaultQueryHints')
528
            ->willReturn([]);
529
530
        $em = $this->getMockBuilder(EntityManager::class)
531
            ->disableOriginalConstructor()
532
            ->getMock();
533
534
        $em->expects($this->any())
535
            ->method('getConfiguration')
536
            ->willReturn($configuration);
537
538
        $queryBuilder = $this->getMockBuilder(QueryBuilder::class)
539
            ->setConstructorArgs([$em])
540
            ->getMock();
541
        $query = new Query($em);
0 ignored issues
show
Documentation introduced by
$em is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Doctrine\ORM\EntityManagerInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
542
543
        $proxyQuery = $this->getMockBuilder(ProxyQuery::class)
544
            ->setConstructorArgs([$queryBuilder])
545
            ->setMethods(['getSortBy', 'getSortOrder', 'getRootAliases'])
546
            ->getMock();
547
548
        $proxyQuery->expects($this->any())
549
            ->method('getSortOrder')
550
            ->willReturn($sortOrder);
551
552
        $proxyQuery->expects($this->any())
553
            ->method('getSortBy')
554
            ->willReturn($sortBy);
555
556
        $queryBuilder->expects($isAddOrderBy ? $this->atLeastOnce() : $this->never())
557
            ->method('addOrderBy');
558
559
        $proxyQuery->expects($this->any())
560
            ->method('getRootAliases')
561
            ->willReturn(['a']);
562
563
        $queryBuilder->expects($this->any())
564
            ->method('getQuery')
565
            ->willReturn($query);
566
567
        $datagrid->expects($this->any())
568
            ->method('getQuery')
569
            ->willReturn($proxyQuery);
570
571
        $registry = $this->getMockBuilder(RegistryInterface::class)->getMock();
572
        $manager = new ModelManager($registry);
0 ignored issues
show
Documentation introduced by
$registry is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Bridge\Doctrine\RegistryInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
573
        $manager->getDataSourceIterator($datagrid, []);
0 ignored issues
show
Documentation introduced by
$datagrid is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Sonata\AdminBundl...grid\DatagridInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
574
575
        if ($isAddOrderBy) {
576
            $this->assertArrayHasKey($key = 'doctrine.customTreeWalkers', $hints = $query->getHints());
577
            $this->assertContains(OrderByToSelectWalker::class, $hints[$key]);
578
        }
579
    }
580
581
    public function testModelReverseTransform(): void
582
    {
583
        $class = SimpleEntity::class;
584
585
        $metadataFactory = $this->createMock(ClassMetadataFactory::class);
586
        $modelManager = $this->createMock(ObjectManager::class);
587
        $registry = $this->createMock(RegistryInterface::class);
588
589
        $classMetadata = new ClassMetadata($class);
590
        $classMetadata->reflClass = new \ReflectionClass($class);
591
592
        $modelManager->expects($this->once())
593
            ->method('getMetadataFactory')
594
            ->willReturn($metadataFactory);
595
        $metadataFactory->expects($this->once())
596
            ->method('getMetadataFor')
597
            ->with($class)
598
            ->willReturn($classMetadata);
599
        $registry->expects($this->once())
600
            ->method('getManagerForClass')
601
            ->with($class)
602
            ->willReturn($modelManager);
603
604
        $manager = new ModelManager($registry);
0 ignored issues
show
Documentation introduced by
$registry is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Bridge\Doctrine\RegistryInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
605
        $this->assertInstanceOf($class, $object = $manager->modelReverseTransform(
606
            $class,
607
            [
608
                'schmeckles' => 42,
609
                'multi_word_property' => 'hello',
610
            ]
611
        ));
612
        $this->assertSame(42, $object->getSchmeckles());
613
        $this->assertSame('hello', $object->getMultiWordProperty());
614
    }
615
616
    public function testCollections(): void
617
    {
618
        $registry = $this->createMock(RegistryInterface::class);
619
        $model = new ModelManager($registry);
0 ignored issues
show
Documentation introduced by
$registry is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Bridge\Doctrine\RegistryInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
620
621
        $collection = $model->getModelCollectionInstance('whyDoWeEvenHaveThisParameter');
622
        $this->assertInstanceOf(ArrayCollection::class, $collection);
623
624
        $item1 = 'item1';
625
        $item2 = 'item2';
626
        $model->collectionAddElement($collection, $item1);
627
        $model->collectionAddElement($collection, $item2);
628
629
        $this->assertTrue($model->collectionHasElement($collection, $item1));
630
631
        $model->collectionRemoveElement($collection, $item1);
632
633
        $this->assertFalse($model->collectionHasElement($collection, $item1));
634
635
        $model->collectionClear($collection);
636
637
        $this->assertTrue($collection->isEmpty());
638
    }
639
640
    public function testModelTransform(): void
641
    {
642
        $registry = $this->createMock(RegistryInterface::class);
643
        $model = new ModelManager($registry);
0 ignored issues
show
Documentation introduced by
$registry is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Bridge\Doctrine\RegistryInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
644
645
        $result = $model->modelTransform('thisIsNotUsed', 'doWeNeedThisMethod');
0 ignored issues
show
Documentation introduced by
'doWeNeedThisMethod' is of type string, but the function expects a object.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
646
647
        $this->assertSame('doWeNeedThisMethod', $result);
648
    }
649
650
    public function testGetPaginationParameters(): void
651
    {
652
        $datagrid = $this->createMock(DatagridInterface::class);
653
        $filter = $this->createMock(FilterInterface::class);
654
        $registry = $this->createMock(RegistryInterface::class);
655
656
        $datagrid->expects($this->once())
657
            ->method('getValues')
658
            ->willReturn(['_sort_by' => $filter]);
659
660
        $filter->expects($this->once())
661
            ->method('getName')
662
            ->willReturn($name = 'test');
663
664
        $model = new ModelManager($registry);
0 ignored issues
show
Documentation introduced by
$registry is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Bridge\Doctrine\RegistryInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
665
666
        $result = $model->getPaginationParameters($datagrid, $page = 5);
0 ignored issues
show
Documentation introduced by
$datagrid is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Sonata\AdminBundl...grid\DatagridInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
667
668
        $this->assertSame($page, $result['filter']['_page']);
669
        $this->assertSame($name, $result['filter']['_sort_by']);
670
    }
671
672
    public function testGetModelInstanceException(): void
673
    {
674
        $registry = $this->createMock(RegistryInterface::class);
675
676
        $model = new ModelManager($registry);
0 ignored issues
show
Documentation introduced by
$registry is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Bridge\Doctrine\RegistryInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
677
678
        $this->expectException(\RuntimeException::class);
679
680
        $model->getModelInstance(AbstractEntity::class);
681
    }
682
683
    public function testGetModelInstanceForProtectedEntity(): void
684
    {
685
        $registry = $this->createMock(RegistryInterface::class);
686
687
        $model = new ModelManager($registry);
0 ignored issues
show
Documentation introduced by
$registry is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Bridge\Doctrine\RegistryInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
688
689
        $this->assertInstanceOf(ProtectedEntity::class, $model->getModelInstance(ProtectedEntity::class));
690
    }
691
692
    public function testGetEntityManagerException(): void
693
    {
694
        $registry = $this->createMock(RegistryInterface::class);
695
696
        $model = new ModelManager($registry);
0 ignored issues
show
Documentation introduced by
$registry is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Bridge\Doctrine\RegistryInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
697
698
        $this->expectException(\RuntimeException::class);
699
700
        $model->getEntityManager(VersionedEntity::class);
701
    }
702
703
    public function testGetNewFieldDescriptionInstanceException(): void
704
    {
705
        $registry = $this->createMock(RegistryInterface::class);
706
707
        $model = new ModelManager($registry);
0 ignored issues
show
Documentation introduced by
$registry is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Bridge\Doctrine\RegistryInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
708
709
        $this->expectException(\RuntimeException::class);
710
711
        $model->getNewFieldDescriptionInstance(VersionedEntity::class, [], []);
0 ignored issues
show
Documentation introduced by
array() is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
712
    }
713
714
    /**
715
     * @dataProvider createUpdateRemoveData
716
     */
717
    public function testCreate($exception): void
718
    {
719
        $registry = $this->createMock(RegistryInterface::class);
720
721
        $entityManger = $this->createMock(EntityManager::class);
722
723
        $registry->expects($this->once())
724
            ->method('getManagerForClass')
725
            ->willReturn($entityManger);
726
727
        $entityManger->expects($this->once())
728
            ->method('persist');
729
730
        $entityManger->expects($this->once())
731
            ->method('flush')
732
            ->willThrowException($exception);
733
734
        $model = new ModelManager($registry);
0 ignored issues
show
Documentation introduced by
$registry is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Bridge\Doctrine\RegistryInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
735
736
        $this->expectException(ModelManagerException::class);
737
738
        $model->create(new VersionedEntity());
739
    }
740
741
    public function createUpdateRemoveData()
742
    {
743
        return [
744
            'PDOException' => [
745
                new \PDOException(),
746
            ],
747
            'DBALException' => [
748
                new DBALException(),
749
            ],
750
        ];
751
    }
752
753
    /**
754
     * @dataProvider createUpdateRemoveData
755
     */
756
    public function testUpdate($exception): void
757
    {
758
        $registry = $this->createMock(RegistryInterface::class);
759
760
        $entityManger = $this->createMock(EntityManager::class);
761
762
        $registry->expects($this->once())
763
            ->method('getManagerForClass')
764
            ->willReturn($entityManger);
765
766
        $entityManger->expects($this->once())
767
            ->method('persist');
768
769
        $entityManger->expects($this->once())
770
            ->method('flush')
771
            ->willThrowException($exception);
772
773
        $model = new ModelManager($registry);
0 ignored issues
show
Documentation introduced by
$registry is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Bridge\Doctrine\RegistryInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
774
775
        $this->expectException(ModelManagerException::class);
776
777
        $model->update(new VersionedEntity());
778
    }
779
780
    /**
781
     * @dataProvider createUpdateRemoveData
782
     */
783
    public function testRemove($exception): void
784
    {
785
        $registry = $this->createMock(RegistryInterface::class);
786
787
        $entityManger = $this->createMock(EntityManager::class);
788
789
        $registry->expects($this->once())
790
            ->method('getManagerForClass')
791
            ->willReturn($entityManger);
792
793
        $entityManger->expects($this->once())
794
            ->method('remove');
795
796
        $entityManger->expects($this->once())
797
            ->method('flush')
798
            ->willThrowException($exception);
799
800
        $model = new ModelManager($registry);
0 ignored issues
show
Documentation introduced by
$registry is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Bridge\Doctrine\RegistryInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
801
802
        $this->expectException(ModelManagerException::class);
803
804
        $model->delete(new VersionedEntity());
805
    }
806
807
    public function testFindBadId(): void
808
    {
809
        $registry = $this->createMock(RegistryInterface::class);
810
811
        $model = new ModelManager($registry);
0 ignored issues
show
Documentation introduced by
$registry is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Bridge\Doctrine\RegistryInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
812
813
        $this->assertNull($model->find('notImportant', null));
814
    }
815
816
    public function testGetUrlsafeIdentifierException(): void
817
    {
818
        $registry = $this->createMock(RegistryInterface::class);
819
820
        $model = new ModelManager($registry);
0 ignored issues
show
Documentation introduced by
$registry is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Bridge\Doctrine\RegistryInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
821
822
        $this->expectException(\RuntimeException::class);
823
824
        $model->getNormalizedIdentifier('test');
0 ignored issues
show
Documentation introduced by
'test' is of type string, but the function expects a object.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
825
    }
826
827
    public function testGetUrlsafeIdentifierNull(): void
828
    {
829
        $registry = $this->createMock(RegistryInterface::class);
830
831
        $model = new ModelManager($registry);
0 ignored issues
show
Documentation introduced by
$registry is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Bridge\Doctrine\RegistryInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
832
833
        $this->assertNull($model->getNormalizedIdentifier(null));
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
834
    }
835
836
    private function getMetadata($class, $isVersioned)
837
    {
838
        $metadata = new ClassMetadata($class);
839
840
        $metadata->isVersioned = $isVersioned;
841
842
        if ($isVersioned) {
843
            $versionField = 'version';
844
            $metadata->versionField = $versionField;
845
            $metadata->reflFields[$versionField] = new \ReflectionProperty($class, $versionField);
846
        }
847
848
        return $metadata;
849
    }
850
}
851