Completed
Push — master ( ae5e03...0447ee )
by Jeroen
10:35 queued 04:37
created

KunstmaanAdminExtensionTest   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 181
Duplicated Lines 8.84 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 15
lcom 1
cbo 3
dl 16
loc 181
rs 10
c 0
b 0
f 0

14 Methods

Rating   Name   Duplication   Size   Complexity  
A getContainerExtensions() 0 4 1
A testCorrectParametersHaveBeenSet() 0 28 1
A testWebsiteTitleWithParameterSet() 0 8 1
A testWebsiteTitleWithParameterAndConfigSet() 0 8 1
A testMultiLanguageWithParameterSet() 0 8 1
A testMultiLanguageWithParameterAndConfigSet() 8 8 1
A testMultiLanguageScalarParameter() 8 8 1
A testRequiredLocalesWithParameterSet() 0 8 1
A testRequiredLocalesWithParameterAndConfigSet() 0 8 1
A testDefaultLocaleWithParameterSet() 0 8 1
A testDefaultLocaleWithParameterAndConfigSet() 0 8 1
A testLegacyParameters() 0 9 1
A setUp() 0 8 1
A getRequiredConfig() 0 15 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Kunstmaan\AdminBundle\Tests\DependencyInjection;
4
5
use Kunstmaan\AdminBundle\DependencyInjection\KunstmaanAdminExtension;
6
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
7
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase;
8
9
/**
10
 * Class KunstmaanAdminExtensionTest
11
 */
