Failed Conditions
Push — master ( cdc595...f2bb18 )
by Adrien
02:12
created

UtilityTest.php$0 ➔ testModelToId()   A

Complexity

Conditions 1

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
c 0
b 0
f 0
dl 0
loc 26
rs 9.504

2 Methods

Rating   Name   Duplication   Size   Complexity  
A UtilityTest.php$0 ➔ __construct() 0 2 1
A UtilityTest.php$0 ➔ getEntity() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace EcodevTests\Felix;
6
7
use Ecodev\Felix\Utility;
8
use EcodevTests\Felix\Blog\Model\User;
9
use GraphQL\Doctrine\Definition\EntityID;
10
11
class UtilityTest extends \PHPUnit\Framework\TestCase
12
{
13
    public function testGetShortClassName(): void
14
    {
15
        self::assertSame('User', Utility::getShortClassName(new User()));
16
        self::assertSame('User', Utility::getShortClassName(User::class));
17
    }
18
19
    public function testModelToId(): void
20
    {
21
        $input = [
22
            3 => new \stdClass(),
23
            4 => 1,
24
            'model' => new User(),
25
            'entity' => new class() extends EntityID {
26
                public function __construct()
27
                {
28
                }
29
30
                public function getEntity()
31
                {
32
                    return 'real entity';
33
                }
34
            },
35
        ];
36
37
        $actual = Utility::entityIdToModel($input);
38
39
        $expected = $input;
40
        $expected['entity'] = 'real entity';
41
42
        self::assertSame($expected, $actual, 'keys and non model values should be preserved');
43
        self::assertNull(Utility::entityIdToModel(null));
44
        self::assertSame([], Utility::entityIdToModel([]));
45
    }
46
}
47