1 | <?php |
||
28 | final class ResourceLoaderSpec extends ObjectBehavior |
||
29 | { |
||
30 | function let(RegistryInterface $resourceRegistry, RouteFactoryInterface $routeFactory): void |
||
31 | { |
||
32 | $this->beConstructedWith($resourceRegistry, $routeFactory); |
||
33 | } |
||
34 | |||
35 | function it_is_a_Symfony_routing_loader(): void |
||
|
|||
36 | { |
||
37 | $this->shouldImplement(LoaderInterface::class); |
||
38 | } |
||
39 | |||
40 | function it_processes_configuration_and_throws_exception_if_invalid(): void |
||
41 | { |
||
42 | $configuration = |
||
43 | <<<EOT |
||
44 | foo: bar |
||
45 | only: string |
||
46 | EOT; |
||
47 | |||
48 | $this |
||
49 | ->shouldThrow(InvalidConfigurationException::class) |
||
50 | ->during('load', [$configuration, 'sylius.resource']); |
||
51 | } |
||
52 | |||
53 | function it_throws_an_exception_if_invalid_resource_configured(RegistryInterface $resourceRegistry): void |
||
54 | { |
||
55 | $resourceRegistry->get('sylius.foo')->willThrow(new \InvalidArgumentException()); |
||
56 | |||
57 | $configuration = |
||
58 | <<<EOT |
||
59 | alias: sylius.foo |
||
60 | EOT; |
||
61 | |||
62 | $this |
||
63 | ->shouldThrow(\InvalidArgumentException::class) |
||
64 | ->during('load', [$configuration, 'sylius.resource']); |
||
65 | } |
||
66 | |||
67 | function it_generates_routing_based_on_resource_configuration( |
||
68 | RegistryInterface $resourceRegistry, |
||
69 | MetadataInterface $metadata, |
||
70 | RouteFactoryInterface $routeFactory, |
||
71 | RouteCollection $routeCollection, |
||
72 | Route $showRoute, |
||
73 | Route $indexRoute, |
||
74 | Route $createRoute, |
||
75 | Route $updateRoute, |
||
76 | Route $deleteRoute |
||
77 | ): void { |
||
78 | $resourceRegistry->get('sylius.product')->willReturn($metadata); |
||
79 | $metadata->getApplicationName()->willReturn('sylius'); |
||
80 | $metadata->getName()->willReturn('product'); |
||
81 | $metadata->getPluralName()->willReturn('products'); |
||
82 | $metadata->getServiceId('controller')->willReturn('sylius.controller.product'); |
||
83 | |||
84 | $routeFactory->createRouteCollection()->willReturn($routeCollection); |
||
85 | |||
86 | $configuration = |
||
87 | <<<EOT |
||
88 | alias: sylius.product |
||
89 | EOT; |
||
90 | |||
91 | $showDefaults = [ |
||
92 | '_controller' => 'sylius.controller.product:showAction', |
||
93 | '_sylius' => [ |
||
94 | 'permission' => false, |
||
95 | ], |
||
96 | ]; |
||
97 | $routeFactory->createRoute('/products/{id}', $showDefaults, [], [], '', [], ['GET'])->willReturn($showRoute); |
||
98 | $routeCollection->add('sylius_product_show', $showRoute)->shouldBeCalled(); |
||
99 | |||
100 | $indexDefaults = [ |
||
101 | '_controller' => 'sylius.controller.product:indexAction', |
||
102 | '_sylius' => [ |
||
103 | 'permission' => false, |
||
104 | ], |
||
105 | ]; |
||
106 | $routeFactory->createRoute('/products/', $indexDefaults, [], [], '', [], ['GET'])->willReturn($indexRoute); |
||
107 | $routeCollection->add('sylius_product_index', $indexRoute)->shouldBeCalled(); |
||
108 | |||
109 | $createDefaults = [ |
||
110 | '_controller' => 'sylius.controller.product:createAction', |
||
111 | '_sylius' => [ |
||
112 | 'permission' => false, |
||
113 | ], |
||
114 | ]; |
||
115 | $routeFactory->createRoute('/products/new', $createDefaults, [], [], '', [], ['GET', 'POST'])->willReturn($createRoute); |
||
116 | $routeCollection->add('sylius_product_create', $createRoute)->shouldBeCalled(); |
||
117 | |||
118 | $updateDefaults = [ |
||
119 | '_controller' => 'sylius.controller.product:updateAction', |
||
120 | '_sylius' => [ |
||
121 | 'permission' => false, |
||
122 | ], |
||
123 | ]; |
||
124 | $routeFactory->createRoute('/products/{id}/edit', $updateDefaults, [], [], '', [], ['GET', 'PUT', 'PATCH'])->willReturn($updateRoute); |
||
125 | $routeCollection->add('sylius_product_update', $updateRoute)->shouldBeCalled(); |
||
126 | |||
127 | $deleteDefaults = [ |
||
128 | '_controller' => 'sylius.controller.product:deleteAction', |
||
129 | '_sylius' => [ |
||
130 | 'permission' => false, |
||
131 | ], |
||
132 | ]; |
||
133 | $routeFactory->createRoute('/products/{id}', $deleteDefaults, [], [], '', [], ['DELETE'])->willReturn($deleteRoute); |
||
134 | $routeCollection->add('sylius_product_delete', $deleteRoute)->shouldBeCalled(); |
||
135 | |||
136 | $this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection); |
||
137 | } |
||
138 | |||
139 | function it_generates_urlized_paths_for_resources_with_multiple_words_in_name( |
||
140 | RegistryInterface $resourceRegistry, |
||
141 | MetadataInterface $metadata, |
||
142 | RouteFactoryInterface $routeFactory, |
||
143 | RouteCollection $routeCollection, |
||
144 | Route $showRoute, |
||
145 | Route $indexRoute, |
||
146 | Route $createRoute, |
||
147 | Route $updateRoute, |
||
148 | Route $deleteRoute |
||
149 | ): void { |
||
150 | $resourceRegistry->get('sylius.product_option')->willReturn($metadata); |
||
151 | $metadata->getApplicationName()->willReturn('sylius'); |
||
152 | $metadata->getName()->willReturn('product_option'); |
||
153 | $metadata->getPluralName()->willReturn('product_options'); |
||
154 | $metadata->getServiceId('controller')->willReturn('sylius.controller.product_option'); |
||
155 | |||
156 | $routeFactory->createRouteCollection()->willReturn($routeCollection); |
||
157 | |||
158 | $configuration = |
||
159 | <<<EOT |
||
160 | alias: sylius.product_option |
||
161 | EOT; |
||
162 | |||
163 | $showDefaults = [ |
||
164 | '_controller' => 'sylius.controller.product_option:showAction', |
||
165 | '_sylius' => [ |
||
166 | 'permission' => false, |
||
167 | ], |
||
168 | ]; |
||
169 | $routeFactory->createRoute('/product-options/{id}', $showDefaults, [], [], '', [], ['GET'])->willReturn($showRoute); |
||
170 | $routeCollection->add('sylius_product_option_show', $showRoute)->shouldBeCalled(); |
||
171 | |||
172 | $indexDefaults = [ |
||
173 | '_controller' => 'sylius.controller.product_option:indexAction', |
||
174 | '_sylius' => [ |
||
175 | 'permission' => false, |
||
176 | ], |
||
177 | ]; |
||
178 | $routeFactory->createRoute('/product-options/', $indexDefaults, [], [], '', [], ['GET'])->willReturn($indexRoute); |
||
179 | $routeCollection->add('sylius_product_option_index', $indexRoute)->shouldBeCalled(); |
||
180 | |||
181 | $createDefaults = [ |
||
182 | '_controller' => 'sylius.controller.product_option:createAction', |
||
183 | '_sylius' => [ |
||
184 | 'permission' => false, |
||
185 | ], |
||
186 | ]; |
||
187 | $routeFactory->createRoute('/product-options/new', $createDefaults, [], [], '', [], ['GET', 'POST'])->willReturn($createRoute); |
||
188 | $routeCollection->add('sylius_product_option_create', $createRoute)->shouldBeCalled(); |
||
189 | |||
190 | $updateDefaults = [ |
||
191 | '_controller' => 'sylius.controller.product_option:updateAction', |
||
192 | '_sylius' => [ |
||
193 | 'permission' => false, |
||
194 | ], |
||
195 | ]; |
||
196 | $routeFactory->createRoute('/product-options/{id}/edit', $updateDefaults, [], [], '', [], ['GET', 'PUT', 'PATCH'])->willReturn($updateRoute); |
||
197 | $routeCollection->add('sylius_product_option_update', $updateRoute)->shouldBeCalled(); |
||
198 | |||
199 | $deleteDefaults = [ |
||
200 | '_controller' => 'sylius.controller.product_option:deleteAction', |
||
201 | '_sylius' => [ |
||
202 | 'permission' => false, |
||
203 | ], |
||
204 | ]; |
||
205 | $routeFactory->createRoute('/product-options/{id}', $deleteDefaults, [], [], '', [], ['DELETE'])->willReturn($deleteRoute); |
||
206 | $routeCollection->add('sylius_product_option_delete', $deleteRoute)->shouldBeCalled(); |
||
207 | |||
208 | $this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection); |
||
209 | } |
||
210 | |||
211 | function it_generates_urlized_paths_for_resources_with_custom_identifier( |
||
212 | RegistryInterface $resourceRegistry, |
||
213 | MetadataInterface $metadata, |
||
214 | RouteFactoryInterface $routeFactory, |
||
215 | RouteCollection $routeCollection, |
||
216 | Route $showRoute, |
||
217 | Route $indexRoute, |
||
218 | Route $createRoute, |
||
219 | Route $updateRoute, |
||
220 | Route $deleteRoute |
||
221 | ): void { |
||
222 | $resourceRegistry->get('sylius.product_option')->willReturn($metadata); |
||
223 | $metadata->getApplicationName()->willReturn('sylius'); |
||
224 | $metadata->getName()->willReturn('product_option'); |
||
225 | $metadata->getPluralName()->willReturn('product_options'); |
||
226 | $metadata->getServiceId('controller')->willReturn('sylius.controller.product_option'); |
||
227 | |||
228 | $routeFactory->createRouteCollection()->willReturn($routeCollection); |
||
229 | |||
230 | $configuration = |
||
231 | <<<EOT |
||
232 | alias: sylius.product_option |
||
233 | identifier: code |
||
234 | criteria: |
||
235 | code: \$code |
||
236 | filterable: true |
||
237 | EOT; |
||
238 | |||
239 | $showDefaults = [ |
||
240 | '_controller' => 'sylius.controller.product_option:showAction', |
||
241 | '_sylius' => [ |
||
242 | 'permission' => false, |
||
243 | 'criteria' => [ |
||
244 | 'code' => '$code', |
||
245 | ], |
||
246 | 'filterable' => true, |
||
247 | ], |
||
248 | ]; |
||
249 | $routeFactory->createRoute('/product-options/{code}', $showDefaults, [], [], '', [], ['GET'])->willReturn($showRoute); |
||
250 | $routeCollection->add('sylius_product_option_show', $showRoute)->shouldBeCalled(); |
||
251 | |||
252 | $indexDefaults = [ |
||
253 | '_controller' => 'sylius.controller.product_option:indexAction', |
||
254 | '_sylius' => [ |
||
255 | 'permission' => false, |
||
256 | 'criteria' => [ |
||
257 | 'code' => '$code', |
||
258 | ], |
||
259 | 'filterable' => true, |
||
260 | ], |
||
261 | ]; |
||
262 | $routeFactory->createRoute('/product-options/', $indexDefaults, [], [], '', [], ['GET'])->willReturn($indexRoute); |
||
263 | $routeCollection->add('sylius_product_option_index', $indexRoute)->shouldBeCalled(); |
||
264 | |||
265 | $createDefaults = [ |
||
266 | '_controller' => 'sylius.controller.product_option:createAction', |
||
267 | '_sylius' => [ |
||
268 | 'permission' => false, |
||
269 | 'criteria' => [ |
||
270 | 'code' => '$code', |
||
271 | ], |
||
272 | 'filterable' => true, |
||
273 | ], |
||
274 | ]; |
||
275 | $routeFactory->createRoute('/product-options/new', $createDefaults, [], [], '', [], ['GET', 'POST'])->willReturn($createRoute); |
||
276 | $routeCollection->add('sylius_product_option_create', $createRoute)->shouldBeCalled(); |
||
277 | |||
278 | $updateDefaults = [ |
||
279 | '_controller' => 'sylius.controller.product_option:updateAction', |
||
280 | '_sylius' => [ |
||
281 | 'permission' => false, |
||
282 | 'criteria' => [ |
||
283 | 'code' => '$code', |
||
284 | ], |
||
285 | 'filterable' => true, |
||
286 | ], |
||
287 | ]; |
||
288 | $routeFactory->createRoute('/product-options/{code}/edit', $updateDefaults, [], [], '', [], ['GET', 'PUT', 'PATCH'])->willReturn($updateRoute); |
||
289 | $routeCollection->add('sylius_product_option_update', $updateRoute)->shouldBeCalled(); |
||
290 | |||
291 | $deleteDefaults = [ |
||
292 | '_controller' => 'sylius.controller.product_option:deleteAction', |
||
293 | '_sylius' => [ |
||
294 | 'permission' => false, |
||
295 | 'criteria' => [ |
||
296 | 'code' => '$code', |
||
297 | ], |
||
298 | 'filterable' => true, |
||
299 | ], |
||
300 | ]; |
||
301 | $routeFactory->createRoute('/product-options/{code}', $deleteDefaults, [], [], '', [], ['DELETE'])->willReturn($deleteRoute); |
||
302 | $routeCollection->add('sylius_product_option_delete', $deleteRoute)->shouldBeCalled(); |
||
303 | |||
304 | $this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection); |
||
305 | } |
||
306 | |||
307 | function it_generates_routing_with_custom_path_if_specified( |
||
308 | RegistryInterface $resourceRegistry, |
||
309 | MetadataInterface $metadata, |
||
310 | RouteFactoryInterface $routeFactory, |
||
311 | RouteCollection $routeCollection, |
||
312 | Route $showRoute, |
||
313 | Route $indexRoute, |
||
314 | Route $createRoute, |
||
315 | Route $updateRoute, |
||
316 | Route $deleteRoute |
||
317 | ): void { |
||
318 | $resourceRegistry->get('sylius.product')->willReturn($metadata); |
||
319 | $metadata->getApplicationName()->willReturn('sylius'); |
||
320 | $metadata->getName()->willReturn('product'); |
||
321 | $metadata->getPluralName()->willReturn('products'); |
||
322 | $metadata->getServiceId('controller')->willReturn('sylius.controller.product'); |
||
323 | |||
324 | $routeFactory->createRouteCollection()->willReturn($routeCollection); |
||
325 | |||
326 | $configuration = |
||
327 | <<<EOT |
||
328 | alias: sylius.product |
||
329 | path: super-duper-products |
||
330 | EOT; |
||
331 | |||
332 | $showDefaults = [ |
||
333 | '_controller' => 'sylius.controller.product:showAction', |
||
334 | '_sylius' => [ |
||
335 | 'permission' => false, |
||
336 | ], |
||
337 | ]; |
||
338 | $routeFactory->createRoute('/super-duper-products/{id}', $showDefaults, [], [], '', [], ['GET'])->willReturn($showRoute); |
||
339 | $routeCollection->add('sylius_product_show', $showRoute)->shouldBeCalled(); |
||
340 | |||
341 | $indexDefaults = [ |
||
342 | '_controller' => 'sylius.controller.product:indexAction', |
||
343 | '_sylius' => [ |
||
344 | 'permission' => false, |
||
345 | ], |
||
346 | ]; |
||
347 | $routeFactory->createRoute('/super-duper-products/', $indexDefaults, [], [], '', [], ['GET'])->willReturn($indexRoute); |
||
348 | $routeCollection->add('sylius_product_index', $indexRoute)->shouldBeCalled(); |
||
349 | |||
350 | $createDefaults = [ |
||
351 | '_controller' => 'sylius.controller.product:createAction', |
||
352 | '_sylius' => [ |
||
353 | 'permission' => false, |
||
354 | ], |
||
355 | ]; |
||
356 | $routeFactory->createRoute('/super-duper-products/new', $createDefaults, [], [], '', [], ['GET', 'POST'])->willReturn($createRoute); |
||
357 | $routeCollection->add('sylius_product_create', $createRoute)->shouldBeCalled(); |
||
358 | |||
359 | $updateDefaults = [ |
||
360 | '_controller' => 'sylius.controller.product:updateAction', |
||
361 | '_sylius' => [ |
||
362 | 'permission' => false, |
||
363 | ], |
||
364 | ]; |
||
365 | $routeFactory->createRoute('/super-duper-products/{id}/edit', $updateDefaults, [], [], '', [], ['GET', 'PUT', 'PATCH'])->willReturn($updateRoute); |
||
366 | $routeCollection->add('sylius_product_update', $updateRoute)->shouldBeCalled(); |
||
367 | |||
368 | $deleteDefaults = [ |
||
369 | '_controller' => 'sylius.controller.product:deleteAction', |
||
370 | '_sylius' => [ |
||
371 | 'permission' => false, |
||
372 | ], |
||
373 | ]; |
||
374 | $routeFactory->createRoute('/super-duper-products/{id}', $deleteDefaults, [], [], '', [], ['DELETE'])->willReturn($deleteRoute); |
||
375 | $routeCollection->add('sylius_product_delete', $deleteRoute)->shouldBeCalled(); |
||
376 | |||
377 | $this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection); |
||
378 | } |
||
379 | |||
380 | function it_generates_routing_with_custom_form_if_specified( |
||
381 | RegistryInterface $resourceRegistry, |
||
382 | MetadataInterface $metadata, |
||
383 | RouteFactoryInterface $routeFactory, |
||
384 | RouteCollection $routeCollection, |
||
385 | Route $showRoute, |
||
386 | Route $indexRoute, |
||
387 | Route $createRoute, |
||
388 | Route $updateRoute, |
||
389 | Route $deleteRoute |
||
390 | ): void { |
||
391 | $resourceRegistry->get('sylius.product')->willReturn($metadata); |
||
392 | $metadata->getApplicationName()->willReturn('sylius'); |
||
393 | $metadata->getName()->willReturn('product'); |
||
394 | $metadata->getPluralName()->willReturn('products'); |
||
395 | $metadata->getServiceId('controller')->willReturn('sylius.controller.product'); |
||
396 | |||
397 | $routeFactory->createRouteCollection()->willReturn($routeCollection); |
||
398 | |||
399 | $configuration = |
||
400 | <<<EOT |
||
401 | alias: sylius.product |
||
402 | form: sylius_product_custom |
||
403 | EOT; |
||
404 | |||
405 | $showDefaults = [ |
||
406 | '_controller' => 'sylius.controller.product:showAction', |
||
407 | '_sylius' => [ |
||
408 | 'permission' => false, |
||
409 | ], |
||
410 | ]; |
||
411 | $routeFactory->createRoute('/products/{id}', $showDefaults, [], [], '', [], ['GET'])->willReturn($showRoute); |
||
412 | $routeCollection->add('sylius_product_show', $showRoute)->shouldBeCalled(); |
||
413 | |||
414 | $indexDefaults = [ |
||
415 | '_controller' => 'sylius.controller.product:indexAction', |
||
416 | '_sylius' => [ |
||
417 | 'permission' => false, |
||
418 | ], |
||
419 | ]; |
||
420 | $routeFactory->createRoute('/products/', $indexDefaults, [], [], '', [], ['GET'])->willReturn($indexRoute); |
||
421 | $routeCollection->add('sylius_product_index', $indexRoute)->shouldBeCalled(); |
||
422 | |||
423 | $createDefaults = [ |
||
424 | '_controller' => 'sylius.controller.product:createAction', |
||
425 | '_sylius' => [ |
||
426 | 'form' => 'sylius_product_custom', |
||
427 | 'permission' => false, |
||
428 | ], |
||
429 | ]; |
||
430 | $routeFactory->createRoute('/products/new', $createDefaults, [], [], '', [], ['GET', 'POST'])->willReturn($createRoute); |
||
431 | $routeCollection->add('sylius_product_create', $createRoute)->shouldBeCalled(); |
||
432 | |||
433 | $updateDefaults = [ |
||
434 | '_controller' => 'sylius.controller.product:updateAction', |
||
435 | '_sylius' => [ |
||
436 | 'form' => 'sylius_product_custom', |
||
437 | 'permission' => false, |
||
438 | ], |
||
439 | ]; |
||
440 | $routeFactory->createRoute('/products/{id}/edit', $updateDefaults, [], [], '', [], ['GET', 'PUT', 'PATCH'])->willReturn($updateRoute); |
||
441 | $routeCollection->add('sylius_product_update', $updateRoute)->shouldBeCalled(); |
||
442 | |||
443 | $deleteDefaults = [ |
||
444 | '_controller' => 'sylius.controller.product:deleteAction', |
||
445 | '_sylius' => [ |
||
446 | 'permission' => false, |
||
447 | ], |
||
448 | ]; |
||
449 | $routeFactory->createRoute('/products/{id}', $deleteDefaults, [], [], '', [], ['DELETE'])->willReturn($deleteRoute); |
||
450 | $routeCollection->add('sylius_product_delete', $deleteRoute)->shouldBeCalled(); |
||
451 | |||
452 | $this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection); |
||
453 | } |
||
454 | |||
455 | function it_generates_routing_for_a_section( |
||
456 | RegistryInterface $resourceRegistry, |
||
457 | MetadataInterface $metadata, |
||
458 | RouteFactoryInterface $routeFactory, |
||
459 | RouteCollection $routeCollection, |
||
460 | Route $showRoute, |
||
461 | Route $indexRoute, |
||
462 | Route $createRoute, |
||
463 | Route $updateRoute, |
||
464 | Route $deleteRoute |
||
465 | ): void { |
||
466 | $resourceRegistry->get('sylius.product')->willReturn($metadata); |
||
467 | $metadata->getApplicationName()->willReturn('sylius'); |
||
468 | $metadata->getName()->willReturn('product'); |
||
469 | $metadata->getPluralName()->willReturn('products'); |
||
470 | $metadata->getServiceId('controller')->willReturn('sylius.controller.product'); |
||
471 | |||
472 | $routeFactory->createRouteCollection()->willReturn($routeCollection); |
||
473 | |||
474 | $configuration = |
||
475 | <<<EOT |
||
476 | alias: sylius.product |
||
477 | section: admin |
||
478 | EOT; |
||
479 | |||
480 | $showDefaults = [ |
||
481 | '_controller' => 'sylius.controller.product:showAction', |
||
482 | '_sylius' => [ |
||
483 | 'section' => 'admin', |
||
484 | 'permission' => false, |
||
485 | ], |
||
486 | ]; |
||
487 | $routeFactory->createRoute('/products/{id}', $showDefaults, [], [], '', [], ['GET'])->willReturn($showRoute); |
||
488 | $routeCollection->add('sylius_admin_product_show', $showRoute)->shouldBeCalled(); |
||
489 | |||
490 | $indexDefaults = [ |
||
491 | '_controller' => 'sylius.controller.product:indexAction', |
||
492 | '_sylius' => [ |
||
493 | 'section' => 'admin', |
||
494 | 'permission' => false, |
||
495 | ], |
||
496 | ]; |
||
497 | $routeFactory->createRoute('/products/', $indexDefaults, [], [], '', [], ['GET'])->willReturn($indexRoute); |
||
498 | $routeCollection->add('sylius_admin_product_index', $indexRoute)->shouldBeCalled(); |
||
499 | |||
500 | $createDefaults = [ |
||
501 | '_controller' => 'sylius.controller.product:createAction', |
||
502 | '_sylius' => [ |
||
503 | 'section' => 'admin', |
||
504 | 'permission' => false, |
||
505 | ], |
||
506 | ]; |
||
507 | $routeFactory->createRoute('/products/new', $createDefaults, [], [], '', [], ['GET', 'POST'])->willReturn($createRoute); |
||
508 | $routeCollection->add('sylius_admin_product_create', $createRoute)->shouldBeCalled(); |
||
509 | |||
510 | $updateDefaults = [ |
||
511 | '_controller' => 'sylius.controller.product:updateAction', |
||
512 | '_sylius' => [ |
||
513 | 'section' => 'admin', |
||
514 | 'permission' => false, |
||
515 | ], |
||
516 | ]; |
||
517 | $routeFactory->createRoute('/products/{id}/edit', $updateDefaults, [], [], '', [], ['GET', 'PUT', 'PATCH'])->willReturn($updateRoute); |
||
518 | $routeCollection->add('sylius_admin_product_update', $updateRoute)->shouldBeCalled(); |
||
519 | |||
520 | $deleteDefaults = [ |
||
521 | '_controller' => 'sylius.controller.product:deleteAction', |
||
522 | '_sylius' => [ |
||
523 | 'section' => 'admin', |
||
524 | 'permission' => false, |
||
525 | ], |
||
526 | ]; |
||
527 | $routeFactory->createRoute('/products/{id}', $deleteDefaults, [], [], '', [], ['DELETE'])->willReturn($deleteRoute); |
||
528 | $routeCollection->add('sylius_admin_product_delete', $deleteRoute)->shouldBeCalled(); |
||
529 | |||
530 | $this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection); |
||
531 | } |
||
532 | |||
533 | function it_generates_routing_with_custom_templates_namespace( |
||
534 | RegistryInterface $resourceRegistry, |
||
535 | MetadataInterface $metadata, |
||
536 | RouteFactoryInterface $routeFactory, |
||
537 | RouteCollection $routeCollection, |
||
538 | Route $showRoute, |
||
539 | Route $indexRoute, |
||
540 | Route $createRoute, |
||
541 | Route $updateRoute, |
||
542 | Route $deleteRoute |
||
543 | ): void { |
||
544 | $resourceRegistry->get('sylius.product')->willReturn($metadata); |
||
545 | $metadata->getApplicationName()->willReturn('sylius'); |
||
546 | $metadata->getName()->willReturn('product'); |
||
547 | $metadata->getPluralName()->willReturn('products'); |
||
548 | $metadata->getServiceId('controller')->willReturn('sylius.controller.product'); |
||
549 | |||
550 | $routeFactory->createRouteCollection()->willReturn($routeCollection); |
||
551 | |||
552 | $configuration = |
||
553 | <<<EOT |
||
554 | alias: sylius.product |
||
555 | templates: SyliusAdminBundle:Product |
||
556 | EOT; |
||
557 | |||
558 | $showDefaults = [ |
||
559 | '_controller' => 'sylius.controller.product:showAction', |
||
560 | '_sylius' => [ |
||
561 | 'template' => 'SyliusAdminBundle:Product:show.html.twig', |
||
562 | 'permission' => false, |
||
563 | ], |
||
564 | ]; |
||
565 | $routeFactory->createRoute('/products/{id}', $showDefaults, [], [], '', [], ['GET'])->willReturn($showRoute); |
||
566 | $routeCollection->add('sylius_product_show', $showRoute)->shouldBeCalled(); |
||
567 | |||
568 | $indexDefaults = [ |
||
569 | '_controller' => 'sylius.controller.product:indexAction', |
||
570 | '_sylius' => [ |
||
571 | 'template' => 'SyliusAdminBundle:Product:index.html.twig', |
||
572 | 'permission' => false, |
||
573 | ], |
||
574 | ]; |
||
575 | $routeFactory->createRoute('/products/', $indexDefaults, [], [], '', [], ['GET'])->willReturn($indexRoute); |
||
576 | $routeCollection->add('sylius_product_index', $indexRoute)->shouldBeCalled(); |
||
577 | |||
578 | $createDefaults = [ |
||
579 | '_controller' => 'sylius.controller.product:createAction', |
||
580 | '_sylius' => [ |
||
581 | 'template' => 'SyliusAdminBundle:Product:create.html.twig', |
||
582 | 'permission' => false, |
||
583 | ], |
||
584 | ]; |
||
585 | $routeFactory->createRoute('/products/new', $createDefaults, [], [], '', [], ['GET', 'POST'])->willReturn($createRoute); |
||
586 | $routeCollection->add('sylius_product_create', $createRoute)->shouldBeCalled(); |
||
587 | |||
588 | $updateDefaults = [ |
||
589 | '_controller' => 'sylius.controller.product:updateAction', |
||
590 | '_sylius' => [ |
||
591 | 'template' => 'SyliusAdminBundle:Product:update.html.twig', |
||
592 | 'permission' => false, |
||
593 | ], |
||
594 | ]; |
||
595 | $routeFactory->createRoute('/products/{id}/edit', $updateDefaults, [], [], '', [], ['GET', 'PUT', 'PATCH'])->willReturn($updateRoute); |
||
596 | $routeCollection->add('sylius_product_update', $updateRoute)->shouldBeCalled(); |
||
597 | |||
598 | $deleteDefaults = [ |
||
599 | '_controller' => 'sylius.controller.product:deleteAction', |
||
600 | '_sylius' => [ |
||
601 | 'permission' => false, |
||
602 | ], |
||
603 | ]; |
||
604 | $routeFactory->createRoute('/products/{id}', $deleteDefaults, [], [], '', [], ['DELETE'])->willReturn($deleteRoute); |
||
605 | $routeCollection->add('sylius_product_delete', $deleteRoute)->shouldBeCalled(); |
||
606 | |||
607 | $this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection); |
||
608 | } |
||
609 | |||
610 | function it_excludes_specific_routes_if_configured( |
||
611 | RegistryInterface $resourceRegistry, |
||
612 | MetadataInterface $metadata, |
||
613 | RouteFactoryInterface $routeFactory, |
||
614 | RouteCollection $routeCollection, |
||
615 | Route $indexRoute, |
||
616 | Route $createRoute, |
||
617 | Route $updateRoute |
||
618 | ): void { |
||
619 | $resourceRegistry->get('sylius.product')->willReturn($metadata); |
||
620 | $metadata->getApplicationName()->willReturn('sylius'); |
||
621 | $metadata->getName()->willReturn('product'); |
||
622 | $metadata->getPluralName()->willReturn('products'); |
||
623 | $metadata->getServiceId('controller')->willReturn('sylius.controller.product'); |
||
624 | |||
625 | $routeFactory->createRouteCollection()->willReturn($routeCollection); |
||
626 | |||
627 | $configuration = |
||
628 | <<<EOT |
||
629 | alias: sylius.product |
||
630 | except: ['show', 'delete'] |
||
631 | EOT; |
||
632 | |||
633 | $indexDefaults = [ |
||
634 | '_controller' => 'sylius.controller.product:indexAction', |
||
635 | '_sylius' => [ |
||
636 | 'permission' => false, |
||
637 | ], |
||
638 | ]; |
||
639 | $routeFactory->createRoute('/products/', $indexDefaults, [], [], '', [], ['GET'])->willReturn($indexRoute); |
||
640 | $routeCollection->add('sylius_product_index', $indexRoute)->shouldBeCalled(); |
||
641 | |||
642 | $createDefaults = [ |
||
643 | '_controller' => 'sylius.controller.product:createAction', |
||
644 | '_sylius' => [ |
||
645 | 'permission' => false, |
||
646 | ], |
||
647 | ]; |
||
648 | $routeFactory->createRoute('/products/new', $createDefaults, [], [], '', [], ['GET', 'POST'])->willReturn($createRoute); |
||
649 | $routeCollection->add('sylius_product_create', $createRoute)->shouldBeCalled(); |
||
650 | |||
651 | $updateDefaults = [ |
||
652 | '_controller' => 'sylius.controller.product:updateAction', |
||
653 | '_sylius' => [ |
||
654 | 'permission' => false, |
||
655 | ], |
||
656 | ]; |
||
657 | $routeFactory->createRoute('/products/{id}/edit', $updateDefaults, [], [], '', [], ['GET', 'PUT', 'PATCH'])->willReturn($updateRoute); |
||
658 | $routeCollection->add('sylius_product_update', $updateRoute)->shouldBeCalled(); |
||
659 | |||
660 | $this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection); |
||
661 | } |
||
662 | |||
663 | function it_includes_only_specific_routes_if_configured( |
||
664 | RegistryInterface $resourceRegistry, |
||
665 | MetadataInterface $metadata, |
||
666 | RouteFactoryInterface $routeFactory, |
||
667 | RouteCollection $routeCollection, |
||
668 | Route $indexRoute, |
||
669 | Route $createRoute |
||
670 | ): void { |
||
671 | $resourceRegistry->get('sylius.product')->willReturn($metadata); |
||
672 | $metadata->getApplicationName()->willReturn('sylius'); |
||
673 | $metadata->getName()->willReturn('product'); |
||
674 | $metadata->getPluralName()->willReturn('products'); |
||
675 | $metadata->getServiceId('controller')->willReturn('sylius.controller.product'); |
||
676 | |||
677 | $routeFactory->createRouteCollection()->willReturn($routeCollection); |
||
678 | |||
679 | $configuration = |
||
680 | <<<EOT |
||
681 | alias: sylius.product |
||
682 | only: ['create', 'index'] |
||
683 | EOT; |
||
684 | |||
685 | $indexDefaults = [ |
||
686 | '_controller' => 'sylius.controller.product:indexAction', |
||
687 | '_sylius' => [ |
||
688 | 'permission' => false, |
||
689 | ], |
||
690 | ]; |
||
691 | $routeFactory->createRoute('/products/', $indexDefaults, [], [], '', [], ['GET'])->willReturn($indexRoute); |
||
692 | $routeCollection->add('sylius_product_index', $indexRoute)->shouldBeCalled(); |
||
693 | |||
694 | $createDefaults = [ |
||
695 | '_controller' => 'sylius.controller.product:createAction', |
||
696 | '_sylius' => [ |
||
697 | 'permission' => false, |
||
698 | ], |
||
699 | ]; |
||
700 | $routeFactory->createRoute('/products/new', $createDefaults, [], [], '', [], ['GET', 'POST'])->willReturn($createRoute); |
||
701 | $routeCollection->add('sylius_product_create', $createRoute)->shouldBeCalled(); |
||
702 | |||
703 | $this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection); |
||
704 | } |
||
705 | |||
706 | function it_throws_an_exception_if_both_excluded_and_includes_routes_configured(): void |
||
719 | |||
720 | function it_generates_routing_with_custom_redirect_if_specified( |
||
721 | RegistryInterface $resourceRegistry, |
||
722 | MetadataInterface $metadata, |
||
723 | RouteFactoryInterface $routeFactory, |
||
724 | RouteCollection $routeCollection, |
||
725 | Route $showRoute, |
||
726 | Route $indexRoute, |
||
727 | Route $createRoute, |
||
728 | Route $updateRoute, |
||
729 | Route $deleteRoute |
||
730 | ): void { |
||
731 | $resourceRegistry->get('sylius.product')->willReturn($metadata); |
||
732 | $metadata->getApplicationName()->willReturn('sylius'); |
||
733 | $metadata->getName()->willReturn('product'); |
||
734 | $metadata->getPluralName()->willReturn('products'); |
||
735 | $metadata->getServiceId('controller')->willReturn('sylius.controller.product'); |
||
736 | |||
737 | $routeFactory->createRouteCollection()->willReturn($routeCollection); |
||
738 | |||
739 | $configuration = |
||
740 | <<<EOT |
||
741 | alias: sylius.product |
||
742 | redirect: update |
||
743 | EOT; |
||
744 | |||
745 | $showDefaults = [ |
||
746 | '_controller' => 'sylius.controller.product:showAction', |
||
747 | '_sylius' => [ |
||
748 | 'permission' => false, |
||
749 | ], |
||
750 | ]; |
||
751 | $routeFactory->createRoute('/products/{id}', $showDefaults, [], [], '', [], ['GET'])->willReturn($showRoute); |
||
752 | $routeCollection->add('sylius_product_show', $showRoute)->shouldBeCalled(); |
||
753 | |||
754 | $indexDefaults = [ |
||
755 | '_controller' => 'sylius.controller.product:indexAction', |
||
756 | '_sylius' => [ |
||
757 | 'permission' => false, |
||
758 | ], |
||
759 | ]; |
||
760 | $routeFactory->createRoute('/products/', $indexDefaults, [], [], '', [], ['GET'])->willReturn($indexRoute); |
||
761 | $routeCollection->add('sylius_product_index', $indexRoute)->shouldBeCalled(); |
||
762 | |||
763 | $createDefaults = [ |
||
764 | '_controller' => 'sylius.controller.product:createAction', |
||
765 | '_sylius' => [ |
||
766 | 'redirect' => 'sylius_product_update', |
||
767 | 'permission' => false, |
||
768 | ], |
||
769 | ]; |
||
770 | $routeFactory->createRoute('/products/new', $createDefaults, [], [], '', [], ['GET', 'POST'])->willReturn($createRoute); |
||
771 | $routeCollection->add('sylius_product_create', $createRoute)->shouldBeCalled(); |
||
772 | |||
773 | $updateDefaults = [ |
||
774 | '_controller' => 'sylius.controller.product:updateAction', |
||
775 | '_sylius' => [ |
||
776 | 'redirect' => 'sylius_product_update', |
||
777 | 'permission' => false, |
||
778 | ], |
||
779 | ]; |
||
780 | $routeFactory->createRoute('/products/{id}/edit', $updateDefaults, [], [], '', [], ['GET', 'PUT', 'PATCH'])->willReturn($updateRoute); |
||
781 | $routeCollection->add('sylius_product_update', $updateRoute)->shouldBeCalled(); |
||
782 | |||
783 | $deleteDefaults = [ |
||
784 | '_controller' => 'sylius.controller.product:deleteAction', |
||
785 | '_sylius' => [ |
||
786 | 'permission' => false, |
||
787 | ], |
||
788 | ]; |
||
789 | $routeFactory->createRoute('/products/{id}', $deleteDefaults, [], [], '', [], ['DELETE'])->willReturn($deleteRoute); |
||
790 | $routeCollection->add('sylius_product_delete', $deleteRoute)->shouldBeCalled(); |
||
791 | |||
792 | $this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection); |
||
793 | } |
||
794 | |||
795 | function it_generates_api_routing_based_on_resource_configuration( |
||
796 | RegistryInterface $resourceRegistry, |
||
797 | MetadataInterface $metadata, |
||
798 | RouteFactoryInterface $routeFactory, |
||
799 | RouteCollection $routeCollection, |
||
800 | Route $showRoute, |
||
801 | Route $indexRoute, |
||
802 | Route $createRoute, |
||
803 | Route $updateRoute, |
||
804 | Route $deleteRoute |
||
805 | ): void { |
||
806 | $resourceRegistry->get('sylius.product')->willReturn($metadata); |
||
807 | $metadata->getApplicationName()->willReturn('sylius'); |
||
808 | $metadata->getName()->willReturn('product'); |
||
809 | $metadata->getPluralName()->willReturn('products'); |
||
810 | $metadata->getServiceId('controller')->willReturn('sylius.controller.product'); |
||
811 | |||
812 | $routeFactory->createRouteCollection()->willReturn($routeCollection); |
||
813 | |||
814 | $configuration = |
||
815 | <<<EOT |
||
816 | alias: sylius.product |
||
817 | EOT; |
||
818 | |||
819 | $showDefaults = [ |
||
820 | '_controller' => 'sylius.controller.product:showAction', |
||
821 | '_sylius' => [ |
||
822 | 'serialization_groups' => ['Default', 'Detailed'], |
||
823 | 'permission' => false, |
||
824 | ], |
||
825 | ]; |
||
826 | $routeFactory->createRoute('/products/{id}', $showDefaults, [], [], '', [], ['GET'])->willReturn($showRoute); |
||
827 | $routeCollection->add('sylius_product_show', $showRoute)->shouldBeCalled(); |
||
828 | |||
829 | $indexDefaults = [ |
||
830 | '_controller' => 'sylius.controller.product:indexAction', |
||
831 | '_sylius' => [ |
||
832 | 'serialization_groups' => ['Default'], |
||
833 | 'permission' => false, |
||
834 | ], |
||
835 | ]; |
||
836 | $routeFactory->createRoute('/products/', $indexDefaults, [], [], '', [], ['GET'])->willReturn($indexRoute); |
||
837 | $routeCollection->add('sylius_product_index', $indexRoute)->shouldBeCalled(); |
||
838 | |||
839 | $createDefaults = [ |
||
840 | '_controller' => 'sylius.controller.product:createAction', |
||
841 | '_sylius' => [ |
||
842 | 'serialization_groups' => ['Default', 'Detailed'], |
||
843 | 'permission' => false, |
||
844 | ], |
||
845 | ]; |
||
846 | $routeFactory->createRoute('/products/', $createDefaults, [], [], '', [], ['POST'])->willReturn($createRoute); |
||
847 | $routeCollection->add('sylius_product_create', $createRoute)->shouldBeCalled(); |
||
848 | |||
849 | $updateDefaults = [ |
||
850 | '_controller' => 'sylius.controller.product:updateAction', |
||
851 | '_sylius' => [ |
||
852 | 'serialization_groups' => ['Default', 'Detailed'], |
||
853 | 'permission' => false, |
||
854 | ], |
||
855 | ]; |
||
856 | $routeFactory->createRoute('/products/{id}', $updateDefaults, [], [], '', [], ['PUT', 'PATCH'])->willReturn($updateRoute); |
||
857 | $routeCollection->add('sylius_product_update', $updateRoute)->shouldBeCalled(); |
||
858 | |||
859 | $deleteDefaults = [ |
||
860 | '_controller' => 'sylius.controller.product:deleteAction', |
||
861 | '_sylius' => [ |
||
862 | 'permission' => false, |
||
863 | 'csrf_protection' => false, |
||
864 | ], |
||
865 | ]; |
||
866 | $routeFactory->createRoute('/products/{id}', $deleteDefaults, [], [], '', [], ['DELETE'])->willReturn($deleteRoute); |
||
867 | $routeCollection->add('sylius_product_delete', $deleteRoute)->shouldBeCalled(); |
||
868 | |||
869 | $this->load($configuration, 'sylius.resource_api')->shouldReturn($routeCollection); |
||
870 | } |
||
871 | |||
872 | function it_configures_grid_for_index_action_if_specified( |
||
873 | RegistryInterface $resourceRegistry, |
||
874 | MetadataInterface $metadata, |
||
875 | RouteFactoryInterface $routeFactory, |
||
876 | RouteCollection $routeCollection, |
||
877 | Route $indexRoute, |
||
878 | Route $createRoute |
||
879 | ): void { |
||
880 | $resourceRegistry->get('sylius.product')->willReturn($metadata); |
||
881 | $metadata->getApplicationName()->willReturn('sylius'); |
||
882 | $metadata->getName()->willReturn('product'); |
||
883 | $metadata->getPluralName()->willReturn('products'); |
||
884 | $metadata->getServiceId('controller')->willReturn('sylius.controller.product'); |
||
885 | |||
886 | $routeFactory->createRouteCollection()->willReturn($routeCollection); |
||
887 | |||
888 | $configuration = |
||
889 | <<<EOT |
||
890 | alias: sylius.product |
||
891 | only: ['create', 'index'] |
||
892 | grid: sylius_admin_product |
||
893 | EOT; |
||
894 | |||
895 | $indexDefaults = [ |
||
896 | '_controller' => 'sylius.controller.product:indexAction', |
||
897 | '_sylius' => [ |
||
898 | 'grid' => 'sylius_admin_product', |
||
899 | 'permission' => false, |
||
900 | ], |
||
901 | ]; |
||
902 | $routeFactory->createRoute('/products/', $indexDefaults, [], [], '', [], ['GET'])->willReturn($indexRoute); |
||
903 | $routeCollection->add('sylius_product_index', $indexRoute)->shouldBeCalled(); |
||
904 | |||
905 | $createDefaults = [ |
||
906 | '_controller' => 'sylius.controller.product:createAction', |
||
907 | '_sylius' => [ |
||
908 | 'permission' => false, |
||
909 | ], |
||
910 | ]; |
||
911 | $routeFactory->createRoute('/products/new', $createDefaults, [], [], '', [], ['GET', 'POST'])->willReturn($createRoute); |
||
912 | $routeCollection->add('sylius_product_create', $createRoute)->shouldBeCalled(); |
||
913 | |||
914 | $this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection); |
||
915 | } |
||
916 | |||
917 | function it_generates_routing_with_custom_variables( |
||
918 | RegistryInterface $resourceRegistry, |
||
919 | MetadataInterface $metadata, |
||
920 | RouteFactoryInterface $routeFactory, |
||
921 | RouteCollection $routeCollection, |
||
922 | Route $showRoute, |
||
923 | Route $indexRoute, |
||
924 | Route $createRoute, |
||
925 | Route $updateRoute, |
||
926 | Route $deleteRoute |
||
927 | ): void { |
||
928 | $resourceRegistry->get('sylius.product')->willReturn($metadata); |
||
929 | $metadata->getApplicationName()->willReturn('sylius'); |
||
930 | $metadata->getName()->willReturn('product'); |
||
931 | $metadata->getPluralName()->willReturn('products'); |
||
932 | $metadata->getServiceId('controller')->willReturn('sylius.controller.product'); |
||
933 | |||
934 | $routeFactory->createRouteCollection()->willReturn($routeCollection); |
||
935 | |||
936 | $configuration = |
||
937 | <<<EOT |
||
938 | alias: sylius.product |
||
939 | vars: |
||
940 | all: |
||
941 | foo: bar |
||
942 | create: |
||
943 | bar: foo |
||
944 | update: |
||
945 | abc: xyz |
||
946 | EOT; |
||
947 | |||
948 | $showDefaults = [ |
||
949 | '_controller' => 'sylius.controller.product:showAction', |
||
950 | '_sylius' => [ |
||
951 | 'permission' => false, |
||
952 | 'vars' => [ |
||
953 | 'foo' => 'bar', |
||
954 | ], |
||
955 | ], |
||
956 | ]; |
||
957 | $routeFactory->createRoute('/products/{id}', $showDefaults, [], [], '', [], ['GET'])->willReturn($showRoute); |
||
958 | $routeCollection->add('sylius_product_show', $showRoute)->shouldBeCalled(); |
||
959 | |||
960 | $indexDefaults = [ |
||
961 | '_controller' => 'sylius.controller.product:indexAction', |
||
962 | '_sylius' => [ |
||
963 | 'permission' => false, |
||
964 | 'vars' => [ |
||
965 | 'foo' => 'bar', |
||
966 | ], |
||
967 | ], |
||
968 | ]; |
||
969 | $routeFactory->createRoute('/products/', $indexDefaults, [], [], '', [], ['GET'])->willReturn($indexRoute); |
||
970 | $routeCollection->add('sylius_product_index', $indexRoute)->shouldBeCalled(); |
||
971 | |||
972 | $createDefaults = [ |
||
973 | '_controller' => 'sylius.controller.product:createAction', |
||
974 | '_sylius' => [ |
||
975 | 'permission' => false, |
||
976 | 'vars' => [ |
||
977 | 'foo' => 'bar', |
||
978 | 'bar' => 'foo', |
||
979 | ], |
||
980 | ], |
||
981 | ]; |
||
982 | $routeFactory->createRoute('/products/new', $createDefaults, [], [], '', [], ['GET', 'POST'])->willReturn($createRoute); |
||
983 | $routeCollection->add('sylius_product_create', $createRoute)->shouldBeCalled(); |
||
984 | |||
985 | $updateDefaults = [ |
||
986 | '_controller' => 'sylius.controller.product:updateAction', |
||
987 | '_sylius' => [ |
||
988 | 'permission' => false, |
||
989 | 'vars' => [ |
||
990 | 'foo' => 'bar', |
||
991 | 'abc' => 'xyz', |
||
992 | ], |
||
993 | ], |
||
994 | ]; |
||
995 | $routeFactory->createRoute('/products/{id}/edit', $updateDefaults, [], [], '', [], ['GET', 'PUT', 'PATCH'])->willReturn($updateRoute); |
||
996 | $routeCollection->add('sylius_product_update', $updateRoute)->shouldBeCalled(); |
||
997 | |||
998 | $deleteDefaults = [ |
||
999 | '_controller' => 'sylius.controller.product:deleteAction', |
||
1000 | '_sylius' => [ |
||
1001 | 'permission' => false, |
||
1002 | 'vars' => [ |
||
1003 | 'foo' => 'bar', |
||
1004 | ], |
||
1005 | ], |
||
1006 | ]; |
||
1007 | $routeFactory->createRoute('/products/{id}', $deleteDefaults, [], [], '', [], ['DELETE'])->willReturn($deleteRoute); |
||
1008 | $routeCollection->add('sylius_product_delete', $deleteRoute)->shouldBeCalled(); |
||
1009 | |||
1010 | $this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection); |
||
1011 | } |
||
1012 | |||
1013 | function it_generates_routing_with_custom_permission( |
||
1014 | RegistryInterface $resourceRegistry, |
||
1015 | MetadataInterface $metadata, |
||
1016 | RouteFactoryInterface $routeFactory, |
||
1017 | RouteCollection $routeCollection, |
||
1018 | Route $showRoute, |
||
1019 | Route $indexRoute, |
||
1020 | Route $createRoute, |
||
1021 | Route $updateRoute, |
||
1022 | Route $deleteRoute |
||
1023 | ): void { |
||
1024 | $resourceRegistry->get('sylius.product')->willReturn($metadata); |
||
1025 | $metadata->getApplicationName()->willReturn('sylius'); |
||
1026 | $metadata->getName()->willReturn('product'); |
||
1027 | $metadata->getPluralName()->willReturn('products'); |
||
1028 | $metadata->getServiceId('controller')->willReturn('sylius.controller.product'); |
||
1029 | |||
1030 | $routeFactory->createRouteCollection()->willReturn($routeCollection); |
||
1031 | |||
1032 | $configuration = |
||
1033 | <<<EOT |
||
1034 | alias: sylius.product |
||
1035 | permission: true |
||
1036 | EOT; |
||
1037 | |||
1038 | $showDefaults = [ |
||
1039 | '_controller' => 'sylius.controller.product:showAction', |
||
1040 | '_sylius' => [ |
||
1041 | 'permission' => true, |
||
1042 | ], |
||
1043 | ]; |
||
1044 | $routeFactory->createRoute('/products/{id}', $showDefaults, [], [], '', [], ['GET'])->willReturn($showRoute); |
||
1045 | $routeCollection->add('sylius_product_show', $showRoute)->shouldBeCalled(); |
||
1046 | |||
1047 | $indexDefaults = [ |
||
1048 | '_controller' => 'sylius.controller.product:indexAction', |
||
1049 | '_sylius' => [ |
||
1050 | 'permission' => true, |
||
1051 | ], |
||
1052 | ]; |
||
1053 | $routeFactory->createRoute('/products/', $indexDefaults, [], [], '', [], ['GET'])->willReturn($indexRoute); |
||
1054 | $routeCollection->add('sylius_product_index', $indexRoute)->shouldBeCalled(); |
||
1055 | |||
1056 | $createDefaults = [ |
||
1057 | '_controller' => 'sylius.controller.product:createAction', |
||
1058 | '_sylius' => [ |
||
1059 | 'permission' => true, |
||
1060 | ], |
||
1061 | ]; |
||
1062 | $routeFactory->createRoute('/products/new', $createDefaults, [], [], '', [], ['GET', 'POST']) |
||
1063 | ->willReturn($createRoute); |
||
1064 | $routeCollection->add('sylius_product_create', $createRoute)->shouldBeCalled(); |
||
1065 | |||
1066 | $updateDefaults = [ |
||
1067 | '_controller' => 'sylius.controller.product:updateAction', |
||
1068 | '_sylius' => [ |
||
1069 | 'permission' => true, |
||
1070 | ], |
||
1071 | ]; |
||
1072 | $routeFactory->createRoute('/products/{id}/edit', $updateDefaults, [], [], '', [], ['GET', 'PUT', 'PATCH']) |
||
1073 | ->willReturn($updateRoute); |
||
1074 | $routeCollection->add('sylius_product_update', $updateRoute)->shouldBeCalled(); |
||
1075 | |||
1076 | $deleteDefaults = [ |
||
1077 | '_controller' => 'sylius.controller.product:deleteAction', |
||
1078 | '_sylius' => [ |
||
1079 | 'permission' => true, |
||
1080 | ], |
||
1081 | ]; |
||
1082 | $routeFactory->createRoute('/products/{id}', $deleteDefaults, [], [], '', [], ['DELETE']) |
||
1083 | ->willReturn($deleteRoute); |
||
1084 | $routeCollection->add('sylius_product_delete', $deleteRoute)->shouldBeCalled(); |
||
1085 | |||
1086 | $this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection); |
||
1087 | } |
||
1088 | |||
1089 | function it_supports_sylius_resource_type(): void |
||
1095 | } |
||
1096 |
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.