Passed
Pull Request — master (#485)
by Alejandro
06:11 queued 14s
created

BasePathPrefixerTest::provideConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 45
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 25
nc 1
nop 0
dl 0
loc 45
rs 9.52
c 2
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace ShlinkioTest\Shlink\Core\Config;
5
6
use PHPUnit\Framework\TestCase;
7
use Shlinkio\Shlink\Core\Config\BasePathPrefixer;
8
9
class BasePathPrefixerTest extends TestCase
10
{
11
    /** @var BasePathPrefixer */
12
    private $prefixer;
13
14
    public function setUp(): void
15
    {
16
        $this->prefixer = new BasePathPrefixer();
17
    }
18
19
    /**
20
     * @test
21
     * @dataProvider provideConfig
22
     */
23
    public function parsesConfigAsExpected(
24
        array $originalConfig,
25
        array $expectedRoutes,
26
        array $expectedMiddlewares,
27
        string $expectedHostname
28
    ): void {
29
        [
30
            'routes' => $routes,
31
            'middleware_pipeline' => $middlewares,
32
            'url_shortener' => $urlShortener,
33
        ] = ($this->prefixer)($originalConfig);
34
35
        $this->assertEquals($expectedRoutes, $routes);
36
        $this->assertEquals($expectedMiddlewares, $middlewares);
37
        $this->assertEquals([
38
            'domain' => [
39
                'hostname' => $expectedHostname,
40
            ],
41
        ], $urlShortener);
42
    }
43
44
    public function provideConfig(): iterable
45
    {
46
        $urlShortener = [
47
            'domain' => [
48
                'hostname' => null,
49
            ],
50
        ];
51
52
        yield 'without anything' => [['url_shortener' => $urlShortener], [], [], ''];
53
        yield 'with empty options' => [
54
            [
55
                'routes' => [],
56
                'middleware_pipeline' => [],
57
                'url_shortener' => $urlShortener,
58
            ],
59
            [],
60
            [],
61
            '',
62
        ];
63
        yield 'with non-empty options' => [
64
            [
65
                'routes' => [
66
                    ['path' => '/something'],
67
                    ['path' => '/something-else'],
68
                ],
69
                'middleware_pipeline' => [
70
                    ['with' => 'no_path'],
71
                    ['path' => '/rest', 'middleware' => []],
72
                ],
73
                'url_shortener' => [
74
                    'domain' => [
75
                        'hostname' => 'doma.in',
76
                    ],
77
                ],
78
                'router' => ['base_path' => '/foo/bar'],
79
            ],
80
            [
81
                ['path' => '/foo/bar/something'],
82
                ['path' => '/foo/bar/something-else'],
83
            ],
84
            [
85
                ['with' => 'no_path'],
86
                ['path' => '/foo/bar/rest', 'middleware' => []],
87
            ],
88
            'doma.in/foo/bar',
89
        ];
90
    }
91
}
92