Completed
Push — master ( 50a374...a35c6f )
by Kamil
21:41
created

ThemeLoaderSpec::it_loads_a_single_theme()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 31
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 8.8571
c 0
b 0
f 0
nc 1
cc 1
eloc 22
nop 5
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
namespace spec\Sylius\Bundle\ThemeBundle\Loader;
13
14
use PhpSpec\ObjectBehavior;
15
use Prophecy\Argument;
16
use Sylius\Bundle\ThemeBundle\Configuration\ConfigurationProviderInterface;
17
use Sylius\Bundle\ThemeBundle\Factory\ThemeAuthorFactoryInterface;
18
use Sylius\Bundle\ThemeBundle\Factory\ThemeFactoryInterface;
19
use Sylius\Bundle\ThemeBundle\Factory\ThemeScreenshotFactoryInterface;
20
use Sylius\Bundle\ThemeBundle\Loader\CircularDependencyCheckerInterface;
21
use Sylius\Bundle\ThemeBundle\Loader\CircularDependencyFoundException;
22
use Sylius\Bundle\ThemeBundle\Loader\ThemeLoader;
23
use Sylius\Bundle\ThemeBundle\Loader\ThemeLoaderInterface;
24
use Sylius\Bundle\ThemeBundle\Loader\ThemeLoadingFailedException;
25
use Sylius\Bundle\ThemeBundle\Model\ThemeAuthor;
26
use Sylius\Bundle\ThemeBundle\Model\ThemeInterface;
27
use Sylius\Bundle\ThemeBundle\Model\ThemeScreenshot;
28
use Zend\Hydrator\HydrationInterface;
29
30
/**
31
 * @author Kamil Kokot <[email protected]>
32
 */
