Passed
Pull Request — master (#526)
by Alejandro
06:41
created

DeprecatedConfigParserTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A doesNotProvideNewConfigIfOldOneIsDefinedButDisabled() 0 14 1
A setUp() 0 3 1
A returnsConfigAsIsIfNewValueIsDefined() 0 11 1
A mapsOldConfigToNewOneWhenOldOneIsEnabled() 0 19 1
A definesNewConfigAsNullIfOldOneIsEnabledWithNoRedirectValue() 0 18 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ShlinkioTest\Shlink\Core\Config;
6
7
use PHPUnit\Framework\TestCase;
8
use Shlinkio\Shlink\Core\Config\DeprecatedConfigParser;
9
10
use function array_merge;
11
12
class DeprecatedConfigParserTest extends TestCase
13
{
14
    /** @var DeprecatedConfigParser */
15
    private $postProcessor;
16
17
    public function setUp(): void
18
    {
19
        $this->postProcessor = new DeprecatedConfigParser();
20
    }
21
22
    /** @test */
23
    public function returnsConfigAsIsIfNewValueIsDefined(): void
24
    {
25
        $config = [
26
            'not_found_redirects' => [
27
                'invalid_short_url' => 'somewhere',
28
            ],
29
        ];
30
31
        $result = ($this->postProcessor)($config);
32
33
        $this->assertEquals($config, $result);
34
    }
35
36
    /** @test */
37
    public function doesNotProvideNewConfigIfOldOneIsDefinedButDisabled(): void
38
    {
39
        $config = [
40
            'url_shortener' => [
41
                'not_found_short_url' => [
42
                    'enable_redirection' => false,
43
                    'redirect_to' => 'somewhere',
44
                ],
45
            ],
46
        ];
47
48
        $result = ($this->postProcessor)($config);
49
50
        $this->assertEquals($config, $result);
51
    }
52
53
    /** @test */
54
    public function mapsOldConfigToNewOneWhenOldOneIsEnabled(): void
55
    {
56
        $config = [
57
            'url_shortener' => [
58
                'not_found_short_url' => [
59
                    'enable_redirection' => true,
60
                    'redirect_to' => 'somewhere',
61
                ],
62
            ],
63
        ];
64
        $expected = array_merge($config, [
65
            'not_found_redirects' => [
66
                'invalid_short_url' => 'somewhere',
67
            ],
68
        ]);
69
70
        $result = ($this->postProcessor)($config);
71
72
        $this->assertEquals($expected, $result);
73
    }
74
75
    /** @test */
76
    public function definesNewConfigAsNullIfOldOneIsEnabledWithNoRedirectValue(): void
77
    {
78
        $config = [
79
            'url_shortener' => [
80
                'not_found_short_url' => [
81
                    'enable_redirection' => true,
82
                ],
83
            ],
84
        ];
85
        $expected = array_merge($config, [
86
            'not_found_redirects' => [
87
                'invalid_short_url' => null,
88
            ],
89
        ]);
90
91
        $result = ($this->postProcessor)($config);
92
93
        $this->assertEquals($expected, $result);
94
    }
95
}
96