PathCollectionTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 30
dl 0
loc 66
rs 10
c 1
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getValueInPathReturnsExpectedValue() 0 3 1
A providePaths() 0 10 1
A setUp() 0 11 1
A providePathsWithValue() 0 16 1
A pathExistsReturnsExpectedValue() 0 3 1
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