12
class KunstmaanAdminExtensionTest extends AbstractExtensionTestCase
13
{
14
    /**
15
     * @return ExtensionInterface[]
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use KunstmaanAdminExtension[].

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
16
     */
17
    protected function getContainerExtensions()
18
    {
19
        return [new KunstmaanAdminExtension()];
20
    }
21
22
    public function testCorrectParametersHaveBeenSet()
23
    {
24
        $this->load([
25
            'dashboard_route' => true,
26
            'admin_password' => 'omgchangethis',
27
            'menu_items' => [
28
                [
29
                    'route' => 'route66',
30
                    'label' => 'Route 66',
31
                ],
32
            ],
33
            'website_title' => 'Example title',
34
            'multi_language' => true,
35
            'required_locales' => 'nl|fr|en',
36
            'default_locale' => 'nl',
37
        ]);
38
39
        $this->assertContainerBuilderHasParameter('version_checker.url', 'https://cms.kunstmaan.be/version-check');
40
        $this->assertContainerBuilderHasParameter('version_checker.timeframe', 60 * 60 * 24);
41
        $this->assertContainerBuilderHasParameter('kunstmaan_admin.admin_locales');
42
        $this->assertContainerBuilderHasParameter('kunstmaan_admin.default_admin_locale');
43
        $this->assertContainerBuilderHasParameter('kunstmaan_admin.session_security.ip_check');
44
        $this->assertContainerBuilderHasParameter('kunstmaan_admin.session_security.user_agent_check');
45
        $this->assertContainerBuilderHasParameter('kunstmaan_admin.google_signin.enabled');
46
        $this->assertContainerBuilderHasParameter('kunstmaan_admin.google_signin.client_id');
47
        $this->assertContainerBuilderHasParameter('kunstmaan_admin.google_signin.client_secret');
48
        $this->assertContainerBuilderHasParameter('kunstmaan_admin.google_signin.hosted_domains');
49
    }
50
51
    /**
52
     * @group legacy
53
     * @expectedDeprecation Not providing a value for the "kunstmaan_admin.website_title" config is deprecated since KunstmaanAdminBundle 5.2, this config value will be required in KunstmaanAdminBundle 6.0.
54
     */
55
    public function testWebsiteTitleWithParameterSet()
56
    {
57
        $this->setParameter('websitetitle', 'Mywebsite');
58
59
        $this->load($this->getRequiredConfig('website_title'));
60
61
        $this->assertContainerBuilderHasParameter('kunstmaan_admin.website_title', 'Mywebsite');
62
    }
63
64
    public function testWebsiteTitleWithParameterAndConfigSet()
65
    {
66
        $this->setParameter('websitetitle', 'Mywebsite');
67
68
        $this->load(array_merge($this->getRequiredConfig(), ['website_title' => 'My real website']));
69
70
        $this->assertContainerBuilderHasParameter('kunstmaan_admin.website_title', 'My real website');
71
    }
72
73
    /**
74
     * @group legacy
75
     * @expectedDeprecation Not providing a value for the "kunstmaan_admin.multi_language" config is deprecated since KunstmaanAdminBundle 5.2, this config value will be required in KunstmaanAdminBundle 6.0.
76
     */
77
    public function testMultiLanguageWithParameterSet()
78
    {
79
        $this->setParameter('multilanguage', true);
80
81
        $this->load($this->getRequiredConfig('multi_language'));
82
83
        $this->assertContainerBuilderHasParameter('kunstmaan_admin.multi_language', true);
84
    }
85
86 View Code Duplication
    public function testMultiLanguageWithParameterAndConfigSet()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
87
    {
88
        $this->setParameter('multilanguage', false);
89
90
        $this->load(array_merge($this->getRequiredConfig(), ['multi_language' => true]));
91
92
        $this->assertContainerBuilderHasParameter('kunstmaan_admin.multi_language', true);
93
    }
94
95
    /**
96
     * @group legacy
97
     */
98 View Code Duplication
    public function testMultiLanguageScalarParameter()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
99
    {
100
        $this->setParameter('multilanguage', true);
101
102
        $this->load(array_merge($this->getRequiredConfig(), ['multi_language' => 'randomvalue']));
103
104
        $this->assertContainerBuilderHasParameter('kunstmaan_admin.multi_language', true);
105
    }
106
107
    /**
108
     * @group legacy
109
     * @expectedDeprecation Not providing a value for the "kunstmaan_admin.required_locales" config is deprecated since KunstmaanAdminBundle 5.2, this config value will be required in KunstmaanAdminBundle 6.0.
110
     */
111
    public function testRequiredLocalesWithParameterSet()
112
    {
113
        $this->setParameter('requiredlocales', 'nl|en');
114
115
        $this->load($this->getRequiredConfig('required_locales'));
116
117
        $this->assertContainerBuilderHasParameter('kunstmaan_admin.required_locales', 'nl|en');
118
    }
119
120
    public function testRequiredLocalesWithParameterAndConfigSet()
121
    {
122
        $this->setParameter('requiredlocales', 'nl|en');
123
124
        $this->load(array_merge($this->getRequiredConfig(), ['required_locales' => 'nl|en|fr']));
125
126
        $this->assertContainerBuilderHasParameter('kunstmaan_admin.required_locales', 'nl|en|fr');
127
    }
128
129
    /**
130
     * @group legacy
131
     * @expectedDeprecation Not providing a value for the "kunstmaan_admin.default_locale" config is deprecated since KunstmaanAdminBundle 5.2, this config value will be required in KunstmaanAdminBundle 6.0.
132
     */
133
    public function testDefaultLocaleWithParameterSet()
134
    {
135
        $this->setParameter('defaultlocale', 'en');
136
137
        $this->load($this->getRequiredConfig('default_locale'));
138
139
        $this->assertContainerBuilderHasParameter('kunstmaan_admin.default_locale', 'en');
140
    }
141
142
    public function testDefaultLocaleWithParameterAndConfigSet()
143
    {
144
        $this->setParameter('defaultlocale', 'en');
145
146
        $this->load(array_merge($this->getRequiredConfig(), ['default_locale' => 'nl']));
147
148
        $this->assertContainerBuilderHasParameter('kunstmaan_admin.default_locale', 'nl');
149
    }
150
151
    /**
152
     * @group legacy
153
     * @expectedDeprecation Not providing a value for the "kunstmaan_admin.website_title" config is deprecated since KunstmaanAdminBundle 5.2, this config value will be required in KunstmaanAdminBundle 6.0.
154
     * @expectedDeprecation Not providing a value for the "kunstmaan_admin.multi_language" config is deprecated since KunstmaanAdminBundle 5.2, this config value will be required in KunstmaanAdminBundle 6.0.
155
     * @expectedDeprecation Not providing a value for the "kunstmaan_admin.required_locales" config is deprecated since KunstmaanAdminBundle 5.2, this config value will be required in KunstmaanAdminBundle 6.0.
156
     * @expectedDeprecation Not providing a value for the "kunstmaan_admin.default_locale" config is deprecated since KunstmaanAdminBundle 5.2, this config value will be required in KunstmaanAdminBundle 6.0.
157
     */
158
    public function testLegacyParameters()
159
    {
160
        $this->load();
161
162
        $this->assertContainerBuilderHasParameter('kunstmaan_admin.website_title', '');
163
        $this->assertContainerBuilderHasParameter('kunstmaan_admin.multi_language', '');
164
        $this->assertContainerBuilderHasParameter('kunstmaan_admin.required_locales', '');
165
        $this->assertContainerBuilderHasParameter('kunstmaan_admin.default_locale', '');
166
    }
167
168
    protected function setUp()
169
    {
170
        parent::setUp();
171
172
        // Some parameters required for the admin extension
173
        $this->container->setParameter('kernel.logs_dir', '/somewhere/over/the/rainbow');
174
        $this->container->setParameter('kernel.environment', 'staging');
175
    }
176
177
    private function getRequiredConfig(string $excludeKey = null)
178
    {
179
        $requiredConfig = [
180
            'website_title' => 'Example title',
181
            'multi_language' => true,
182
            'required_locales' => 'nl|fr|en',
183
            'default_locale' => 'nl',
184
        ];
185
186
        if (array_key_exists($excludeKey, $requiredConfig)) {
187
            unset($requiredConfig[$excludeKey]);
188
        }
189
190
        return $requiredConfig;
191
    }
192
}
193