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 spec\Sylius\Bundle\ThemeBundle\Loader; |
15
|
|
|
|
16
|
|
|
use PhpSpec\ObjectBehavior; |
17
|
|
|
use Prophecy\Argument; |
18
|
|
|
use Sylius\Bundle\ThemeBundle\Configuration\ConfigurationProviderInterface; |
19
|
|
|
use Sylius\Bundle\ThemeBundle\Factory\ThemeAuthorFactoryInterface; |
20
|
|
|
use Sylius\Bundle\ThemeBundle\Factory\ThemeFactoryInterface; |
21
|
|
|
use Sylius\Bundle\ThemeBundle\Factory\ThemeScreenshotFactoryInterface; |
22
|
|
|
use Sylius\Bundle\ThemeBundle\Loader\CircularDependencyCheckerInterface; |
23
|
|
|
use Sylius\Bundle\ThemeBundle\Loader\CircularDependencyFoundException; |
24
|
|
|
use Sylius\Bundle\ThemeBundle\Loader\ThemeLoaderInterface; |
25
|
|
|
use Sylius\Bundle\ThemeBundle\Loader\ThemeLoadingFailedException; |
26
|
|
|
use Sylius\Bundle\ThemeBundle\Model\ThemeAuthor; |
27
|
|
|
use Sylius\Bundle\ThemeBundle\Model\ThemeInterface; |
28
|
|
|
use Sylius\Bundle\ThemeBundle\Model\ThemeScreenshot; |
29
|
|
|
use Zend\Hydrator\HydrationInterface; |
30
|
|
|
|
31
|
|
|
final class ThemeLoaderSpec extends ObjectBehavior |
32
|
|
|
{ |
33
|
|
|
function let( |
34
|
|
|
ConfigurationProviderInterface $configurationProvider, |
35
|
|
|
ThemeFactoryInterface $themeFactory, |
36
|
|
|
ThemeAuthorFactoryInterface $themeAuthorFactory, |
37
|
|
|
ThemeScreenshotFactoryInterface $themeScreenshotFactory, |
38
|
|
|
HydrationInterface $themeHydrator, |
39
|
|
|
CircularDependencyCheckerInterface $circularDependencyChecker |
40
|
|
|
): void { |
41
|
|
|
$this->beConstructedWith( |
42
|
|
|
$configurationProvider, |
43
|
|
|
$themeFactory, |
44
|
|
|
$themeAuthorFactory, |
45
|
|
|
$themeScreenshotFactory, |
46
|
|
|
$themeHydrator, |
47
|
|
|
$circularDependencyChecker |
48
|
|
|
); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
function it_implements_theme_loader_interface(): void |
52
|
|
|
{ |
53
|
|
|
$this->shouldImplement(ThemeLoaderInterface::class); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
function it_loads_a_single_theme( |
57
|
|
|
ConfigurationProviderInterface $configurationProvider, |
58
|
|
|
ThemeFactoryInterface $themeFactory, |
59
|
|
|
HydrationInterface $themeHydrator, |
60
|
|
|
CircularDependencyCheckerInterface $circularDependencyChecker, |
61
|
|
|
ThemeInterface $theme |
62
|
|
|
): void { |
63
|
|
|
$configurationProvider->getConfigurations()->willReturn([ |
64
|
|
|
[ |
65
|
|
|
'name' => 'first/theme', |
66
|
|
|
'path' => '/theme/path', |
67
|
|
|
'parents' => [], |
68
|
|
|
'authors' => [], |
69
|
|
|
'screenshots' => [], |
70
|
|
|
], |
71
|
|
|
]); |
72
|
|
|
|
73
|
|
|
$themeFactory->create('first/theme', '/theme/path')->willReturn($theme); |
|
|
|
|
74
|
|
|
|
75
|
|
|
$themeHydrator->hydrate([ |
76
|
|
|
'name' => 'first/theme', |
77
|
|
|
'path' => '/theme/path', |
78
|
|
|
'parents' => [], |
79
|
|
|
'authors' => [], |
80
|
|
|
'screenshots' => [], |
81
|
|
|
], $theme)->willReturn($theme); |
82
|
|
|
|
83
|
|
|
$circularDependencyChecker->check($theme)->shouldBeCalled(); |
84
|
|
|
|
85
|
|
|
$this->load()->shouldReturn([$theme]); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
function it_loads_a_theme_with_author( |
89
|
|
|
ConfigurationProviderInterface $configurationProvider, |
90
|
|
|
ThemeFactoryInterface $themeFactory, |
91
|
|
|
ThemeAuthorFactoryInterface $themeAuthorFactory, |
92
|
|
|
HydrationInterface $themeHydrator, |
93
|
|
|
CircularDependencyCheckerInterface $circularDependencyChecker, |
94
|
|
|
ThemeInterface $theme |
95
|
|
|
): void { |
96
|
|
|
$themeAuthor = new ThemeAuthor(); |
97
|
|
|
|
98
|
|
|
$configurationProvider->getConfigurations()->willReturn([ |
99
|
|
|
[ |
100
|
|
|
'name' => 'first/theme', |
101
|
|
|
'path' => '/theme/path', |
102
|
|
|
'parents' => [], |
103
|
|
|
'authors' => [['name' => 'Richard Rynkowsky']], |
104
|
|
|
'screenshots' => [], |
105
|
|
|
], |
106
|
|
|
]); |
107
|
|
|
|
108
|
|
|
$themeFactory->create('first/theme', '/theme/path')->willReturn($theme); |
|
|
|
|
109
|
|
|
$themeAuthorFactory->createFromArray(['name' => 'Richard Rynkowsky'])->willReturn($themeAuthor); |
|
|
|
|
110
|
|
|
|
111
|
|
|
$themeHydrator->hydrate([ |
112
|
|
|
'name' => 'first/theme', |
113
|
|
|
'path' => '/theme/path', |
114
|
|
|
'parents' => [], |
115
|
|
|
'authors' => [$themeAuthor], |
116
|
|
|
'screenshots' => [], |
117
|
|
|
], $theme)->willReturn($theme); |
118
|
|
|
|
119
|
|
|
$circularDependencyChecker->check($theme)->shouldBeCalled(); |
120
|
|
|
|
121
|
|
|
$this->load()->shouldReturn([$theme]); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
function it_loads_a_theme_with_screenshot( |
125
|
|
|
ConfigurationProviderInterface $configurationProvider, |
126
|
|
|
ThemeFactoryInterface $themeFactory, |
127
|
|
|
ThemeScreenshotFactoryInterface $themeScreenshotFactory, |
128
|
|
|
HydrationInterface $themeHydrator, |
129
|
|
|
CircularDependencyCheckerInterface $circularDependencyChecker, |
130
|
|
|
ThemeInterface $theme |
131
|
|
|
): void { |
132
|
|
|
$themeScreenshot = new ThemeScreenshot('screenshot/omg.jpg'); |
133
|
|
|
|
134
|
|
|
$configurationProvider->getConfigurations()->willReturn([ |
135
|
|
|
[ |
136
|
|
|
'name' => 'first/theme', |
137
|
|
|
'path' => '/theme/path', |
138
|
|
|
'parents' => [], |
139
|
|
|
'authors' => [], |
140
|
|
|
'screenshots' => [ |
141
|
|
|
['path' => 'screenshot/omg.jpg', 'title' => 'Title'], |
142
|
|
|
], |
143
|
|
|
], |
144
|
|
|
]); |
145
|
|
|
|
146
|
|
|
$themeFactory->create('first/theme', '/theme/path')->willReturn($theme); |
|
|
|
|
147
|
|
|
$themeScreenshotFactory->createFromArray(['path' => 'screenshot/omg.jpg', 'title' => 'Title'])->willReturn($themeScreenshot); |
|
|
|
|
148
|
|
|
|
149
|
|
|
$themeHydrator->hydrate([ |
150
|
|
|
'name' => 'first/theme', |
151
|
|
|
'path' => '/theme/path', |
152
|
|
|
'parents' => [], |
153
|
|
|
'authors' => [], |
154
|
|
|
'screenshots' => [$themeScreenshot], |
155
|
|
|
], $theme)->willReturn($theme); |
156
|
|
|
|
157
|
|
|
$circularDependencyChecker->check($theme)->shouldBeCalled(); |
158
|
|
|
|
159
|
|
|
$this->load()->shouldReturn([$theme]); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
function it_loads_a_theme_with_its_dependency( |
163
|
|
|
ConfigurationProviderInterface $configurationProvider, |
164
|
|
|
ThemeFactoryInterface $themeFactory, |
165
|
|
|
HydrationInterface $themeHydrator, |
166
|
|
|
CircularDependencyCheckerInterface $circularDependencyChecker, |
167
|
|
|
ThemeInterface $firstTheme, |
168
|
|
|
ThemeInterface $secondTheme |
169
|
|
|
): void { |
170
|
|
|
$configurationProvider->getConfigurations()->willReturn([ |
171
|
|
|
[ |
172
|
|
|
'name' => 'first/theme', |
173
|
|
|
'path' => '/first/theme/path', |
174
|
|
|
'parents' => ['second/theme'], |
175
|
|
|
'authors' => [], |
176
|
|
|
'screenshots' => [], |
177
|
|
|
], |
178
|
|
|
[ |
179
|
|
|
'name' => 'second/theme', |
180
|
|
|
'path' => '/second/theme/path', |
181
|
|
|
'parents' => [], |
182
|
|
|
'authors' => [], |
183
|
|
|
'screenshots' => [], |
184
|
|
|
], |
185
|
|
|
]); |
186
|
|
|
|
187
|
|
|
$themeFactory->create('first/theme', '/first/theme/path')->willReturn($firstTheme); |
|
|
|
|
188
|
|
|
$themeFactory->create('second/theme', '/second/theme/path')->willReturn($secondTheme); |
|
|
|
|
189
|
|
|
|
190
|
|
|
$themeHydrator->hydrate([ |
191
|
|
|
'name' => 'first/theme', |
192
|
|
|
'path' => '/first/theme/path', |
193
|
|
|
'parents' => [$secondTheme], |
194
|
|
|
'authors' => [], |
195
|
|
|
'screenshots' => [], |
196
|
|
|
], $firstTheme)->willReturn($firstTheme); |
197
|
|
|
$themeHydrator->hydrate([ |
198
|
|
|
'name' => 'second/theme', |
199
|
|
|
'path' => '/second/theme/path', |
200
|
|
|
'parents' => [], |
201
|
|
|
'authors' => [], |
202
|
|
|
'screenshots' => [], |
203
|
|
|
], $secondTheme)->willReturn($secondTheme); |
204
|
|
|
|
205
|
|
|
$circularDependencyChecker->check($firstTheme)->shouldBeCalled(); |
206
|
|
|
$circularDependencyChecker->check($secondTheme)->shouldBeCalled(); |
207
|
|
|
|
208
|
|
|
$this->load()->shouldReturn([$firstTheme, $secondTheme]); |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
function it_throws_an_exception_if_requires_not_existing_dependency( |
212
|
|
|
ConfigurationProviderInterface $configurationProvider, |
213
|
|
|
ThemeFactoryInterface $themeFactory, |
214
|
|
|
ThemeInterface $firstTheme |
215
|
|
|
): void { |
216
|
|
|
$configurationProvider->getConfigurations()->willReturn([ |
217
|
|
|
[ |
218
|
|
|
'name' => 'first/theme', |
219
|
|
|
'path' => '/theme/path', |
220
|
|
|
'parents' => ['second/theme'], |
221
|
|
|
'authors' => [], |
222
|
|
|
'screenshots' => [], |
223
|
|
|
], |
224
|
|
|
]); |
225
|
|
|
|
226
|
|
|
$themeFactory->create('first/theme', '/theme/path')->willReturn($firstTheme); |
|
|
|
|
227
|
|
|
|
228
|
|
|
$this |
229
|
|
|
->shouldThrow(new ThemeLoadingFailedException('Unexisting theme "second/theme" is required by "first/theme".')) |
230
|
|
|
->during('load') |
231
|
|
|
; |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
function it_throws_an_exception_if_there_is_a_circular_dependency_found( |
235
|
|
|
ConfigurationProviderInterface $configurationProvider, |
236
|
|
|
ThemeFactoryInterface $themeFactory, |
237
|
|
|
HydrationInterface $themeHydrator, |
238
|
|
|
CircularDependencyCheckerInterface $circularDependencyChecker, |
239
|
|
|
ThemeInterface $firstTheme, |
240
|
|
|
ThemeInterface $secondTheme |
241
|
|
|
): void { |
242
|
|
|
$configurationProvider->getConfigurations()->willReturn([ |
243
|
|
|
[ |
244
|
|
|
'name' => 'first/theme', |
245
|
|
|
'path' => '/first/theme/path', |
246
|
|
|
'parents' => ['second/theme'], |
247
|
|
|
'authors' => [], |
248
|
|
|
'screenshots' => [], |
249
|
|
|
], |
250
|
|
|
[ |
251
|
|
|
'name' => 'second/theme', |
252
|
|
|
'path' => '/second/theme/path', |
253
|
|
|
'parents' => ['first/theme'], |
254
|
|
|
'authors' => [], |
255
|
|
|
'screenshots' => [], |
256
|
|
|
], |
257
|
|
|
]); |
258
|
|
|
|
259
|
|
|
$themeFactory->create('first/theme', '/first/theme/path')->willReturn($firstTheme); |
|
|
|
|
260
|
|
|
$themeFactory->create('second/theme', '/second/theme/path')->willReturn($secondTheme); |
|
|
|
|
261
|
|
|
|
262
|
|
|
$themeHydrator->hydrate([ |
263
|
|
|
'name' => 'first/theme', |
264
|
|
|
'path' => '/first/theme/path', |
265
|
|
|
'parents' => [$secondTheme], |
266
|
|
|
'authors' => [], |
267
|
|
|
'screenshots' => [], |
268
|
|
|
], $firstTheme)->willReturn($firstTheme); |
269
|
|
|
$themeHydrator->hydrate([ |
270
|
|
|
'name' => 'second/theme', |
271
|
|
|
'path' => '/second/theme/path', |
272
|
|
|
'parents' => [$firstTheme], |
273
|
|
|
'authors' => [], |
274
|
|
|
'screenshots' => [], |
275
|
|
|
], $secondTheme)->willReturn($secondTheme); |
276
|
|
|
|
277
|
|
|
$circularDependencyChecker->check(Argument::cetera())->willThrow(CircularDependencyFoundException::class); |
278
|
|
|
|
279
|
|
|
$this |
280
|
|
|
->shouldThrow(new ThemeLoadingFailedException('Circular dependency found.')) |
281
|
|
|
->during('load') |
282
|
|
|
; |
283
|
|
|
} |
284
|
|
|
} |
285
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.