Completed
Push — fix_phpstorm ( 0f3b31 )
by
unknown
01:15
created

ModelManagerTest::testCollections()   A

Complexity

Conditions 1
Paths 1

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 1
nc 1
nop 0
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\DoctrineMongoDBAdminBundle\Tests\Model;
15
16
use Doctrine\Common\Collections\ArrayCollection;
17
use Doctrine\Common\Persistence\Mapping\ClassMetadataFactory;
18
use Doctrine\Common\Persistence\ObjectManager;
19
use Doctrine\ODM\MongoDB\DocumentManager;
20
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
21
use PHPUnit\Framework\TestCase;
22
use Sonata\AdminBundle\Datagrid\Datagrid;
23
use Sonata\AdminBundle\Datagrid\DatagridInterface;
24
use Sonata\AdminBundle\Filter\FilterInterface;
25
use Sonata\DoctrineMongoDBAdminBundle\Admin\FieldDescription;
26
use Sonata\DoctrineMongoDBAdminBundle\Model\ModelManager;
27
use Sonata\DoctrineMongoDBAdminBundle\Tests\Fixtures\Document\AbstractDocument;
28
use Sonata\DoctrineMongoDBAdminBundle\Tests\Fixtures\Document\AssociatedDocument;
29
use Sonata\DoctrineMongoDBAdminBundle\Tests\Fixtures\Document\ContainerDocument;
30
use Sonata\DoctrineMongoDBAdminBundle\Tests\Fixtures\Document\EmbeddedDocument;
31
use Sonata\DoctrineMongoDBAdminBundle\Tests\Fixtures\Document\ProtectedDocument;
32
use Sonata\DoctrineMongoDBAdminBundle\Tests\Fixtures\Document\SimpleDocument;
33
use Symfony\Bridge\Doctrine\ManagerRegistry;
34
35
class ModelManagerTest extends TestCase
36
{
37
    public function testSortParameters(): void
38
    {
39
        $registry = $this->createMock(ManagerRegistry::class);
40
41
        $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\ManagerRegistry>.

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...
42
43
        $datagrid1 = $this->createMock(Datagrid::class);
44
        $datagrid2 = $this->createMock(Datagrid::class);
45
46
        $field1 = new FieldDescription();
47
        $field1->setName('field1');
48
49
        $field2 = new FieldDescription();
50
        $field2->setName('field2');
51
52
        $field3 = new FieldDescription();
53
        $field3->setName('field3');
54
        $field3->setOption('sortable', 'field3sortBy');
55
56
        $datagrid1
57
            ->method('getValues')
58
            ->willReturn([
59
                '_sort_by' => $field1,
60
                '_sort_order' => 'ASC',
61
            ]);
62
63
        $datagrid2
64
            ->method('getValues')
65
            ->willReturn([
66
                '_sort_by' => $field3,
67
                '_sort_order' => 'ASC',
68
            ]);
69
70
        $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...
71
72
        $this->assertSame('DESC', $parameters['filter']['_sort_order']);
73
        $this->assertSame('field1', $parameters['filter']['_sort_by']);
74
75
        $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...
76
77
        $this->assertSame('ASC', $parameters['filter']['_sort_order']);
78
        $this->assertSame('field2', $parameters['filter']['_sort_by']);
79
80
        $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...
81
82
        $this->assertSame('ASC', $parameters['filter']['_sort_order']);
83
        $this->assertSame('field3sortBy', $parameters['filter']['_sort_by']);
84
85
        $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...
86
87
        $this->assertSame('DESC', $parameters['filter']['_sort_order']);
88
        $this->assertSame('field3sortBy', $parameters['filter']['_sort_by']);
89
    }
90
91
    public function testGetParentMetadataForProperty(): void
92
    {
93
        $containerDocumentClass = ContainerDocument::class;
94
        $associatedDocumentClass = AssociatedDocument::class;
95
        $embeddedDocumentClass = EmbeddedDocument::class;
96
97
        $dm = $this->createMock(DocumentManager::class);
98
99
        $registry = $this->createMock(ManagerRegistry::class);
100
101
        $modelManager = 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\ManagerRegistry>.

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...
102
103
        $registry
104
            ->method('getManagerForClass')
105
            ->willReturn($dm);
106
107
        $metadataFactory = $this->createMock(ClassMetadataFactory::class);
108
109
        $dm
110
            ->method('getMetadataFactory')
111
            ->willReturn($metadataFactory);
112
113
        $containerDocumentMetadata = $this->getMetadataForContainerDocument();
114
        $associatedDocumentMetadata = $this->getMetadataForAssociatedDocument();
115
        $embeddedDocumentMetadata = $this->getMetadataForEmbeddedDocument();
116
117
        $metadataFactory->method('getMetadataFor')
118
            ->willReturnMap(
119
120
                [
121
                    [$containerDocumentClass, $containerDocumentMetadata],
122
                    [$embeddedDocumentClass, $embeddedDocumentMetadata],
123
                    [$associatedDocumentClass, $associatedDocumentMetadata],
124
                ]
125
126
            );
127
128
        /** @var ClassMetadata $metadata */
129
        [$metadata, $lastPropertyName] = $modelManager
0 ignored issues
show
Bug introduced by
The variable $metadata does not exist. Did you mean $metadataFactory?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
Bug introduced by
The variable $lastPropertyName does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
130
            ->getParentMetadataForProperty($containerDocumentClass, 'plainField');
131
        $this->assertSame($metadata->fieldMappings[$lastPropertyName]['type'], 'integer');
0 ignored issues
show
Bug introduced by
The variable $metadata does not exist. Did you mean $metadataFactory?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
132
133
        [$metadata, $lastPropertyName] = $modelManager
0 ignored issues
show
Bug introduced by
The variable $metadata does not exist. Did you mean $metadataFactory?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
134
            ->getParentMetadataForProperty($containerDocumentClass, 'associatedDocument.plainField');
135
        $this->assertSame($metadata->fieldMappings[$lastPropertyName]['type'], 'string');
0 ignored issues
show
Bug introduced by
The variable $metadata does not exist. Did you mean $metadataFactory?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
136
137
        [$metadata, $lastPropertyName] = $modelManager
0 ignored issues
show
Bug introduced by
The variable $metadata does not exist. Did you mean $metadataFactory?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
138
            ->getParentMetadataForProperty($containerDocumentClass, 'embeddedDocument.plainField');
139
        $this->assertSame($metadata->fieldMappings[$lastPropertyName]['type'], 'boolean');
0 ignored issues
show
Bug introduced by
The variable $metadata does not exist. Did you mean $metadataFactory?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
140
141
        $this->assertSame($metadata->fieldMappings[$lastPropertyName]['type'], 'boolean');
0 ignored issues
show
Bug introduced by
The variable $metadata does not exist. Did you mean $metadataFactory?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
142
    }
143
144
    public function getMetadataForEmbeddedDocument()
145
    {
146
        $metadata = new ClassMetadata(EmbeddedDocument::class);
147
148
        $metadata->fieldMappings = [
149
            'plainField' => [
150
                'fieldName' => 'plainField',
151
                'columnName' => 'plainField',
152
                'type' => 'boolean',
153
            ],
154
        ];
155
156
        return $metadata;
157
    }
158
159
    public function getMetadataForAssociatedDocument()
160
    {
161
        $embeddedDocumentClass = EmbeddedDocument::class;
162
163
        $metadata = new ClassMetadata(AssociatedDocument::class);
164
165
        $metadata->fieldMappings = [
166
            'plainField' => [
167
                'fieldName' => 'plainField',
168
                'name' => 'plainField',
169
                'columnName' => 'plainField',
170
                'type' => 'string',
171
            ],
172
        ];
173
174
        $metadata->mapOneEmbedded([
175
            'fieldName' => 'embeddedDocument',
176
            'name' => 'embeddedDocument',
177
            'targetDocument' => $embeddedDocumentClass,
178
        ]);
179
180
        return $metadata;
181
    }
182
183
    public function getMetadataForContainerDocument()
184
    {
185
        $containerDocumentClass = ContainerDocument::class;
186
        $associatedDocumentClass = AssociatedDocument::class;
187
        $embeddedDocumentClass = EmbeddedDocument::class;
188
189
        $metadata = new ClassMetadata($containerDocumentClass);
190
191
        $metadata->fieldMappings = [
192
            'plainField' => [
193
                'fieldName' => 'plainField',
194
                'name' => 'plainField',
195
                'columnName' => 'plainField',
196
                'type' => 'integer',
197
            ],
198
        ];
199
200
        $metadata->associationMappings['associatedDocument'] = [
201
            'fieldName' => 'associatedDocument',
202
            'name' => 'associatedDocument',
203
            'targetDocument' => $associatedDocumentClass,
204
            'sourceDocument' => $containerDocumentClass,
205
        ];
206
207
        $metadata->mapOneEmbedded([
208
            'fieldName' => 'embeddedDocument',
209
            'name' => 'embeddedDocument',
210
            'targetDocument' => $embeddedDocumentClass,
211
        ]);
212
213
        return $metadata;
214
    }
215
216
    public function testModelReverseTransform(): void
217
    {
218
        $class = SimpleDocument::class;
219
220
        $metadataFactory = $this->createMock(ClassMetadataFactory::class);
221
        $modelManager = $this->createMock(ObjectManager::class);
222
        $registry = $this->createMock(ManagerRegistry::class);
223
224
        $classMetadata = new ClassMetadata($class);
225
        $classMetadata->reflClass = new \ReflectionClass($class);
226
227
        $modelManager->expects($this->once())
228
            ->method('getMetadataFactory')
229
            ->willReturn($metadataFactory);
230
        $metadataFactory->expects($this->once())
231
            ->method('getMetadataFor')
232
            ->with($class)
233
            ->willReturn($classMetadata);
234
        $registry->expects($this->once())
235
            ->method('getManagerForClass')
236
            ->with($class)
237
            ->willReturn($modelManager);
238
239
        $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\ManagerRegistry>.

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...
240
        $this->assertInstanceOf($class, $object = $manager->modelReverseTransform(
241
            $class,
242
            [
243
                'schmeckles' => 42,
244
                'multi_word_property' => 'hello',
245
            ]
246
        ));
247
        $this->assertSame(42, $object->getSchmeckles());
248
        $this->assertSame('hello', $object->getMultiWordProperty());
249
    }
250
251
    public function testCollections(): void
252
    {
253
        $registry = $this->createMock(ManagerRegistry::class);
254
        $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\ManagerRegistry>.

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...
255
256
        $collection = $model->getModelCollectionInstance('whyDoWeEvenHaveThisParameter');
257
        $this->assertInstanceOf(ArrayCollection::class, $collection);
258
259
        $item1 = 'item1';
260
        $item2 = 'item2';
261
        $model->collectionAddElement($collection, $item1);
0 ignored issues
show
Bug introduced by
It seems like $collection defined by $model->getModelCollecti...EvenHaveThisParameter') on line 256 can also be of type object<ArrayAccess>; however, Sonata\DoctrineMongoDBAd...:collectionAddElement() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Documentation introduced by
$item1 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...
262
        $model->collectionAddElement($collection, $item2);
0 ignored issues
show
Documentation introduced by
$item2 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...
263
264
        $this->assertTrue($model->collectionHasElement($collection, $item1));
265
266
        $model->collectionRemoveElement($collection, $item1);
267
268
        $this->assertFalse($model->collectionHasElement($collection, $item1));
269
270
        $model->collectionClear($collection);
271
272
        $this->assertTrue($collection->isEmpty());
0 ignored issues
show
Bug introduced by
The method isEmpty cannot be called on $collection (of type array).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
273
    }
274
275
    public function testModelTransform(): void
276
    {
277
        $registry = $this->createMock(ManagerRegistry::class);
278
        $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\ManagerRegistry>.

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...
279
280
        $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...
281
282
        $this->assertSame('doWeNeedThisMethod', $result);
283
    }
284
285
    public function testGetPaginationParameters(): void
286
    {
287
        $datagrid = $this->createMock(DatagridInterface::class);
288
        $filter = $this->createMock(FilterInterface::class);
289
        $registry = $this->createMock(ManagerRegistry::class);
290
291
        $datagrid->expects($this->once())
292
            ->method('getValues')
293
            ->willReturn(['_sort_by' => $filter]);
294
295
        $filter->expects($this->once())
296
            ->method('getName')
297
            ->willReturn($name = 'test');
298
299
        $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\ManagerRegistry>.

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...
300
301
        $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...
302
303
        $this->assertSame($page, $result['filter']['_page']);
304
        $this->assertSame($name, $result['filter']['_sort_by']);
305
    }
306
307
    public function testGetModelInstanceException(): void
308
    {
309
        $registry = $this->createMock(ManagerRegistry::class);
310
311
        $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\ManagerRegistry>.

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...
312
313
        $this->expectException(\RuntimeException::class);
314
315
        $model->getModelInstance(AbstractDocument::class);
316
    }
317
318
    public function testGetModelInstanceForProtectedDocument(): void
319
    {
320
        $registry = $this->createMock(ManagerRegistry::class);
321
322
        $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\ManagerRegistry>.

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...
323
324
        $this->assertInstanceOf(ProtectedDocument::class, $model->getModelInstance(ProtectedDocument::class));
325
    }
326
327
    public function testFindBadId(): void
328
    {
329
        $registry = $this->createMock(ManagerRegistry::class);
330
331
        $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\ManagerRegistry>.

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...
332
333
        $this->assertNull($model->find('notImportant', null));
334
    }
335
336
    public function testGetUrlsafeIdentifierException(): void
337
    {
338
        $registry = $this->createMock(ManagerRegistry::class);
339
340
        $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\ManagerRegistry>.

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...
341
342
        $this->expectException(\RuntimeException::class);
343
344
        $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...
345
    }
346
347
    public function testGetUrlsafeIdentifierNull(): void
348
    {
349
        $registry = $this->createMock(ManagerRegistry::class);
350
351
        $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\ManagerRegistry>.

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...
352
353
        $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...
354
    }
355
}
356