Completed
Pull Request — master (#242)
by Alejandro
01:36
created

pathExistsReturnsExpectedValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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