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

SimplifiedConfigParserTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
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\SimplifiedConfigParser;
8
9
use function array_merge;
10
11
class SimplifiedConfigParserTest extends TestCase
12
{
13
    private $postProcessor;
14
15
    public function setUp(): void
16
    {
17
        $this->postProcessor = new SimplifiedConfigParser();
18
    }
19
20
    /** @test */
21
    public function properlyMapsSimplifiedConfig(): void
22
    {
23
        $config = [
24
            'app_options' => [
25
                'disable_track_param' => 'foo',
26
            ],
27
28
            'entity_manager' => [
29
                'connection' => [
30
                    'driver' => 'mysql',
31
                    'host' => 'shlink_db',
32
                    'port' => '3306',
33
                ],
34
            ],
35
        ];
36
        $simplified = [
37
            'disable_track_param' => 'bar',
38
            'short_domain_schema' => 'https',
39
            'short_domain_host' => 'doma.in',
40
            'validate_url' => false,
41
            'delete_short_url_threshold' => 50,
42
            'not_found_redirect_to' => 'foobar.com',
43
            'redis_servers' => [
44
                'tcp://1.1.1.1:1111',
45
                'tcp://1.2.2.2:2222',
46
            ],
47
            'db_config' => [
48
                'dbname' => 'shlink',
49
                'user' => 'foo',
50
                'password' => 'bar',
51
                'port' => '1234',
52
            ],
53
            'base_path' => '/foo/bar',
54
        ];
55
        $expected = [
56
            'app_options' => [
57
                'disable_track_param' => 'bar',
58
            ],
59
60
            'entity_manager' => [
61
                'connection' => [
62
                    'driver' => 'mysql',
63
                    'host' => 'shlink_db',
64
                    'dbname' => 'shlink',
65
                    'user' => 'foo',
66
                    'password' => 'bar',
67
                    'port' => '1234',
68
                ],
69
            ],
70
71
            'url_shortener' => [
72
                'domain' => [
73
                    'schema' => 'https',
74
                    'hostname' => 'doma.in',
75
                ],
76
                'validate_url' => false,
77
                'not_found_short_url' => [
78
                    'redirect_to' => 'foobar.com',
79
                    'enable_redirection' => true,
80
                ],
81
            ],
82
83
            'delete_short_urls' => [
84
                'visits_threshold' => 50,
85
                'check_visits_threshold' => true,
86
            ],
87
88
            'dependencies' => [
89
                'aliases' => [
90
                    'lock_store' => 'redis_lock_store',
91
                ],
92
            ],
93
94
            'redis' => [
95
                'servers' => [
96
                    'tcp://1.1.1.1:1111',
97
                    'tcp://1.2.2.2:2222',
98
                ],
99
            ],
100
101
            'router' => [
102
                'base_path' => '/foo/bar',
103
            ],
104
        ];
105
106
        $result = ($this->postProcessor)(array_merge($config, $simplified));
107
108
        $this->assertEquals(array_merge($expected, $simplified), $result);
109
    }
110
}
111