Completed
Pull Request — master (#404)
by Alejandro
06:26
created

properlyMapsSimplifiedConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 71
Code Lines 47

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 47
dl 0
loc 71
rs 9.1563
c 0
b 0
f 0
cc 1
nc 1
nop 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\ConfigPostProcessor;
8
9
use function array_merge;
10
11
class ConfigPostProcessorTest extends TestCase
12
{
13
    private $postProcessor;
14
15
    public function setUp(): void
16
    {
17
        $this->postProcessor = new ConfigPostProcessor();
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
            'locale' => 'es',
43
            'not_found_redirect_to' => 'foobar.com',
44
            'db_config' => [
45
                'dbname' => 'shlink',
46
                'user' => 'foo',
47
                'password' => 'bar',
48
                'port' => '1234',
49
            ],
50
        ];
51
        $expected = [
52
            'app_options' => [
53
                'disable_track_param' => 'bar',
54
            ],
55
56
            'entity_manager' => [
57
                'connection' => [
58
                    'driver' => 'mysql',
59
                    'host' => 'shlink_db',
60
                    'dbname' => 'shlink',
61
                    'user' => 'foo',
62
                    'password' => 'bar',
63
                    'port' => '1234',
64
                ],
65
            ],
66
67
            'url_shortener' => [
68
                'domain' => [
69
                    'schema' => 'https',
70
                    'hostname' => 'doma.in',
71
                ],
72
                'validate_url' => false,
73
                'not_found_short_url' => [
74
                    'redirect_to' => 'foobar.com',
75
                    'enable_redirection' => true,
76
                ],
77
            ],
78
79
            'translator' => [
80
                'locale' => 'es',
81
            ],
82
83
            'delete_short_urls' => [
84
                'visits_threshold' => 50,
85
                'check_visits_threshold' => true,
86
            ],
87
        ];
88
89
        $result = ($this->postProcessor)(array_merge($config, $simplified));
90
91
        $this->assertEquals(array_merge($expected, $simplified), $result);
92
    }
93
}
94