NsArrayPrinterTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 30
dl 0
loc 80
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A arrayProvider() 0 65 1
A testPrintArray() 0 4 1
1
<?php
2
declare(strict_types=1);
3
4
namespace SlayerBirden\DFCodeGeneration\Code\Printer;
5
6
use Nette\PhpGenerator\PhpLiteral;
7
use Nette\PhpGenerator\PhpNamespace;
8
use PHPUnit\Framework\TestCase;
9
10
class A
11
{
12
    public $a;
13
    public static function __set_state($an_array)
14
    {
15
        $obj = new A();
16
        $obj->a = $an_array['a'];
17
        return $obj;
18
    }
19
}
20
21
final class NsArrayPrinterTest extends TestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
22
{
23
    /**
24
     * @param array $testedArray
25
     * @param PhpNamespace $namespace
26
     * @param string $expected
27
     *
28
     * @dataProvider arrayProvider
29
     */
30
    public function testPrintArray(array $testedArray, PhpNamespace $namespace, string $expected): void
31
    {
32
        $printer = new NsArrayPrinter($namespace);
33
        $this->assertSame($expected, $printer->printArray($testedArray));
34
    }
35
36
    public function arrayProvider(): array
37
    {
38
        $ns = new PhpNamespace('bar');
39
        $ns->addUse('A\B\C');
40
41
        return [
42
            [
43
                [1, 2, 3],
44
                $ns,
45
                <<<ARRAY
46
[
47
    1,
48
    2,
49
    3,
50
],
51
52
ARRAY
53
54
            ],
55
            [
56
                [1, ['a' => 'b'], new PhpLiteral('const')],
57
                $ns,
58
                <<<ARRAY
59
[
60
    1,
61
    [
62
        'a' => 'b',
63
    ],
64
    const,
65
],
66
67
ARRAY
68
69
            ],
70
            [
71
                [1, ['a' => 'b', 2]],
72
                $ns,
73
                <<<ARRAY
74
[
75
    1,
76
    [
77
        'a' => 'b',
78
        0 => 2,
79
    ],
80
],
81
82
ARRAY
83
84
            ],
85
            [
86
                ['A\B\C::class', '\A\B\D::class'],
87
                $ns,
88
                <<<ARRAY
89
[
90
    C::class,
91
    \A\B\D::class,
92
],
93
94
ARRAY
95
96
            ],
97
            [
98
                ['{id:\d+}'],
99
                $ns,
100
                <<<ARRAY
101
[
102
    '{id:\d+}',
103
],
104
105
ARRAY
106
107
            ],
108
        ];
109
    }
110
}
111