Completed
Push — 1.1 ( 9d9074...b5b13c )
by Kamil
23:25
created

ThemeConfigurationTest   A

Complexity

Total Complexity 23

Size/Duplication

Total Lines 372
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 23
lcom 0
cbo 1
dl 0
loc 372
c 0
b 0
f 0
rs 10

23 Methods

Rating   Name   Duplication   Size   Complexity  
A it_requires_only_name() 0 10 1
A its_name_is_required_and_cannot_be_empty() 0 16 1
A its_title_is_optional_but_cannot_be_empty() 0 16 1
A its_description_is_optional_but_cannot_be_empty() 0 16 1
A its_path_is_optional_but_cannot_be_empty() 0 16 1
A its_authors_are_optional() 0 9 1
A its_author_can_have_only_name_email_homepage_and_role_properties() 0 37 1
A its_author_must_have_at_least_one_property() 0 10 1
A its_authors_replaces_other_authors_defined_elsewhere() 0 11 1
A it_ignores_undefined_root_level_fields() 0 8 1
A its_parents_are_optional_but_has_to_have_at_least_one_element() 0 16 1
A its_parent_is_strings() 0 9 1
A its_parent_cannot_be_empty() 0 9 1
A its_parents_replaces_other_parents_defined_elsewhere() 0 11 1
A its_screenshots_are_strings() 0 9 1
A its_screenshots_are_optional() 0 9 1
A its_screenshots_must_have_at_least_one_element() 0 9 1
A its_screenshots_cannot_be_empty() 0 9 1
A its_screenshots_replaces_other_screenshots_defined_elsewhere() 0 11 1
A its_screenshots_are_an_array() 0 9 1
A its_screenshots_must_have_a_path() 0 9 1
A its_screenshots_have_optional_title_and_description() 0 13 1
A getConfiguration() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Sylius\Bundle\ThemeBundle\Tests\Configuration;
15
16
use Matthias\SymfonyConfigTest\PhpUnit\ConfigurationTestCaseTrait;
17
use PHPUnit\Framework\TestCase;
18
use Sylius\Bundle\ThemeBundle\Configuration\ThemeConfiguration;
19
use Symfony\Component\Config\Definition\ConfigurationInterface;
20
21
final class ThemeConfigurationTest extends TestCase
22
{
23
    use ConfigurationTestCaseTrait;
24
25
    /**
26
     * @test
27
     */
28
    public function it_requires_only_name(): void
29
    {
30
        $this->assertProcessedConfigurationEquals(
31
            [
32
                ['name' => 'example/sylius-theme'],
33
            ],
34
            ['name' => 'example/sylius-theme'],
35
            'name'
36
        );
37
    }
38
39
    /**
40
     * @test
41
     */
42
    public function its_name_is_required_and_cannot_be_empty(): void
43
    {
44
        $this->assertPartialConfigurationIsInvalid(
45
            [
46
                [/* no name defined */],
47
            ],
48
            'name'
49
        );
50
51
        $this->assertPartialConfigurationIsInvalid(
52
            [
53
                ['name' => ''],
54
            ],
55
            'name'
56
        );
57
    }
58
59
    /**
60
     * @test
61
     */
62
    public function its_title_is_optional_but_cannot_be_empty(): void
63
    {
64
        $this->assertPartialConfigurationIsInvalid(
65
            [
66
                ['title' => ''],
67
            ],
68
            'title'
69
        );
70
71
        $this->assertConfigurationIsValid(
72
            [
73
                ['title' => 'Lorem ipsum'],
74
            ],
75
            'title'
76
        );
77
    }
78
79
    /**
80
     * @test
81
     */
82
    public function its_description_is_optional_but_cannot_be_empty(): void
83
    {
84
        $this->assertPartialConfigurationIsInvalid(
85
            [
86
                ['description' => ''],
87
            ],
88
            'description'
89
        );
90
91
        $this->assertConfigurationIsValid(
92
            [
93
                ['description' => 'Lorem ipsum dolor sit amet'],
94
            ],
95
            'description'
96
        );
97
    }
98
99
    /**
100
     * @test
101
     */
102
    public function its_path_is_optional_but_cannot_be_empty(): void
103
    {
104
        $this->assertPartialConfigurationIsInvalid(
105
            [
106
                ['path' => ''],
107
            ],
108
            'path'
109
        );
110
111
        $this->assertConfigurationIsValid(
112
            [
113
                ['path' => '/theme/path'],
114
            ],
115
            'path'
116
        );
117
    }
118
119
    /**
120
     * @test
121
     */
122
    public function its_authors_are_optional(): void
123
    {
124
        $this->assertConfigurationIsValid(
125
            [
126
                [/* no authors defined */],
127
            ],
128
            'authors'
129
        );
130
    }
131
132
    /**
133
     * @test
134
     */
135
    public function its_author_can_have_only_name_email_homepage_and_role_properties(): void
136
    {
137
        $this->assertConfigurationIsValid(
138
            [
139
                ['authors' => [['name' => 'Kamil Kokot']]],
140
            ],
141
            'authors'
142
        );
143
144
        $this->assertConfigurationIsValid(
145
            [
146
                ['authors' => [['email' => '[email protected]']]],
147
            ],
148
            'authors'
149
        );
150
151
        $this->assertConfigurationIsValid(
152
            [
153
                ['authors' => [['homepage' => 'http://kamil.kokot.me']]],
154
            ],
155
            'authors'
156
        );
157
158
        $this->assertConfigurationIsValid(
159
            [
160
                ['authors' => [['role' => 'Developer']]],
161
            ],
162
            'authors'
163
        );
164
165
        $this->assertPartialConfigurationIsInvalid(
166
            [
167
                ['authors' => [['undefined' => '42']]],
168
            ],
169
            'authors'
170
        );
171
    }
172
173
    /**
174
     * @test
175
     */
176
    public function its_author_must_have_at_least_one_property(): void
177
    {
178
        $this->assertPartialConfigurationIsInvalid(
179
            [
180
                ['authors' => [[/* empty author */]]],
181
            ],
182
            'authors',
183
            'Author cannot be empty'
184
        );
185
    }
186
187
    /**
188
     * @test
189
     */
190
    public function its_authors_replaces_other_authors_defined_elsewhere(): void
191
    {
192
        $this->assertProcessedConfigurationEquals(
193
            [
194
                ['authors' => [['name' => 'Kamil Kokot']]],
195
                ['authors' => [['name' => 'Krzysztof Krawczyk']]],
196
            ],
197
            ['authors' => [['name' => 'Krzysztof Krawczyk']]],
198
            'authors'
199
        );
200
    }
201
202
    /**
203
     * @test
204
     */
205
    public function it_ignores_undefined_root_level_fields(): void
206
    {
207
        $this->assertConfigurationIsValid(
208
            [
209
                ['name' => 'example/sylius-theme', 'undefined_variable' => '42'],
210
            ]
211
        );
212
    }
213
214
    /**
215
     * @test
216
     */
217
    public function its_parents_are_optional_but_has_to_have_at_least_one_element(): void
218
    {
219
        $this->assertConfigurationIsValid(
220
            [
221
                [],
222
            ],
223
            'parents'
224
        );
225
226
        $this->assertPartialConfigurationIsInvalid(
227
            [
228
                ['parents' => [/* no elements */]],
229
            ],
230
            'parents'
231
        );
232
    }
233
234
    /**
235
     * @test
236
     */
237
    public function its_parent_is_strings(): void
238
    {
239
        $this->assertConfigurationIsValid(
240
            [
241
                ['parents' => ['example/parent-theme', 'example/parent-theme-2']],
242
            ],
243
            'parents'
244
        );
245
    }
246
247
    /**
248
     * @test
249
     */
250
    public function its_parent_cannot_be_empty(): void
251
    {
252
        $this->assertPartialConfigurationIsInvalid(
253
            [
254
                ['parents' => ['']],
255
            ],
256
            'parents'
257
        );
258
    }
259
260
    /**
261
     * @test
262
     */
263
    public function its_parents_replaces_other_parents_defined_elsewhere(): void
264
    {
265
        $this->assertProcessedConfigurationEquals(
266
            [
267
                ['parents' => ['example/first-theme']],
268
                ['parents' => ['example/second-theme']],
269
            ],
270
            ['parents' => ['example/second-theme']],
271
            'parents'
272
        );
273
    }
274
275
    /**
276
     * @test
277
     */
278
    public function its_screenshots_are_strings(): void
279
    {
280
        $this->assertConfigurationIsValid(
281
            [
282
                ['screenshots' => ['screenshot/krzysztof-krawczyk.jpg', 'screenshot/ryszard-rynkowski.jpg']],
283
            ],
284
            'screenshots'
285
        );
286
    }
287
288
    /**
289
     * @test
290
     */
291
    public function its_screenshots_are_optional(): void
292
    {
293
        $this->assertConfigurationIsValid(
294
            [
295
                [/* no screenshots defined */],
296
            ],
297
            'screenshots'
298
        );
299
    }
300
301
    /**
302
     * @test
303
     */
304
    public function its_screenshots_must_have_at_least_one_element(): void
305
    {
306
        $this->assertPartialConfigurationIsInvalid(
307
            [
308
                ['screenshots' => [/* no elements */]],
309
            ],
310
            'screenshots'
311
        );
312
    }
313
314
    /**
315
     * @test
316
     */
317
    public function its_screenshots_cannot_be_empty(): void
318
    {
319
        $this->assertPartialConfigurationIsInvalid(
320
            [
321
                ['screenshots' => ['']],
322
            ],
323
            'screenshots'
324
        );
325
    }
326
327
    /**
328
     * @test
329
     */
330
    public function its_screenshots_replaces_other_screenshots_defined_elsewhere(): void
331
    {
332
        $this->assertProcessedConfigurationEquals(
333
            [
334
                ['screenshots' => ['screenshot/zbigniew-holdys.jpg']],
335
                ['screenshots' => ['screenshot/maryla-rodowicz.jpg']],
336
            ],
337
            ['screenshots' => [['path' => 'screenshot/maryla-rodowicz.jpg']]],
338
            'screenshots'
339
        );
340
    }
341
342
    /**
343
     * @test
344
     */
345
    public function its_screenshots_are_an_array(): void
346
    {
347
        $this->assertConfigurationIsValid(
348
            [
349
                ['screenshots' => [['path' => 'screenshot/rick-astley.jpg']]],
350
            ],
351
            'screenshots'
352
        );
353
    }
354
355
    /**
356
     * @test
357
     */
358
    public function its_screenshots_must_have_a_path(): void
359
    {
360
        $this->assertPartialConfigurationIsInvalid(
361
            [
362
                ['screenshots' => [['title' => 'Candy shop']]],
363
            ],
364
            'screenshots'
365
        );
366
    }
367
368
    /**
369
     * @test
370
     */
371
    public function its_screenshots_have_optional_title_and_description(): void
372
    {
373
        $this->assertConfigurationIsValid(
374
            [
375
                ['screenshots' => [[
376
                    'path' => 'screenshot/rick-astley.jpg',
377
                    'title' => 'Rick Astley',
378
                    'description' => 'He\'ll never gonna give you up or let you down',
379
                ]]],
380
            ],
381
            'screenshots'
382
        );
383
    }
384
385
    /**
386
     * {@inheritdoc}
387
     */
388
    protected function getConfiguration(): ConfigurationInterface
389
    {
390
        return new ThemeConfiguration();
391
    }
392
}
393