Completed
Push — master ( b862c7...3fbbd0 )
by
unknown
02:19 queued 10s
created

ModelManagerTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 45
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testFilterEmpty() 0 6 1
A testNormalizedIdentifierException() 0 10 1
A getWrongDocuments() 0 10 1
A testGetNormalizedIdentifierNull() 0 8 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\DoctrineMongoDBAdminBundle\Tests\Model;
15
16
use PHPUnit\Framework\TestCase;
17
use Sonata\DoctrineMongoDBAdminBundle\Model\ModelManager;
18
use Symfony\Bridge\Doctrine\ManagerRegistry;
19
20
class ModelManagerTest extends TestCase
21
{
22
    public function testFilterEmpty(): void
23
    {
24
        $registry = $this->createMock(ManagerRegistry::class);
25
26
        new ModelManager($registry);
27
    }
28
29
    /**
30
     * @dataProvider getWrongDocuments
31
     *
32
     * @param mixed $document
33
     */
34
    public function testNormalizedIdentifierException($document): void
35
    {
36
        $registry = $this->createMock(ManagerRegistry::class);
37
38
        $model = new ModelManager($registry);
39
40
        $this->expectException(\RuntimeException::class);
41
42
        $model->getNormalizedIdentifier($document);
43
    }
44
45
    public function getWrongDocuments(): iterable
46
    {
47
        yield [0];
48
        yield [1];
49
        yield [false];
50
        yield [true];
51
        yield [[]];
52
        yield [''];
53
        yield ['sonata-project'];
54
    }
55
56
    public function testGetNormalizedIdentifierNull(): void
57
    {
58
        $registry = $this->createMock(ManagerRegistry::class);
59
60
        $model = new ModelManager($registry);
61
62
        $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...
63
    }
64
}
65