Completed
Pull Request — develop (#591)
by Alejandro
04:24
created

DeprecatedConfigParserTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 40
dl 0
loc 98
rs 10
c 2
b 0
f 0
wmc 6

6 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
A removesTheOldSecretKey() 0 14 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
    private DeprecatedConfigParser $postProcessor;
15
16
    public function setUp(): void
17
    {
18
        $this->postProcessor = new DeprecatedConfigParser();
19
    }
20
21
    /** @test */
22
    public function returnsConfigAsIsIfNewValueIsDefined(): void
23
    {
24
        $config = [
25
            'not_found_redirects' => [
26
                'invalid_short_url' => 'somewhere',
27
            ],
28
        ];
29
30
        $result = ($this->postProcessor)($config);
31
32
        $this->assertEquals($config, $result);
33
    }
34
35
    /** @test */
36
    public function doesNotProvideNewConfigIfOldOneIsDefinedButDisabled(): void
37
    {
38
        $config = [
39
            'url_shortener' => [
40
                'not_found_short_url' => [
41
                    'enable_redirection' => false,
42
                    'redirect_to' => 'somewhere',
43
                ],
44
            ],
45
        ];
46
47
        $result = ($this->postProcessor)($config);
48
49
        $this->assertEquals($config, $result);
50
    }
51
52
    /** @test */
53
    public function mapsOldConfigToNewOneWhenOldOneIsEnabled(): void
54
    {
55
        $config = [
56
            'url_shortener' => [
57
                'not_found_short_url' => [
58
                    'enable_redirection' => true,
59
                    'redirect_to' => 'somewhere',
60
                ],
61
            ],
62
        ];
63
        $expected = array_merge($config, [
64
            'not_found_redirects' => [
65
                'invalid_short_url' => 'somewhere',
66
            ],
67
        ]);
68
69
        $result = ($this->postProcessor)($config);
70
71
        $this->assertEquals($expected, $result);
72
    }
73
74
    /** @test */
75
    public function definesNewConfigAsNullIfOldOneIsEnabledWithNoRedirectValue(): void
76
    {
77
        $config = [
78
            'url_shortener' => [
79
                'not_found_short_url' => [
80
                    'enable_redirection' => true,
81
                ],
82
            ],
83
        ];
84
        $expected = array_merge($config, [
85
            'not_found_redirects' => [
86
                'invalid_short_url' => null,
87
            ],
88
        ]);
89
90
        $result = ($this->postProcessor)($config);
91
92
        $this->assertEquals($expected, $result);
93
    }
94
95
    /** @test */
96
    public function removesTheOldSecretKey(): void
97
    {
98
        $config = [
99
            'app_options' => [
100
                'secret_key' => 'foobar',
101
            ],
102
        ];
103
        $expected = [
104
            'app_options' => [],
105
        ];
106
107
        $result = ($this->postProcessor)($config);
108
109
        $this->assertEquals($expected, $result);
110
    }
111
}
112