|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace ShlinkioTest\Shlink\Config\Collection; |
|
6
|
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
|
8
|
|
|
use Shlinkio\Shlink\Config\Collection\PathCollection; |
|
9
|
|
|
|
|
10
|
|
|
class PathCollectionTest extends TestCase |
|
11
|
|
|
{ |
|
12
|
|
|
private PathCollection $collection; |
|
13
|
|
|
|
|
14
|
|
|
public function setUp(): void |
|
15
|
|
|
{ |
|
16
|
|
|
$this->collection = new PathCollection([ |
|
17
|
|
|
'foo' => [ |
|
18
|
|
|
'bar' => [ |
|
19
|
|
|
'baz' => 'Hello world!', |
|
20
|
|
|
], |
|
21
|
|
|
], |
|
22
|
|
|
'something' => [], |
|
23
|
|
|
'another' => [ |
|
24
|
|
|
'one' => 'Shlink', |
|
25
|
|
|
], |
|
26
|
|
|
]); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @test |
|
31
|
|
|
* @dataProvider providePaths |
|
32
|
|
|
*/ |
|
33
|
|
|
public function pathExistsReturnsExpectedValue(array $path, bool $expected): void |
|
34
|
|
|
{ |
|
35
|
|
|
$this->assertEquals($expected, $this->collection->pathExists($path)); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function providePaths(): iterable |
|
39
|
|
|
{ |
|
40
|
|
|
yield [[], false]; |
|
41
|
|
|
yield [['boo'], false]; |
|
42
|
|
|
yield [['foo', 'nop'], false]; |
|
43
|
|
|
yield [['another', 'one', 'nop'], false]; |
|
44
|
|
|
yield [['foo'], true]; |
|
45
|
|
|
yield [['foo', 'bar'], true]; |
|
46
|
|
|
yield [['foo', 'bar', 'baz'], true]; |
|
47
|
|
|
yield [['something'], true]; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @param mixed $expected |
|
52
|
|
|
* @test |
|
53
|
|
|
* @dataProvider providePathsWithValue |
|
54
|
|
|
*/ |
|
55
|
|
|
public function getValueInPathReturnsExpectedValue(array $path, $expected): void |
|
56
|
|
|
{ |
|
57
|
|
|
$this->assertEquals($expected, $this->collection->getValueInPath($path)); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function providePathsWithValue(): iterable |
|
61
|
|
|
{ |
|
62
|
|
|
yield [[], null]; |
|
63
|
|
|
yield [['boo'], null]; |
|
64
|
|
|
yield [['foo', 'nop'], null]; |
|
65
|
|
|
yield [['another', 'one', 'nop'], null]; |
|
66
|
|
|
yield [['foo'], [ |
|
67
|
|
|
'bar' => [ |
|
68
|
|
|
'baz' => 'Hello world!', |
|
69
|
|
|
], |
|
70
|
|
|
]]; |
|
71
|
|
|
yield [['foo', 'bar'], [ |
|
72
|
|
|
'baz' => 'Hello world!', |
|
73
|
|
|
]]; |
|
74
|
|
|
yield [['foo', 'bar', 'baz'], 'Hello world!']; |
|
75
|
|
|
yield [['something'], []]; |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|