33
final class ThemeLoaderSpec extends ObjectBehavior
34
{
35
    function let(
36
        ConfigurationProviderInterface $configurationProvider,
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $configurationProvider exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
37
        ThemeFactoryInterface $themeFactory,
38
        ThemeAuthorFactoryInterface $themeAuthorFactory,
39
        ThemeScreenshotFactoryInterface $themeScreenshotFactory,
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $themeScreenshotFactory exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
40
        HydrationInterface $themeHydrator,
41
        CircularDependencyCheckerInterface $circularDependencyChecker
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $circularDependencyChecker exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
42
    ) {
43
        $this->beConstructedWith(
44
            $configurationProvider,
45
            $themeFactory,
46
            $themeAuthorFactory,
47
            $themeScreenshotFactory,
48
            $themeHydrator,
49
            $circularDependencyChecker
50
        );
51
    }
52
53
    function it_is_initializable()
54
    {
55
        $this->shouldHaveType(ThemeLoader::class);
56
    }
57
58
    function it_implements_theme_loader_interface()
59
    {
60
        $this->shouldImplement(ThemeLoaderInterface::class);
61
    }
62
63
    function it_loads_a_single_theme(
64
        ConfigurationProviderInterface $configurationProvider,
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $configurationProvider exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
65
        ThemeFactoryInterface $themeFactory,
66
        HydrationInterface $themeHydrator,
67
        CircularDependencyCheckerInterface $circularDependencyChecker,
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $circularDependencyChecker exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
68
        ThemeInterface $theme
69
    ) {
70
        $configurationProvider->getConfigurations()->willReturn([
71
            [
72
                'name' => 'first/theme',
73
                'path' => '/theme/path',
74
                'parents' => [],
75
                'authors' => [],
76
                'screenshots' => [],
77
            ],
78
        ]);
79
80
        $themeFactory->create('first/theme', '/theme/path')->willReturn($theme);
81
82
        $themeHydrator->hydrate([
83
            'name' => 'first/theme',
84
            'path' => '/theme/path',
85
            'parents' => [],
86
            'authors' => [],
87
            'screenshots' => [],
88
        ], $theme)->willReturn($theme);
89
90
        $circularDependencyChecker->check($theme)->shouldBeCalled();
91
92
        $this->load()->shouldReturn([$theme]);
93
    }
94
95
    function it_loads_a_theme_with_author(
96
        ConfigurationProviderInterface $configurationProvider,
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $configurationProvider exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
97
        ThemeFactoryInterface $themeFactory,
98
        ThemeAuthorFactoryInterface $themeAuthorFactory,
99
        HydrationInterface $themeHydrator,
100
        CircularDependencyCheckerInterface $circularDependencyChecker,
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $circularDependencyChecker exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
101
        ThemeInterface $theme
102
    ) {
103
        $themeAuthor = new ThemeAuthor();
104
105
        $configurationProvider->getConfigurations()->willReturn([
106
            [
107
                'name' => 'first/theme',
108
                'path' => '/theme/path',
109
                'parents' => [],
110
                'authors' => [['name' => 'Richard Rynkowsky']],
111
                'screenshots' => [],
112
            ]
113
        ]);
114
115
        $themeFactory->create('first/theme', '/theme/path')->willReturn($theme);
116
        $themeAuthorFactory->createFromArray(['name' => 'Richard Rynkowsky'])->willReturn($themeAuthor);
117
118
        $themeHydrator->hydrate([
119
            'name' => 'first/theme',
120
            'path' => '/theme/path',
121
            'parents' => [],
122
            'authors' => [$themeAuthor],
123
            'screenshots' => [],
124
        ], $theme)->willReturn($theme);
125
126
        $circularDependencyChecker->check($theme)->shouldBeCalled();
127
128
        $this->load()->shouldReturn([$theme]);
129
    }
130
131
    function it_loads_a_theme_with_screenshot(
132
        ConfigurationProviderInterface $configurationProvider,
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $configurationProvider exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
133
        ThemeFactoryInterface $themeFactory,
134
        ThemeScreenshotFactoryInterface $themeScreenshotFactory,
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $themeScreenshotFactory exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
135
        HydrationInterface $themeHydrator,
136
        CircularDependencyCheckerInterface $circularDependencyChecker,
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $circularDependencyChecker exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
137
        ThemeInterface $theme
138
    ) {
139
        $themeScreenshot = new ThemeScreenshot('screenshot/omg.jpg');
140
141
        $configurationProvider->getConfigurations()->willReturn([
142
            [
143
                'name' => 'first/theme',
144
                'path' => '/theme/path',
145
                'parents' => [],
146
                'authors' => [],
147
                'screenshots' => [
148
                    ['path' => 'screenshot/omg.jpg', 'title' => 'Title'],
149
                ],
150
            ],
151
        ]);
152
153
        $themeFactory->create('first/theme', '/theme/path')->willReturn($theme);
154
        $themeScreenshotFactory->createFromArray(['path' => 'screenshot/omg.jpg', 'title' => 'Title'])->willReturn($themeScreenshot);
155
156
        $themeHydrator->hydrate([
157
            'name' => 'first/theme',
158
            'path' => '/theme/path',
159
            'parents' => [],
160
            'authors' => [],
161
            'screenshots' => [$themeScreenshot],
162
        ], $theme)->willReturn($theme);
163
164
        $circularDependencyChecker->check($theme)->shouldBeCalled();
165
166
        $this->load()->shouldReturn([$theme]);
167
    }
168
169
    function it_loads_a_theme_with_its_dependency(
170
        ConfigurationProviderInterface $configurationProvider,
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $configurationProvider exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
171
        ThemeFactoryInterface $themeFactory,
172
        HydrationInterface $themeHydrator,
173
        CircularDependencyCheckerInterface $circularDependencyChecker,
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $circularDependencyChecker exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
174
        ThemeInterface $firstTheme,
175
        ThemeInterface $secondTheme
176
    ) {
177
        $configurationProvider->getConfigurations()->willReturn([
178
            [
179
                'name' => 'first/theme',
180
                'path' => '/first/theme/path',
181
                'parents' => ['second/theme'],
182
                'authors' => [],
183
                'screenshots' => [],
184
            ],
185
            [
186
                'name' => 'second/theme',
187
                'path' => '/second/theme/path',
188
                'parents' => [],
189
                'authors' => [],
190
                'screenshots' => [],
191
            ],
192
        ]);
193
194
        $themeFactory->create('first/theme', '/first/theme/path')->willReturn($firstTheme);
195
        $themeFactory->create('second/theme', '/second/theme/path')->willReturn($secondTheme);
196
197
        $themeHydrator->hydrate([
198
            'name' => 'first/theme',
199
            'path' => '/first/theme/path',
200
            'parents' => [$secondTheme],
201
            'authors' => [],
202
            'screenshots' => [],
203
        ], $firstTheme)->willReturn($firstTheme);
204
        $themeHydrator->hydrate([
205
            'name' => 'second/theme',
206
            'path' => '/second/theme/path',
207
            'parents' => [],
208
            'authors' => [],
209
            'screenshots' => [],
210
        ], $secondTheme)->willReturn($secondTheme);
211
212
        $circularDependencyChecker->check($firstTheme)->shouldBeCalled();
213
        $circularDependencyChecker->check($secondTheme)->shouldBeCalled();
214
215
        $this->load()->shouldReturn([$firstTheme, $secondTheme]);
216
    }
217
218
    function it_throws_an_exception_if_requires_not_existing_dependency(
219
        ConfigurationProviderInterface $configurationProvider,
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $configurationProvider exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
220
        ThemeFactoryInterface $themeFactory,
221
        ThemeInterface $firstTheme
222
    ) {
223
        $configurationProvider->getConfigurations()->willReturn([
224
            [
225
                'name' => 'first/theme',
226
                'path' => '/theme/path',
227
                'parents' => ['second/theme'],
228
                'authors' => [],
229
                'screenshots' => [],
230
            ],
231
        ]);
232
233
        $themeFactory->create('first/theme', '/theme/path')->willReturn($firstTheme);
234
235
        $this
236
            ->shouldThrow(new ThemeLoadingFailedException('Unexisting theme "second/theme" is required by "first/theme".'))
237
            ->during('load')
238
        ;
239
    }
240
241
    function it_throws_an_exception_if_there_is_a_circular_dependency_found(
242
        ConfigurationProviderInterface $configurationProvider,
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $configurationProvider exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
243
        ThemeFactoryInterface $themeFactory,
244
        HydrationInterface $themeHydrator,
245
        CircularDependencyCheckerInterface $circularDependencyChecker,
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $circularDependencyChecker exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
246
        ThemeInterface $firstTheme,
247
        ThemeInterface $secondTheme
248
    ) {
249
        $configurationProvider->getConfigurations()->willReturn([
250
            [
251
                'name' => 'first/theme',
252
                'path' => '/first/theme/path',
253
                'parents' => ['second/theme'],
254
                'authors' => [],
255
                'screenshots' => [],
256
            ],
257
            [
258
                'name' => 'second/theme',
259
                'path' => '/second/theme/path',
260
                'parents' => ['first/theme'],
261
                'authors' => [],
262
                'screenshots' => [],
263
            ],
264
        ]);
265
266
        $themeFactory->create('first/theme', '/first/theme/path')->willReturn($firstTheme);
267
        $themeFactory->create('second/theme', '/second/theme/path')->willReturn($secondTheme);
268
269
        $themeHydrator->hydrate([
270
            'name' => 'first/theme',
271
            'path' => '/first/theme/path',
272
            'parents' => [$secondTheme],
273
            'authors' => [],
274
            'screenshots' => [],
275
        ], $firstTheme)->willReturn($firstTheme);
276
        $themeHydrator->hydrate([
277
            'name' => 'second/theme',
278
            'path' => '/second/theme/path',
279
            'parents' => [$firstTheme],
280
            'authors' => [],
281
            'screenshots' => [],
282
        ], $secondTheme)->willReturn($secondTheme);
283
284
        $circularDependencyChecker->check(Argument::cetera())->willThrow(CircularDependencyFoundException::class);
285
286
        $this
287
            ->shouldThrow(new ThemeLoadingFailedException('Circular dependency found.'))
288
            ->during('load')
289
        ;
290
    }
291
}
292