SimplifiedConfigParserTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 145
Duplicated Lines 0 %

Importance

Changes 8
Bugs 0 Features 0
Metric Value
wmc 2
eloc 94
dl 0
loc 145
rs 10
c 8
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 3 1
B properlyMapsSimplifiedConfig() 0 135 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\SimplifiedConfigParser;
0 ignored issues
show
Bug introduced by
The type Shlinkio\Shlink\Core\Config\SimplifiedConfigParser was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
10
use function array_merge;
11
12
class SimplifiedConfigParserTest extends TestCase
13
{
14
    private SimplifiedConfigParser $postProcessor;
15
16
    public function setUp(): void
17
    {
18
        $this->postProcessor = new SimplifiedConfigParser();
19
    }
20
21
    /** @test */
22
    public function properlyMapsSimplifiedConfig(): void
23
    {
24
        $config = [
25
            'app_options' => [
26
                'disable_track_param' => 'foo',
27
            ],
28
29
            'entity_manager' => [
30
                'connection' => [
31
                    'driver' => 'mysql',
32
                    'host' => 'shlink_db',
33
                    'port' => '3306',
34
                ],
35
            ],
36
        ];
37
        $simplified = [
38
            'disable_track_param' => 'bar',
39
            'short_domain_schema' => 'https',
40
            'short_domain_host' => 'doma.in',
41
            'validate_url' => true,
42
            'delete_short_url_threshold' => 50,
43
            'invalid_short_url_redirect_to' => 'foobar.com',
44
            'regular_404_redirect_to' => 'bar.com',
45
            'base_url_redirect_to' => 'foo.com',
46
            'redis_servers' => [
47
                'tcp://1.1.1.1:1111',
48
                'tcp://1.2.2.2:2222',
49
            ],
50
            'db_config' => [
51
                'dbname' => 'shlink',
52
                'user' => 'foo',
53
                'password' => 'bar',
54
                'port' => '1234',
55
            ],
56
            'base_path' => '/foo/bar',
57
            'task_worker_num' => 50,
58
            'visits_webhooks' => [
59
                'http://my-api.com/api/v2.3/notify',
60
                'https://third-party.io/foo',
61
            ],
62
            'default_short_codes_length' => 8,
63
            'geolite_license_key' => 'kjh23ljkbndskj345',
64
            'mercure_public_hub_url' => 'public_url',
65
            'mercure_internal_hub_url' => 'internal_url',
66
            'mercure_jwt_secret' => 'super_secret_value',
67
            'anonymize_remote_addr' => false,
68
            'redirect_status_code' => 301,
69
            'redirect_cache_lifetime' => 90,
70
            'port' => 8888,
71
        ];
72
        $expected = [
73
            'app_options' => [
74
                'disable_track_param' => 'bar',
75
            ],
76
77
            'entity_manager' => [
78
                'connection' => [
79
                    'driver' => 'mysql',
80
                    'host' => 'shlink_db',
81
                    'dbname' => 'shlink',
82
                    'user' => 'foo',
83
                    'password' => 'bar',
84
                    'port' => '1234',
85
                ],
86
            ],
87
88
            'url_shortener' => [
89
                'domain' => [
90
                    'schema' => 'https',
91
                    'hostname' => 'doma.in',
92
                ],
93
                'validate_url' => true,
94
                'visits_webhooks' => [
95
                    'http://my-api.com/api/v2.3/notify',
96
                    'https://third-party.io/foo',
97
                ],
98
                'default_short_codes_length' => 8,
99
                'anonymize_remote_addr' => false,
100
                'redirect_status_code' => 301,
101
                'redirect_cache_lifetime' => 90,
102
            ],
103
104
            'delete_short_urls' => [
105
                'visits_threshold' => 50,
106
                'check_visits_threshold' => true,
107
            ],
108
109
            'dependencies' => [
110
                'aliases' => [
111
                    'lock_store' => 'redis_lock_store',
112
                ],
113
            ],
114
115
            'cache' => [
116
                'redis' => [
117
                    'servers' => [
118
                        'tcp://1.1.1.1:1111',
119
                        'tcp://1.2.2.2:2222',
120
                    ],
121
                ],
122
            ],
123
124
            'router' => [
125
                'base_path' => '/foo/bar',
126
            ],
127
128
            'not_found_redirects' => [
129
                'invalid_short_url' => 'foobar.com',
130
                'regular_404' => 'bar.com',
131
                'base_url' => 'foo.com',
132
            ],
133
134
            'mezzio-swoole' => [
135
                'swoole-http-server' => [
136
                    'port' => 8888,
137
                    'options' => [
138
                        'task_worker_num' => 50,
139
                    ],
140
                ],
141
            ],
142
143
            'geolite2' => [
144
                'license_key' => 'kjh23ljkbndskj345',
145
            ],
146
147
            'mercure' => [
148
                'public_hub_url' => 'public_url',
149
                'internal_hub_url' => 'internal_url',
150
                'jwt_secret' => 'super_secret_value',
151
            ],
152
        ];
153
154
        $result = ($this->postProcessor)(array_merge($config, $simplified));
155
156
        self::assertEquals(array_merge($expected, $simplified), $result);
157
    }
158
}
159