Passed
Pull Request — master (#30)
by Dmitriy
21:12 queued 06:11
created

ConfigMergeHelperTest::replaceArrayValueProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 19
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Composer\Config\Tests\Unit\Util;
6
7
use PHPUnit\Framework\TestCase;
8
use Yiisoft\Arrays\ReplaceArrayValue;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Arrays\ReplaceArrayValue was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Yiisoft\Arrays\UnsetArrayValue;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Arrays\UnsetArrayValue was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Yiisoft\Composer\Config\Util\ConfigMergeHelper;
11
12
final class ConfigMergeHelperTest extends TestCase
13
{
14
    /**
15
     * @dataProvider replaceValuesProvider()
16
     * @dataProvider mergeValuesProvider()
17
     * @dataProvider replaceArrayValueProvider()
18
     * @dataProvider unsetArrayValueProvider()
19
     * @dataProvider emptyValuesProvider()
20
     * @param array $arraysToMerge
21
     * @param array $expected
22
     */
23
    public function testMerge(array $arraysToMerge, array $expected): void
24
    {
25
        $actual = ConfigMergeHelper::mergeConfig(...$arraysToMerge);
26
        $this->assertEquals($expected, $actual);
27
    }
28
29
    public function replaceValuesProvider(): array
30
    {
31
        return [
32
            [
33
                [
34
                    [1],
35
                    [1],
36
                ],
37
                [1],
38
            ],
39
            [
40
                [
41
                    [1, 2, 3],
42
                    [1, 2, 3],
43
                ],
44
                [1, 2, 3],
45
            ],
46
            [
47
                [
48
                    ['key' => 'value'],
49
                    ['key' => 'value2'],
50
                ],
51
                [
52
                    'key' => 'value2',
53
                ],
54
            ],
55
        ];
56
    }
57
58
    public function mergeValuesProvider(): array
59
    {
60
        return [
61
            [
62
                [
63
                    [1, 2, 3],
64
                    [4, 5, 6],
65
                ],
66
                [1, 2, 3, 4, 5, 6],
67
            ],
68
            [
69
                [
70
                    [['key' => 'value']],
71
                    [['key' => 'value2']],
72
                ],
73
                [
74
                    ['key' => 'value'],
75
                    ['key' => 'value2'],
76
                ],
77
            ],
78
            [
79
                [
80
                    ['key' => ['value']],
81
                    ['key' => ['value2']],
82
                ],
83
                [
84
                    'key' => ['value', 'value2'],
85
                ],
86
            ],
87
        ];
88
    }
89
90
    public function replaceArrayValueProvider(): array
91
    {
92
        return [
93
            [
94
                [
95
                    ['key' => ['value']],
96
                    ['key' => new ReplaceArrayValue('replaced')],
97
                ],
98
                [
99
                    'key' => 'replaced',
100
                ],
101
            ],
102
            [
103
                [
104
                    ['key' => ['value']],
105
                    ['key' => [new ReplaceArrayValue('replaced')]],
106
                ],
107
                [
108
                    'key' => ['replaced'],
109
                ],
110
            ],
111
        ];
112
    }
113
114
    public function unsetArrayValueProvider(): array
115
    {
116
        return [
117
            [
118
                [
119
                    ['key' => ['value']],
120
                    ['key' => new UnsetArrayValue()],
121
                ],
122
                [],
123
            ],
124
            [
125
                [
126
                    ['key' => ['value']],
127
                    ['key' => [new UnsetArrayValue()]],
128
                ],
129
                [
130
                    'key' => [],
131
                ],
132
            ],
133
        ];
134
    }
135
136
    public function emptyValuesProvider(): array
137
    {
138
        return [
139
            [
140
                [],
141
                [],
142
            ],
143
            [
144
                [
145
                    [],
146
                ],
147
                [],
148
            ],
149
            [
150
                [
151
                    [],
152
                    [],
153
                ],
154
                [],
155
            ],
156
        ];
157
    }
158
}
159