Completed
Push — master ( fb684b...d17533 )
by Alejandro
21s queued 12s
created

properlyMapsSimplifiedConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 83
Code Lines 54

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 54
nc 1
nop 0
dl 0
loc 83
rs 9.0036
c 2
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
declare(strict_types=1);
3
4
namespace ShlinkioTest\Shlink\Core;
5
6
use PHPUnit\Framework\TestCase;
7
use Shlinkio\Shlink\Core\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
        ];
54
        $expected = [
55
            'app_options' => [
56
                'disable_track_param' => 'bar',
57
            ],
58
59
            'entity_manager' => [
60
                'connection' => [
61
                    'driver' => 'mysql',
62
                    'host' => 'shlink_db',
63
                    'dbname' => 'shlink',
64
                    'user' => 'foo',
65
                    'password' => 'bar',
66
                    'port' => '1234',
67
                ],
68
            ],
69
70
            'url_shortener' => [
71
                'domain' => [
72
                    'schema' => 'https',
73
                    'hostname' => 'doma.in',
74
                ],
75
                'validate_url' => false,
76
                'not_found_short_url' => [
77
                    'redirect_to' => 'foobar.com',
78
                    'enable_redirection' => true,
79
                ],
80
            ],
81
82
            'delete_short_urls' => [
83
                'visits_threshold' => 50,
84
                'check_visits_threshold' => true,
85
            ],
86
87
            'dependencies' => [
88
                'aliases' => [
89
                    'lock_store' => 'redis_lock_store',
90
                ],
91
            ],
92
93
            'redis' => [
94
                'servers' => [
95
                    'tcp://1.1.1.1:1111',
96
                    'tcp://1.2.2.2:2222',
97
                ],
98
            ],
99
        ];
100
101
        $result = ($this->postProcessor)(array_merge($config, $simplified));
102
103
        $this->assertEquals(array_merge($expected, $simplified), $result);
104
    }
105
}
106