Completed
Push — 1.2 ( 853a8e...084ecf )
by Kamil
51:54 queued 25:03
created

it_generates_routing_with_custom_variables()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 131

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 131
rs 8
c 0
b 0
f 0
cc 1
nc 1
nop 10

How to fix   Long Method    Many Parameters   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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\ResourceBundle\Routing;
15
16
use PhpSpec\ObjectBehavior;
17
use Sylius\Bundle\ResourceBundle\Routing\RouteFactoryInterface;
18
use Sylius\Component\Resource\Metadata\MetadataInterface;
19
use Sylius\Component\Resource\Metadata\RegistryInterface;
20
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
21
use Symfony\Component\Config\Loader\LoaderInterface;
22
use Symfony\Component\Routing\Route;
23
use Symfony\Component\Routing\RouteCollection;
24
25
final class ResourceLoaderSpec extends ObjectBehavior
26
{
27
    function let(RegistryInterface $resourceRegistry, RouteFactoryInterface $routeFactory): void
28
    {
29
        $this->beConstructedWith($resourceRegistry, $routeFactory);
30
    }
31
32
    function it_is_a_Symfony_routing_loader(): void
0 ignored issues
show
Coding Style introduced by
function it_is_a_Symfony_routing_loader() does not seem to conform to the naming convention (^(?:(?:[a-z]|__)[a-zA-Z0-9]*|[a-z][a-z0-9_]*)$).

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.

Loading history...
33
    {
34
        $this->shouldImplement(LoaderInterface::class);
35
    }
36
37
    function it_processes_configuration_and_throws_exception_if_invalid(): void
38
    {
39
        $configuration =
40
<<<EOT
41
foo: bar
42
only: string
43
EOT;
44
45
        $this
46
            ->shouldThrow(InvalidConfigurationException::class)
47
            ->during('load', [$configuration, 'sylius.resource']);
48
    }
49
50
    function it_throws_an_exception_if_invalid_resource_configured(RegistryInterface $resourceRegistry): void
51
    {
52
        $resourceRegistry->get('sylius.foo')->willThrow(new \InvalidArgumentException());
0 ignored issues
show
Bug introduced by
The method willThrow() does not seem to exist on object<Sylius\Component\...data\MetadataInterface>.

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.

Loading history...
53
54
        $configuration =
55
<<<EOT
56
alias: sylius.foo
57
EOT;
58
59
        $this
60
            ->shouldThrow(\InvalidArgumentException::class)
61
            ->during('load', [$configuration, 'sylius.resource']);
62
    }
63
64
    function it_generates_routing_based_on_resource_configuration(
65
        RegistryInterface $resourceRegistry,
66
        MetadataInterface $metadata,
67
        RouteFactoryInterface $routeFactory,
68
        RouteCollection $routeCollection,
69
        Route $showRoute,
70
        Route $indexRoute,
71
        Route $createRoute,
72
        Route $updateRoute,
73
        Route $bulkDeleteRoute,
74
        Route $deleteRoute
75
    ): void {
76
        $resourceRegistry->get('sylius.product')->willReturn($metadata);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...data\MetadataInterface>.

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.

Loading history...
77
        $metadata->getApplicationName()->willReturn('sylius');
78
        $metadata->getName()->willReturn('product');
79
        $metadata->getPluralName()->willReturn('products');
80
        $metadata->getServiceId('controller')->willReturn('sylius.controller.product');
81
82
        $routeFactory->createRouteCollection()->willReturn($routeCollection);
83
84
        $configuration =
85
<<<EOT
86
alias: sylius.product
87
EOT;
88
89
        $showDefaults = [
90
            '_controller' => 'sylius.controller.product:showAction',
91
            '_sylius' => [
92
                'permission' => false,
93
            ],
94
        ];
95
        $routeFactory
96
            ->createRoute('/products/{id}', $showDefaults, [], [], '', [], ['GET'])
97
            ->willReturn($showRoute)
98
        ;
99
        $routeCollection->add('sylius_product_show', $showRoute)->shouldBeCalled();
100
101
        $indexDefaults = [
102
            '_controller' => 'sylius.controller.product:indexAction',
103
            '_sylius' => [
104
                'permission' => false,
105
            ],
106
        ];
107
        $routeFactory
108
            ->createRoute('/products/', $indexDefaults, [], [], '', [], ['GET'])
109
            ->willReturn($indexRoute)
110
        ;
111
        $routeCollection->add('sylius_product_index', $indexRoute)->shouldBeCalled();
112
113
        $createDefaults = [
114
            '_controller' => 'sylius.controller.product:createAction',
115
            '_sylius' => [
116
                'permission' => false,
117
            ],
118
        ];
119
        $routeFactory
120
            ->createRoute('/products/new', $createDefaults, [], [], '', [], ['GET', 'POST'])
121
            ->willReturn($createRoute)
122
        ;
123
        $routeCollection->add('sylius_product_create', $createRoute)->shouldBeCalled();
124
125
        $updateDefaults = [
126
            '_controller' => 'sylius.controller.product:updateAction',
127
            '_sylius' => [
128
                'permission' => false,
129
            ],
130
        ];
131
        $routeFactory
132
            ->createRoute('/products/{id}/edit', $updateDefaults, [], [], '', [], ['GET', 'PUT', 'PATCH'])
133
            ->willReturn($updateRoute)
134
        ;
135
        $routeCollection->add('sylius_product_update', $updateRoute)->shouldBeCalled();
136
137
        $bulkDeleteDefaults = [
138
            '_controller' => 'sylius.controller.product:bulkDeleteAction',
139
            '_sylius' => [
140
                'permission' => false,
141
                'paginate' => false,
142
                'repository' => [
143
                    'method' => 'findById',
144
                    'arguments' => ['$ids'],
145
                ],
146
            ],
147
        ];
148
        $routeFactory
149
            ->createRoute('/products/bulk-delete', $bulkDeleteDefaults, [], [], '', [], ['DELETE'])
150
            ->willReturn($bulkDeleteRoute)
151
        ;
152
        $routeCollection->add('sylius_product_bulk_delete', $bulkDeleteRoute)->shouldBeCalled();
153
154
        $deleteDefaults = [
155
            '_controller' => 'sylius.controller.product:deleteAction',
156
            '_sylius' => [
157
                'permission' => false,
158
            ],
159
        ];
160
        $routeFactory
161
            ->createRoute('/products/{id}', $deleteDefaults, [], [], '', [], ['DELETE'])
162
            ->willReturn($deleteRoute)
163
        ;
164
        $routeCollection->add('sylius_product_delete', $deleteRoute)->shouldBeCalled();
165
166
        $this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection);
167
    }
168
169
    function it_generates_urlized_paths_for_resources_with_multiple_words_in_name(
170
        RegistryInterface $resourceRegistry,
171
        MetadataInterface $metadata,
172
        RouteFactoryInterface $routeFactory,
173
        RouteCollection $routeCollection,
174
        Route $showRoute,
175
        Route $indexRoute,
176
        Route $createRoute,
177
        Route $updateRoute,
178
        Route $bulkDeleteRoute,
179
        Route $deleteRoute
180
    ): void {
181
        $resourceRegistry->get('sylius.product_option')->willReturn($metadata);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...data\MetadataInterface>.

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.

Loading history...
182
        $metadata->getApplicationName()->willReturn('sylius');
183
        $metadata->getName()->willReturn('product_option');
184
        $metadata->getPluralName()->willReturn('product_options');
185
        $metadata->getServiceId('controller')->willReturn('sylius.controller.product_option');
186
187
        $routeFactory->createRouteCollection()->willReturn($routeCollection);
188
189
        $configuration =
190
<<<EOT
191
alias: sylius.product_option
192
EOT;
193
194
        $showDefaults = [
195
            '_controller' => 'sylius.controller.product_option:showAction',
196
            '_sylius' => [
197
                'permission' => false,
198
            ],
199
        ];
200
        $routeFactory
201
            ->createRoute('/product-options/{id}', $showDefaults, [], [], '', [], ['GET'])
202
            ->willReturn($showRoute)
203
        ;
204
        $routeCollection->add('sylius_product_option_show', $showRoute)->shouldBeCalled();
205
206
        $indexDefaults = [
207
            '_controller' => 'sylius.controller.product_option:indexAction',
208
            '_sylius' => [
209
                'permission' => false,
210
            ],
211
        ];
212
        $routeFactory
213
            ->createRoute('/product-options/', $indexDefaults, [], [], '', [], ['GET'])
214
            ->willReturn($indexRoute)
215
        ;
216
        $routeCollection->add('sylius_product_option_index', $indexRoute)->shouldBeCalled();
217
218
        $createDefaults = [
219
            '_controller' => 'sylius.controller.product_option:createAction',
220
            '_sylius' => [
221
                'permission' => false,
222
            ],
223
        ];
224
        $routeFactory
225
            ->createRoute('/product-options/new', $createDefaults, [], [], '', [], ['GET', 'POST'])
226
            ->willReturn($createRoute)
227
        ;
228
        $routeCollection->add('sylius_product_option_create', $createRoute)->shouldBeCalled();
229
230
        $updateDefaults = [
231
            '_controller' => 'sylius.controller.product_option:updateAction',
232
            '_sylius' => [
233
                'permission' => false,
234
            ],
235
        ];
236
        $routeFactory
237
            ->createRoute('/product-options/{id}/edit', $updateDefaults, [], [], '', [], ['GET', 'PUT', 'PATCH'])
238
            ->willReturn($updateRoute)
239
        ;
240
        $routeCollection->add('sylius_product_option_update', $updateRoute)->shouldBeCalled();
241
242
        $bulkDeleteDefaults = [
243
            '_controller' => 'sylius.controller.product_option:bulkDeleteAction',
244
            '_sylius' => [
245
                'permission' => false,
246
                'paginate' => false,
247
                'repository' => [
248
                    'method' => 'findById',
249
                    'arguments' => ['$ids'],
250
                ],
251
            ],
252
        ];
253
        $routeFactory
254
            ->createRoute('/product-options/bulk-delete', $bulkDeleteDefaults, [], [], '', [], ['DELETE'])
255
            ->willReturn($bulkDeleteRoute)
256
        ;
257
        $routeCollection->add('sylius_product_option_bulk_delete', $bulkDeleteRoute)->shouldBeCalled();
258
259
        $deleteDefaults = [
260
            '_controller' => 'sylius.controller.product_option:deleteAction',
261
            '_sylius' => [
262
                'permission' => false,
263
            ],
264
        ];
265
        $routeFactory
266
            ->createRoute('/product-options/{id}', $deleteDefaults, [], [], '', [], ['DELETE'])
267
            ->willReturn($deleteRoute)
268
        ;
269
        $routeCollection->add('sylius_product_option_delete', $deleteRoute)->shouldBeCalled();
270
271
        $this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection);
272
    }
273
274
    function it_generates_urlized_paths_for_resources_with_custom_identifier(
275
        RegistryInterface $resourceRegistry,
276
        MetadataInterface $metadata,
277
        RouteFactoryInterface $routeFactory,
278
        RouteCollection $routeCollection,
279
        Route $showRoute,
280
        Route $indexRoute,
281
        Route $createRoute,
282
        Route $updateRoute,
283
        Route $bulkDeleteRoute,
284
        Route $deleteRoute
285
    ): void {
286
        $resourceRegistry->get('sylius.product_option')->willReturn($metadata);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...data\MetadataInterface>.

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.

Loading history...
287
        $metadata->getApplicationName()->willReturn('sylius');
288
        $metadata->getName()->willReturn('product_option');
289
        $metadata->getPluralName()->willReturn('product_options');
290
        $metadata->getServiceId('controller')->willReturn('sylius.controller.product_option');
291
292
        $routeFactory->createRouteCollection()->willReturn($routeCollection);
293
294
        $configuration =
295
<<<EOT
296
alias: sylius.product_option
297
identifier: code
298
criteria:
299
    code: \$code
300
filterable: true
301
EOT;
302
303
        $showDefaults = [
304
            '_controller' => 'sylius.controller.product_option:showAction',
305
            '_sylius' => [
306
                'permission' => false,
307
                'criteria' => [
308
                    'code' => '$code',
309
                ],
310
                'filterable' => true,
311
            ],
312
        ];
313
        $routeFactory
314
            ->createRoute('/product-options/{code}', $showDefaults, [], [], '', [], ['GET'])
315
            ->willReturn($showRoute)
316
        ;
317
        $routeCollection->add('sylius_product_option_show', $showRoute)->shouldBeCalled();
318
319
        $indexDefaults = [
320
            '_controller' => 'sylius.controller.product_option:indexAction',
321
            '_sylius' => [
322
                'permission' => false,
323
                'criteria' => [
324
                    'code' => '$code',
325
                ],
326
                'filterable' => true,
327
            ],
328
        ];
329
        $routeFactory
330
            ->createRoute('/product-options/', $indexDefaults, [], [], '', [], ['GET'])
331
            ->willReturn($indexRoute)
332
        ;
333
        $routeCollection->add('sylius_product_option_index', $indexRoute)->shouldBeCalled();
334
335
        $createDefaults = [
336
            '_controller' => 'sylius.controller.product_option:createAction',
337
            '_sylius' => [
338
                'permission' => false,
339
                'criteria' => [
340
                    'code' => '$code',
341
                ],
342
                'filterable' => true,
343
            ],
344
        ];
345
        $routeFactory
346
            ->createRoute('/product-options/new', $createDefaults, [], [], '', [], ['GET', 'POST'])
347
            ->willReturn($createRoute)
348
        ;
349
        $routeCollection->add('sylius_product_option_create', $createRoute)->shouldBeCalled();
350
351
        $updateDefaults = [
352
            '_controller' => 'sylius.controller.product_option:updateAction',
353
            '_sylius' => [
354
                'permission' => false,
355
                'criteria' => [
356
                    'code' => '$code',
357
                ],
358
                'filterable' => true,
359
            ],
360
        ];
361
        $routeFactory
362
            ->createRoute('/product-options/{code}/edit', $updateDefaults, [], [], '', [], ['GET', 'PUT', 'PATCH'])
363
            ->willReturn($updateRoute)
364
        ;
365
        $routeCollection->add('sylius_product_option_update', $updateRoute)->shouldBeCalled();
366
367
        $bulkDeleteDefaults = [
368
            '_controller' => 'sylius.controller.product_option:bulkDeleteAction',
369
            '_sylius' => [
370
                'permission' => false,
371
                'paginate' => false,
372
                'repository' => [
373
                    'method' => 'findById',
374
                    'arguments' => ['$ids'],
375
                ],
376
                'criteria' => [
377
                    'code' => '$code',
378
                ],
379
                'filterable' => true,
380
            ],
381
        ];
382
        $routeFactory
383
            ->createRoute('/product-options/bulk-delete', $bulkDeleteDefaults, [], [], '', [], ['DELETE'])
384
            ->willReturn($bulkDeleteRoute)
385
        ;
386
        $routeCollection->add('sylius_product_option_bulk_delete', $bulkDeleteRoute)->shouldBeCalled();
387
388
        $deleteDefaults = [
389
            '_controller' => 'sylius.controller.product_option:deleteAction',
390
            '_sylius' => [
391
                'permission' => false,
392
                'criteria' => [
393
                    'code' => '$code',
394
                ],
395
                'filterable' => true,
396
            ],
397
        ];
398
        $routeFactory
399
            ->createRoute('/product-options/{code}', $deleteDefaults, [], [], '', [], ['DELETE'])
400
            ->willReturn($deleteRoute)
401
        ;
402
        $routeCollection->add('sylius_product_option_delete', $deleteRoute)->shouldBeCalled();
403
404
        $this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection);
405
    }
406
407
    function it_generates_routing_with_custom_path_if_specified(
408
        RegistryInterface $resourceRegistry,
409
        MetadataInterface $metadata,
410
        RouteFactoryInterface $routeFactory,
411
        RouteCollection $routeCollection,
412
        Route $showRoute,
413
        Route $indexRoute,
414
        Route $createRoute,
415
        Route $updateRoute,
416
        Route $bulkDeleteRoute,
417
        Route $deleteRoute
418
    ): void {
419
        $resourceRegistry->get('sylius.product')->willReturn($metadata);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...data\MetadataInterface>.

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.

Loading history...
420
        $metadata->getApplicationName()->willReturn('sylius');
421
        $metadata->getName()->willReturn('product');
422
        $metadata->getPluralName()->willReturn('products');
423
        $metadata->getServiceId('controller')->willReturn('sylius.controller.product');
424
425
        $routeFactory->createRouteCollection()->willReturn($routeCollection);
426
427
        $configuration =
428
<<<EOT
429
alias: sylius.product
430
path: super-duper-products
431
EOT;
432
433
        $showDefaults = [
434
            '_controller' => 'sylius.controller.product:showAction',
435
            '_sylius' => [
436
                'permission' => false,
437
            ],
438
        ];
439
        $routeFactory
440
            ->createRoute('/super-duper-products/{id}', $showDefaults, [], [], '', [], ['GET'])
441
            ->willReturn($showRoute)
442
        ;
443
        $routeCollection->add('sylius_product_show', $showRoute)->shouldBeCalled();
444
445
        $indexDefaults = [
446
            '_controller' => 'sylius.controller.product:indexAction',
447
            '_sylius' => [
448
                'permission' => false,
449
            ],
450
        ];
451
        $routeFactory
452
            ->createRoute('/super-duper-products/', $indexDefaults, [], [], '', [], ['GET'])
453
            ->willReturn($indexRoute)
454
        ;
455
        $routeCollection->add('sylius_product_index', $indexRoute)->shouldBeCalled();
456
457
        $createDefaults = [
458
            '_controller' => 'sylius.controller.product:createAction',
459
            '_sylius' => [
460
                'permission' => false,
461
            ],
462
        ];
463
        $routeFactory
464
            ->createRoute('/super-duper-products/new', $createDefaults, [], [], '', [], ['GET', 'POST'])
465
            ->willReturn($createRoute)
466
        ;
467
        $routeCollection->add('sylius_product_create', $createRoute)->shouldBeCalled();
468
469
        $updateDefaults = [
470
            '_controller' => 'sylius.controller.product:updateAction',
471
            '_sylius' => [
472
                'permission' => false,
473
            ],
474
        ];
475
        $routeFactory
476
            ->createRoute('/super-duper-products/{id}/edit', $updateDefaults, [], [], '', [], ['GET', 'PUT', 'PATCH'])
477
            ->willReturn($updateRoute)
478
        ;
479
        $routeCollection->add('sylius_product_update', $updateRoute)->shouldBeCalled();
480
481
        $bulkDeleteDefaults = [
482
            '_controller' => 'sylius.controller.product:bulkDeleteAction',
483
            '_sylius' => [
484
                'permission' => false,
485
                'paginate' => false,
486
                'repository' => [
487
                    'method' => 'findById',
488
                    'arguments' => ['$ids'],
489
                ],
490
            ],
491
        ];
492
        $routeFactory
493
            ->createRoute('/super-duper-products/bulk-delete', $bulkDeleteDefaults, [], [], '', [], ['DELETE'])
494
            ->willReturn($bulkDeleteRoute)
495
        ;
496
        $routeCollection->add('sylius_product_bulk_delete', $bulkDeleteRoute)->shouldBeCalled();
497
498
        $deleteDefaults = [
499
            '_controller' => 'sylius.controller.product:deleteAction',
500
            '_sylius' => [
501
                'permission' => false,
502
            ],
503
        ];
504
        $routeFactory
505
            ->createRoute('/super-duper-products/{id}', $deleteDefaults, [], [], '', [], ['DELETE'])
506
            ->willReturn($deleteRoute)
507
        ;
508
        $routeCollection->add('sylius_product_delete', $deleteRoute)->shouldBeCalled();
509
510
        $this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection);
511
    }
512
513
    function it_generates_routing_with_custom_form_if_specified(
514
        RegistryInterface $resourceRegistry,
515
        MetadataInterface $metadata,
516
        RouteFactoryInterface $routeFactory,
517
        RouteCollection $routeCollection,
518
        Route $showRoute,
519
        Route $indexRoute,
520
        Route $createRoute,
521
        Route $updateRoute,
522
        Route $bulkDeleteRoute,
523
        Route $deleteRoute
524
    ): void {
525
        $resourceRegistry->get('sylius.product')->willReturn($metadata);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...data\MetadataInterface>.

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.

Loading history...
526
        $metadata->getApplicationName()->willReturn('sylius');
527
        $metadata->getName()->willReturn('product');
528
        $metadata->getPluralName()->willReturn('products');
529
        $metadata->getServiceId('controller')->willReturn('sylius.controller.product');
530
531
        $routeFactory->createRouteCollection()->willReturn($routeCollection);
532
533
        $configuration =
534
<<<EOT
535
alias: sylius.product
536
form: sylius_product_custom
537
EOT;
538
539
        $showDefaults = [
540
            '_controller' => 'sylius.controller.product:showAction',
541
            '_sylius' => [
542
                'permission' => false,
543
            ],
544
        ];
545
        $routeFactory
546
            ->createRoute('/products/{id}', $showDefaults, [], [], '', [], ['GET'])
547
            ->willReturn($showRoute)
548
        ;
549
        $routeCollection->add('sylius_product_show', $showRoute)->shouldBeCalled();
550
551
        $indexDefaults = [
552
            '_controller' => 'sylius.controller.product:indexAction',
553
            '_sylius' => [
554
                'permission' => false,
555
            ],
556
        ];
557
        $routeFactory
558
            ->createRoute('/products/', $indexDefaults, [], [], '', [], ['GET'])
559
            ->willReturn($indexRoute)
560
        ;
561
        $routeCollection->add('sylius_product_index', $indexRoute)->shouldBeCalled();
562
563
        $createDefaults = [
564
            '_controller' => 'sylius.controller.product:createAction',
565
            '_sylius' => [
566
                'form' => 'sylius_product_custom',
567
                'permission' => false,
568
            ],
569
        ];
570
        $routeFactory
571
            ->createRoute('/products/new', $createDefaults, [], [], '', [], ['GET', 'POST'])
572
            ->willReturn($createRoute)
573
        ;
574
        $routeCollection->add('sylius_product_create', $createRoute)->shouldBeCalled();
575
576
        $updateDefaults = [
577
            '_controller' => 'sylius.controller.product:updateAction',
578
            '_sylius' => [
579
                'form' => 'sylius_product_custom',
580
                'permission' => false,
581
            ],
582
        ];
583
        $routeFactory
584
            ->createRoute('/products/{id}/edit', $updateDefaults, [], [], '', [], ['GET', 'PUT', 'PATCH'])
585
            ->willReturn($updateRoute)
586
        ;
587
        $routeCollection->add('sylius_product_update', $updateRoute)->shouldBeCalled();
588
589
        $bulkDeleteDefaults = [
590
            '_controller' => 'sylius.controller.product:bulkDeleteAction',
591
            '_sylius' => [
592
                'permission' => false,
593
                'paginate' => false,
594
                'repository' => [
595
                    'method' => 'findById',
596
                    'arguments' => ['$ids'],
597
                ],
598
            ],
599
        ];
600
        $routeFactory
601
            ->createRoute('/products/bulk-delete', $bulkDeleteDefaults, [], [], '', [], ['DELETE'])
602
            ->willReturn($bulkDeleteRoute)
603
        ;
604
        $routeCollection->add('sylius_product_bulk_delete', $bulkDeleteRoute)->shouldBeCalled();
605
606
        $deleteDefaults = [
607
            '_controller' => 'sylius.controller.product:deleteAction',
608
            '_sylius' => [
609
                'permission' => false,
610
            ],
611
        ];
612
        $routeFactory
613
            ->createRoute('/products/{id}', $deleteDefaults, [], [], '', [], ['DELETE'])
614
            ->willReturn($deleteRoute)
615
        ;
616
        $routeCollection->add('sylius_product_delete', $deleteRoute)->shouldBeCalled();
617
618
        $this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection);
619
    }
620
621
    function it_generates_routing_for_a_section(
622
        RegistryInterface $resourceRegistry,
623
        MetadataInterface $metadata,
624
        RouteFactoryInterface $routeFactory,
625
        RouteCollection $routeCollection,
626
        Route $showRoute,
627
        Route $indexRoute,
628
        Route $createRoute,
629
        Route $updateRoute,
630
        Route $bulkDeleteRoute,
631
        Route $deleteRoute
632
    ): void {
633
        $resourceRegistry->get('sylius.product')->willReturn($metadata);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...data\MetadataInterface>.

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.

Loading history...
634
        $metadata->getApplicationName()->willReturn('sylius');
635
        $metadata->getName()->willReturn('product');
636
        $metadata->getPluralName()->willReturn('products');
637
        $metadata->getServiceId('controller')->willReturn('sylius.controller.product');
638
639
        $routeFactory->createRouteCollection()->willReturn($routeCollection);
640
641
        $configuration =
642
<<<EOT
643
alias: sylius.product
644
section: admin
645
EOT;
646
647
        $showDefaults = [
648
            '_controller' => 'sylius.controller.product:showAction',
649
            '_sylius' => [
650
                'section' => 'admin',
651
                'permission' => false,
652
            ],
653
        ];
654
        $routeFactory
655
            ->createRoute('/products/{id}', $showDefaults, [], [], '', [], ['GET'])
656
            ->willReturn($showRoute)
657
        ;
658
        $routeCollection->add('sylius_admin_product_show', $showRoute)->shouldBeCalled();
659
660
        $indexDefaults = [
661
            '_controller' => 'sylius.controller.product:indexAction',
662
            '_sylius' => [
663
                'section' => 'admin',
664
                'permission' => false,
665
            ],
666
        ];
667
        $routeFactory
668
            ->createRoute('/products/', $indexDefaults, [], [], '', [], ['GET'])
669
            ->willReturn($indexRoute)
670
        ;
671
        $routeCollection->add('sylius_admin_product_index', $indexRoute)->shouldBeCalled();
672
673
        $createDefaults = [
674
            '_controller' => 'sylius.controller.product:createAction',
675
            '_sylius' => [
676
                'section' => 'admin',
677
                'permission' => false,
678
            ],
679
        ];
680
        $routeFactory
681
            ->createRoute('/products/new', $createDefaults, [], [], '', [], ['GET', 'POST'])
682
            ->willReturn($createRoute)
683
        ;
684
        $routeCollection->add('sylius_admin_product_create', $createRoute)->shouldBeCalled();
685
686
        $updateDefaults = [
687
            '_controller' => 'sylius.controller.product:updateAction',
688
            '_sylius' => [
689
                'section' => 'admin',
690
                'permission' => false,
691
            ],
692
        ];
693
        $routeFactory
694
            ->createRoute('/products/{id}/edit', $updateDefaults, [], [], '', [], ['GET', 'PUT', 'PATCH'])
695
            ->willReturn($updateRoute)
696
        ;
697
        $routeCollection->add('sylius_admin_product_update', $updateRoute)->shouldBeCalled();
698
699
        $bulkDeleteDefaults = [
700
            '_controller' => 'sylius.controller.product:bulkDeleteAction',
701
            '_sylius' => [
702
                'section' => 'admin',
703
                'permission' => false,
704
                'paginate' => false,
705
                'repository' => [
706
                    'method' => 'findById',
707
                    'arguments' => ['$ids'],
708
                ],
709
            ],
710
        ];
711
        $routeFactory
712
            ->createRoute('/products/bulk-delete', $bulkDeleteDefaults, [], [], '', [], ['DELETE'])
713
            ->willReturn($bulkDeleteRoute)
714
        ;
715
        $routeCollection->add('sylius_admin_product_bulk_delete', $bulkDeleteRoute)->shouldBeCalled();
716
717
        $deleteDefaults = [
718
            '_controller' => 'sylius.controller.product:deleteAction',
719
            '_sylius' => [
720
                'section' => 'admin',
721
                'permission' => false,
722
            ],
723
        ];
724
        $routeFactory
725
            ->createRoute('/products/{id}', $deleteDefaults, [], [], '', [], ['DELETE'])
726
            ->willReturn($deleteRoute)
727
        ;
728
        $routeCollection->add('sylius_admin_product_delete', $deleteRoute)->shouldBeCalled();
729
730
        $this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection);
731
    }
732
733
    function it_generates_routing_with_custom_templates_namespace_in_bundle(
734
        RegistryInterface $resourceRegistry,
735
        MetadataInterface $metadata,
736
        RouteFactoryInterface $routeFactory,
737
        RouteCollection $routeCollection,
738
        Route $showRoute,
739
        Route $indexRoute,
740
        Route $createRoute,
741
        Route $updateRoute,
742
        Route $bulkDeleteRoute,
743
        Route $deleteRoute
744
    ): void {
745
        $resourceRegistry->get('sylius.product')->willReturn($metadata);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...data\MetadataInterface>.

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.

Loading history...
746
        $metadata->getApplicationName()->willReturn('sylius');
747
        $metadata->getName()->willReturn('product');
748
        $metadata->getPluralName()->willReturn('products');
749
        $metadata->getServiceId('controller')->willReturn('sylius.controller.product');
750
751
        $routeFactory->createRouteCollection()->willReturn($routeCollection);
752
753
        $configuration =
754
<<<EOT
755
alias: sylius.product
756
templates: SyliusAdminBundle:Product
757
EOT;
758
759
        $showDefaults = [
760
            '_controller' => 'sylius.controller.product:showAction',
761
            '_sylius' => [
762
                'template' => 'SyliusAdminBundle:Product:show.html.twig',
763
                'permission' => false,
764
            ],
765
        ];
766
        $routeFactory
767
            ->createRoute('/products/{id}', $showDefaults, [], [], '', [], ['GET'])
768
            ->willReturn($showRoute)
769
        ;
770
        $routeCollection->add('sylius_product_show', $showRoute)->shouldBeCalled();
771
772
        $indexDefaults = [
773
            '_controller' => 'sylius.controller.product:indexAction',
774
            '_sylius' => [
775
                'template' => 'SyliusAdminBundle:Product:index.html.twig',
776
                'permission' => false,
777
            ],
778
        ];
779
        $routeFactory
780
            ->createRoute('/products/', $indexDefaults, [], [], '', [], ['GET'])
781
            ->willReturn($indexRoute)
782
        ;
783
        $routeCollection->add('sylius_product_index', $indexRoute)->shouldBeCalled();
784
785
        $createDefaults = [
786
            '_controller' => 'sylius.controller.product:createAction',
787
            '_sylius' => [
788
                'template' => 'SyliusAdminBundle:Product:create.html.twig',
789
                'permission' => false,
790
            ],
791
        ];
792
        $routeFactory
793
            ->createRoute('/products/new', $createDefaults, [], [], '', [], ['GET', 'POST'])
794
            ->willReturn($createRoute)
795
        ;
796
        $routeCollection->add('sylius_product_create', $createRoute)->shouldBeCalled();
797
798
        $updateDefaults = [
799
            '_controller' => 'sylius.controller.product:updateAction',
800
            '_sylius' => [
801
                'template' => 'SyliusAdminBundle:Product:update.html.twig',
802
                'permission' => false,
803
            ],
804
        ];
805
        $routeFactory
806
            ->createRoute('/products/{id}/edit', $updateDefaults, [], [], '', [], ['GET', 'PUT', 'PATCH'])
807
            ->willReturn($updateRoute)
808
        ;
809
        $routeCollection->add('sylius_product_update', $updateRoute)->shouldBeCalled();
810
811
        $bulkDeleteDefaults = [
812
            '_controller' => 'sylius.controller.product:bulkDeleteAction',
813
            '_sylius' => [
814
                'permission' => false,
815
                'paginate' => false,
816
                'repository' => [
817
                    'method' => 'findById',
818
                    'arguments' => ['$ids'],
819
                ],
820
            ],
821
        ];
822
        $routeFactory
823
            ->createRoute('/products/bulk-delete', $bulkDeleteDefaults, [], [], '', [], ['DELETE'])
824
            ->willReturn($bulkDeleteRoute)
825
        ;
826
        $routeCollection->add('sylius_product_bulk_delete', $bulkDeleteRoute)->shouldBeCalled();
827
828
        $deleteDefaults = [
829
            '_controller' => 'sylius.controller.product:deleteAction',
830
            '_sylius' => [
831
                'permission' => false,
832
            ],
833
        ];
834
        $routeFactory
835
            ->createRoute('/products/{id}', $deleteDefaults, [], [], '', [], ['DELETE'])
836
            ->willReturn($deleteRoute)
837
        ;
838
        $routeCollection->add('sylius_product_delete', $deleteRoute)->shouldBeCalled();
839
840
        $this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection);
841
    }
842
843
    function it_generates_routing_with_custom_templates_namespace_out_of_bundle(
844
        RegistryInterface $resourceRegistry,
845
        MetadataInterface $metadata,
846
        RouteFactoryInterface $routeFactory,
847
        RouteCollection $routeCollection,
848
        Route $showRoute,
849
        Route $indexRoute,
850
        Route $createRoute,
851
        Route $updateRoute,
852
        Route $bulkDeleteRoute,
853
        Route $deleteRoute
854
    ): void {
855
        $resourceRegistry->get('sylius.product')->willReturn($metadata);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...data\MetadataInterface>.

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.

Loading history...
856
        $metadata->getApplicationName()->willReturn('sylius');
857
        $metadata->getName()->willReturn('product');
858
        $metadata->getPluralName()->willReturn('products');
859
        $metadata->getServiceId('controller')->willReturn('sylius.controller.product');
860
861
        $routeFactory->createRouteCollection()->willReturn($routeCollection);
862
863
        $configuration =
864
            <<<EOT
865
alias: sylius.product
866
templates: admin/product
867
EOT;
868
869
        $showDefaults = [
870
            '_controller' => 'sylius.controller.product:showAction',
871
            '_sylius' => [
872
                'template' => 'admin/product/show.html.twig',
873
                'permission' => false,
874
            ],
875
        ];
876
        $routeFactory
877
            ->createRoute('/products/{id}', $showDefaults, [], [], '', [], ['GET'])
878
            ->willReturn($showRoute)
879
        ;
880
        $routeCollection->add('sylius_product_show', $showRoute)->shouldBeCalled();
881
882
        $indexDefaults = [
883
            '_controller' => 'sylius.controller.product:indexAction',
884
            '_sylius' => [
885
                'template' => 'admin/product/index.html.twig',
886
                'permission' => false,
887
            ],
888
        ];
889
        $routeFactory
890
            ->createRoute('/products/', $indexDefaults, [], [], '', [], ['GET'])
891
            ->willReturn($indexRoute)
892
        ;
893
        $routeCollection->add('sylius_product_index', $indexRoute)->shouldBeCalled();
894
895
        $createDefaults = [
896
            '_controller' => 'sylius.controller.product:createAction',
897
            '_sylius' => [
898
                'template' => 'admin/product/create.html.twig',
899
                'permission' => false,
900
            ],
901
        ];
902
        $routeFactory
903
            ->createRoute('/products/new', $createDefaults, [], [], '', [], ['GET', 'POST'])
904
            ->willReturn($createRoute)
905
        ;
906
        $routeCollection->add('sylius_product_create', $createRoute)->shouldBeCalled();
907
908
        $updateDefaults = [
909
            '_controller' => 'sylius.controller.product:updateAction',
910
            '_sylius' => [
911
                'template' => 'admin/product/update.html.twig',
912
                'permission' => false,
913
            ],
914
        ];
915
        $routeFactory
916
            ->createRoute('/products/{id}/edit', $updateDefaults, [], [], '', [], ['GET', 'PUT', 'PATCH'])
917
            ->willReturn($updateRoute)
918
        ;
919
        $routeCollection->add('sylius_product_update', $updateRoute)->shouldBeCalled();
920
921
        $bulkDeleteDefaults = [
922
            '_controller' => 'sylius.controller.product:bulkDeleteAction',
923
            '_sylius' => [
924
                'permission' => false,
925
                'paginate' => false,
926
                'repository' => [
927
                    'method' => 'findById',
928
                    'arguments' => ['$ids'],
929
                ],
930
            ],
931
        ];
932
        $routeFactory
933
            ->createRoute('/products/bulk-delete', $bulkDeleteDefaults, [], [], '', [], ['DELETE'])
934
            ->willReturn($bulkDeleteRoute)
935
        ;
936
        $routeCollection->add('sylius_product_bulk_delete', $bulkDeleteRoute)->shouldBeCalled();
937
938
        $deleteDefaults = [
939
            '_controller' => 'sylius.controller.product:deleteAction',
940
            '_sylius' => [
941
                'permission' => false,
942
            ],
943
        ];
944
        $routeFactory
945
            ->createRoute('/products/{id}', $deleteDefaults, [], [], '', [], ['DELETE'])
946
            ->willReturn($deleteRoute)
947
        ;
948
        $routeCollection->add('sylius_product_delete', $deleteRoute)->shouldBeCalled();
949
950
        $this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection);
951
    }
952
953
    function it_excludes_specific_routes_if_configured(
954
        RegistryInterface $resourceRegistry,
955
        MetadataInterface $metadata,
956
        RouteFactoryInterface $routeFactory,
957
        RouteCollection $routeCollection,
958
        Route $indexRoute,
959
        Route $createRoute,
960
        Route $updateRoute
961
    ): void {
962
        $resourceRegistry->get('sylius.product')->willReturn($metadata);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...data\MetadataInterface>.

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.

Loading history...
963
        $metadata->getApplicationName()->willReturn('sylius');
964
        $metadata->getName()->willReturn('product');
965
        $metadata->getPluralName()->willReturn('products');
966
        $metadata->getServiceId('controller')->willReturn('sylius.controller.product');
967
968
        $routeFactory->createRouteCollection()->willReturn($routeCollection);
969
970
        $configuration =
971
<<<EOT
972
alias: sylius.product
973
except: ['show', 'delete', 'bulkDelete']
974
EOT;
975
976
        $indexDefaults = [
977
            '_controller' => 'sylius.controller.product:indexAction',
978
            '_sylius' => [
979
                'permission' => false,
980
            ],
981
        ];
982
        $routeFactory
983
            ->createRoute('/products/', $indexDefaults, [], [], '', [], ['GET'])
984
            ->willReturn($indexRoute)
985
        ;
986
        $routeCollection->add('sylius_product_index', $indexRoute)->shouldBeCalled();
987
988
        $createDefaults = [
989
            '_controller' => 'sylius.controller.product:createAction',
990
            '_sylius' => [
991
                'permission' => false,
992
            ],
993
        ];
994
        $routeFactory
995
            ->createRoute('/products/new', $createDefaults, [], [], '', [], ['GET', 'POST'])
996
            ->willReturn($createRoute)
997
        ;
998
        $routeCollection->add('sylius_product_create', $createRoute)->shouldBeCalled();
999
1000
        $updateDefaults = [
1001
            '_controller' => 'sylius.controller.product:updateAction',
1002
            '_sylius' => [
1003
                'permission' => false,
1004
            ],
1005
        ];
1006
        $routeFactory
1007
            ->createRoute('/products/{id}/edit', $updateDefaults, [], [], '', [], ['GET', 'PUT', 'PATCH'])
1008
            ->willReturn($updateRoute)
1009
        ;
1010
        $routeCollection->add('sylius_product_update', $updateRoute)->shouldBeCalled();
1011
1012
        $this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection);
1013
    }
1014
1015
    function it_includes_only_specific_routes_if_configured(
1016
        RegistryInterface $resourceRegistry,
1017
        MetadataInterface $metadata,
1018
        RouteFactoryInterface $routeFactory,
1019
        RouteCollection $routeCollection,
1020
        Route $indexRoute,
1021
        Route $createRoute
1022
    ): void {
1023
        $resourceRegistry->get('sylius.product')->willReturn($metadata);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...data\MetadataInterface>.

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.

Loading history...
1024
        $metadata->getApplicationName()->willReturn('sylius');
1025
        $metadata->getName()->willReturn('product');
1026
        $metadata->getPluralName()->willReturn('products');
1027
        $metadata->getServiceId('controller')->willReturn('sylius.controller.product');
1028
1029
        $routeFactory->createRouteCollection()->willReturn($routeCollection);
1030
1031
        $configuration =
1032
<<<EOT
1033
alias: sylius.product
1034
only: ['create', 'index']
1035
EOT;
1036
1037
        $indexDefaults = [
1038
            '_controller' => 'sylius.controller.product:indexAction',
1039
            '_sylius' => [
1040
                'permission' => false,
1041
            ],
1042
        ];
1043
        $routeFactory
1044
            ->createRoute('/products/', $indexDefaults, [], [], '', [], ['GET'])
1045
            ->willReturn($indexRoute)
1046
        ;
1047
        $routeCollection->add('sylius_product_index', $indexRoute)->shouldBeCalled();
1048
1049
        $createDefaults = [
1050
            '_controller' => 'sylius.controller.product:createAction',
1051
            '_sylius' => [
1052
                'permission' => false,
1053
            ],
1054
        ];
1055
        $routeFactory
1056
            ->createRoute('/products/new', $createDefaults, [], [], '', [], ['GET', 'POST'])
1057
            ->willReturn($createRoute)
1058
        ;
1059
        $routeCollection->add('sylius_product_create', $createRoute)->shouldBeCalled();
1060
1061
        $this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection);
1062
    }
1063
1064
    function it_throws_an_exception_if_both_excluded_and_includes_routes_configured(): void
1065
    {
1066
        $configuration =
1067
<<<EOT
1068
alias: sylius.product
1069
except: ['show', 'delete']
1070
only: ['create']
1071
EOT;
1072
1073
        $this
1074
            ->shouldThrow(\InvalidArgumentException::class)
1075
            ->during('load', [$configuration, 'sylius.resource']);
1076
    }
1077
1078
    function it_generates_routing_with_custom_redirect_if_specified(
1079
        RegistryInterface $resourceRegistry,
1080
        MetadataInterface $metadata,
1081
        RouteFactoryInterface $routeFactory,
1082
        RouteCollection $routeCollection,
1083
        Route $showRoute,
1084
        Route $indexRoute,
1085
        Route $createRoute,
1086
        Route $updateRoute,
1087
        Route $bulkDeleteRoute,
1088
        Route $deleteRoute
1089
    ): void {
1090
        $resourceRegistry->get('sylius.product')->willReturn($metadata);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...data\MetadataInterface>.

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.

Loading history...
1091
        $metadata->getApplicationName()->willReturn('sylius');
1092
        $metadata->getName()->willReturn('product');
1093
        $metadata->getPluralName()->willReturn('products');
1094
        $metadata->getServiceId('controller')->willReturn('sylius.controller.product');
1095
1096
        $routeFactory->createRouteCollection()->willReturn($routeCollection);
1097
1098
        $configuration =
1099
<<<EOT
1100
alias: sylius.product
1101
redirect: update
1102
EOT;
1103
1104
        $showDefaults = [
1105
            '_controller' => 'sylius.controller.product:showAction',
1106
            '_sylius' => [
1107
                'permission' => false,
1108
            ],
1109
        ];
1110
        $routeFactory
1111
            ->createRoute('/products/{id}', $showDefaults, [], [], '', [], ['GET'])
1112
            ->willReturn($showRoute)
1113
        ;
1114
        $routeCollection->add('sylius_product_show', $showRoute)->shouldBeCalled();
1115
1116
        $indexDefaults = [
1117
            '_controller' => 'sylius.controller.product:indexAction',
1118
            '_sylius' => [
1119
                'permission' => false,
1120
            ],
1121
        ];
1122
        $routeFactory
1123
            ->createRoute('/products/', $indexDefaults, [], [], '', [], ['GET'])
1124
            ->willReturn($indexRoute)
1125
        ;
1126
        $routeCollection->add('sylius_product_index', $indexRoute)->shouldBeCalled();
1127
1128
        $createDefaults = [
1129
            '_controller' => 'sylius.controller.product:createAction',
1130
            '_sylius' => [
1131
                'redirect' => 'sylius_product_update',
1132
                'permission' => false,
1133
            ],
1134
        ];
1135
        $routeFactory
1136
            ->createRoute('/products/new', $createDefaults, [], [], '', [], ['GET', 'POST'])
1137
            ->willReturn($createRoute)
1138
        ;
1139
        $routeCollection->add('sylius_product_create', $createRoute)->shouldBeCalled();
1140
1141
        $updateDefaults = [
1142
            '_controller' => 'sylius.controller.product:updateAction',
1143
            '_sylius' => [
1144
                'redirect' => 'sylius_product_update',
1145
                'permission' => false,
1146
            ],
1147
        ];
1148
        $routeFactory
1149
            ->createRoute('/products/{id}/edit', $updateDefaults, [], [], '', [], ['GET', 'PUT', 'PATCH'])
1150
            ->willReturn($updateRoute)
1151
        ;
1152
        $routeCollection->add('sylius_product_update', $updateRoute)->shouldBeCalled();
1153
1154
        $bulkDeleteDefaults = [
1155
            '_controller' => 'sylius.controller.product:bulkDeleteAction',
1156
            '_sylius' => [
1157
                'permission' => false,
1158
                'paginate' => false,
1159
                'repository' => [
1160
                    'method' => 'findById',
1161
                    'arguments' => ['$ids'],
1162
                ],
1163
            ],
1164
        ];
1165
        $routeFactory
1166
            ->createRoute('/products/bulk-delete', $bulkDeleteDefaults, [], [], '', [], ['DELETE'])
1167
            ->willReturn($bulkDeleteRoute)
1168
        ;
1169
        $routeCollection->add('sylius_product_bulk_delete', $bulkDeleteRoute)->shouldBeCalled();
1170
1171
        $deleteDefaults = [
1172
            '_controller' => 'sylius.controller.product:deleteAction',
1173
            '_sylius' => [
1174
                'permission' => false,
1175
            ],
1176
        ];
1177
        $routeFactory
1178
            ->createRoute('/products/{id}', $deleteDefaults, [], [], '', [], ['DELETE'])
1179
            ->willReturn($deleteRoute)
1180
        ;
1181
        $routeCollection->add('sylius_product_delete', $deleteRoute)->shouldBeCalled();
1182
1183
        $this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection);
1184
    }
1185
1186
    function it_generates_api_routing_based_on_resource_configuration(
1187
        RegistryInterface $resourceRegistry,
1188
        MetadataInterface $metadata,
1189
        RouteFactoryInterface $routeFactory,
1190
        RouteCollection $routeCollection,
1191
        Route $showRoute,
1192
        Route $indexRoute,
1193
        Route $createRoute,
1194
        Route $updateRoute,
1195
        Route $deleteRoute
1196
    ): void {
1197
        $resourceRegistry->get('sylius.product')->willReturn($metadata);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...data\MetadataInterface>.

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.

Loading history...
1198
        $metadata->getApplicationName()->willReturn('sylius');
1199
        $metadata->getName()->willReturn('product');
1200
        $metadata->getPluralName()->willReturn('products');
1201
        $metadata->getServiceId('controller')->willReturn('sylius.controller.product');
1202
1203
        $routeFactory->createRouteCollection()->willReturn($routeCollection);
1204
1205
        $configuration =
1206
<<<EOT
1207
alias: sylius.product
1208
EOT;
1209
1210
        $showDefaults = [
1211
            '_controller' => 'sylius.controller.product:showAction',
1212
            '_sylius' => [
1213
                'serialization_groups' => ['Default', 'Detailed'],
1214
                'permission' => false,
1215
            ],
1216
        ];
1217
        $routeFactory
1218
            ->createRoute('/products/{id}', $showDefaults, [], [], '', [], ['GET'])
1219
            ->willReturn($showRoute)
1220
        ;
1221
        $routeCollection->add('sylius_product_show', $showRoute)->shouldBeCalled();
1222
1223
        $indexDefaults = [
1224
            '_controller' => 'sylius.controller.product:indexAction',
1225
            '_sylius' => [
1226
                'serialization_groups' => ['Default'],
1227
                'permission' => false,
1228
            ],
1229
        ];
1230
        $routeFactory
1231
            ->createRoute('/products/', $indexDefaults, [], [], '', [], ['GET'])
1232
            ->willReturn($indexRoute)
1233
        ;
1234
        $routeCollection->add('sylius_product_index', $indexRoute)->shouldBeCalled();
1235
1236
        $createDefaults = [
1237
            '_controller' => 'sylius.controller.product:createAction',
1238
            '_sylius' => [
1239
                'serialization_groups' => ['Default', 'Detailed'],
1240
                'permission' => false,
1241
            ],
1242
        ];
1243
        $routeFactory
1244
            ->createRoute('/products/', $createDefaults, [], [], '', [], ['POST'])
1245
            ->willReturn($createRoute)
1246
        ;
1247
        $routeCollection->add('sylius_product_create', $createRoute)->shouldBeCalled();
1248
1249
        $updateDefaults = [
1250
            '_controller' => 'sylius.controller.product:updateAction',
1251
            '_sylius' => [
1252
                'serialization_groups' => ['Default', 'Detailed'],
1253
                'permission' => false,
1254
            ],
1255
        ];
1256
        $routeFactory
1257
            ->createRoute('/products/{id}', $updateDefaults, [], [], '', [], ['PUT', 'PATCH'])
1258
            ->willReturn($updateRoute)
1259
        ;
1260
        $routeCollection->add('sylius_product_update', $updateRoute)->shouldBeCalled();
1261
1262
        $deleteDefaults = [
1263
            '_controller' => 'sylius.controller.product:deleteAction',
1264
            '_sylius' => [
1265
                'permission' => false,
1266
                'csrf_protection' => false,
1267
            ],
1268
        ];
1269
        $routeFactory
1270
            ->createRoute('/products/{id}', $deleteDefaults, [], [], '', [], ['DELETE'])
1271
            ->willReturn($deleteRoute)
1272
        ;
1273
        $routeCollection->add('sylius_product_delete', $deleteRoute)->shouldBeCalled();
1274
1275
        $this->load($configuration, 'sylius.resource_api')->shouldReturn($routeCollection);
1276
    }
1277
1278
    function it_configures_grid_for_index_action_if_specified(
1279
        RegistryInterface $resourceRegistry,
1280
        MetadataInterface $metadata,
1281
        RouteFactoryInterface $routeFactory,
1282
        RouteCollection $routeCollection,
1283
        Route $indexRoute,
1284
        Route $createRoute
1285
    ): void {
1286
        $resourceRegistry->get('sylius.product')->willReturn($metadata);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...data\MetadataInterface>.

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.

Loading history...
1287
        $metadata->getApplicationName()->willReturn('sylius');
1288
        $metadata->getName()->willReturn('product');
1289
        $metadata->getPluralName()->willReturn('products');
1290
        $metadata->getServiceId('controller')->willReturn('sylius.controller.product');
1291
1292
        $routeFactory->createRouteCollection()->willReturn($routeCollection);
1293
1294
        $configuration =
1295
<<<EOT
1296
alias: sylius.product
1297
only: ['create', 'index']
1298
grid: sylius_admin_product
1299
EOT;
1300
1301
        $indexDefaults = [
1302
            '_controller' => 'sylius.controller.product:indexAction',
1303
            '_sylius' => [
1304
                'grid' => 'sylius_admin_product',
1305
                'permission' => false,
1306
            ],
1307
        ];
1308
        $routeFactory
1309
            ->createRoute('/products/', $indexDefaults, [], [], '', [], ['GET'])
1310
            ->willReturn($indexRoute)
1311
        ;
1312
        $routeCollection->add('sylius_product_index', $indexRoute)->shouldBeCalled();
1313
1314
        $createDefaults = [
1315
            '_controller' => 'sylius.controller.product:createAction',
1316
            '_sylius' => [
1317
                'permission' => false,
1318
            ],
1319
        ];
1320
        $routeFactory
1321
            ->createRoute('/products/new', $createDefaults, [], [], '', [], ['GET', 'POST'])
1322
            ->willReturn($createRoute)
1323
        ;
1324
        $routeCollection->add('sylius_product_create', $createRoute)->shouldBeCalled();
1325
1326
        $this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection);
1327
    }
1328
1329
    function it_generates_routing_with_custom_variables(
1330
        RegistryInterface $resourceRegistry,
1331
        MetadataInterface $metadata,
1332
        RouteFactoryInterface $routeFactory,
1333
        RouteCollection $routeCollection,
1334
        Route $showRoute,
1335
        Route $indexRoute,
1336
        Route $createRoute,
1337
        Route $updateRoute,
1338
        Route $deleteRoute,
1339
        Route $bulkDeleteRoute
1340
    ): void {
1341
        $resourceRegistry->get('sylius.product')->willReturn($metadata);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...data\MetadataInterface>.

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.

Loading history...
1342
        $metadata->getApplicationName()->willReturn('sylius');
1343
        $metadata->getName()->willReturn('product');
1344
        $metadata->getPluralName()->willReturn('products');
1345
        $metadata->getServiceId('controller')->willReturn('sylius.controller.product');
1346
1347
        $routeFactory->createRouteCollection()->willReturn($routeCollection);
1348
1349
        $configuration =
1350
<<<EOT
1351
alias: sylius.product
1352
vars:
1353
    all:
1354
        foo: bar
1355
    create:
1356
        bar: foo
1357
    update:
1358
        abc: xyz
1359
EOT;
1360
1361
        $showDefaults = [
1362
            '_controller' => 'sylius.controller.product:showAction',
1363
            '_sylius' => [
1364
                'permission' => false,
1365
                'vars' => [
1366
                    'foo' => 'bar',
1367
                ],
1368
            ],
1369
        ];
1370
        $routeFactory
1371
            ->createRoute('/products/{id}', $showDefaults, [], [], '', [], ['GET'])
1372
            ->willReturn($showRoute)
1373
        ;
1374
        $routeCollection->add('sylius_product_show', $showRoute)->shouldBeCalled();
1375
1376
        $indexDefaults = [
1377
            '_controller' => 'sylius.controller.product:indexAction',
1378
            '_sylius' => [
1379
                'permission' => false,
1380
                'vars' => [
1381
                    'foo' => 'bar',
1382
                ],
1383
            ],
1384
        ];
1385
        $routeFactory
1386
            ->createRoute('/products/', $indexDefaults, [], [], '', [], ['GET'])
1387
            ->willReturn($indexRoute)
1388
        ;
1389
        $routeCollection->add('sylius_product_index', $indexRoute)->shouldBeCalled();
1390
1391
        $createDefaults = [
1392
            '_controller' => 'sylius.controller.product:createAction',
1393
            '_sylius' => [
1394
                'permission' => false,
1395
                'vars' => [
1396
                    'foo' => 'bar',
1397
                    'bar' => 'foo',
1398
                ],
1399
            ],
1400
        ];
1401
        $routeFactory
1402
            ->createRoute('/products/new', $createDefaults, [], [], '', [], ['GET', 'POST'])
1403
            ->willReturn($createRoute)
1404
        ;
1405
        $routeCollection->add('sylius_product_create', $createRoute)->shouldBeCalled();
1406
1407
        $updateDefaults = [
1408
            '_controller' => 'sylius.controller.product:updateAction',
1409
            '_sylius' => [
1410
                'permission' => false,
1411
                'vars' => [
1412
                    'foo' => 'bar',
1413
                    'abc' => 'xyz',
1414
                ],
1415
            ],
1416
        ];
1417
        $routeFactory
1418
            ->createRoute('/products/{id}/edit', $updateDefaults, [], [], '', [], ['GET', 'PUT', 'PATCH'])
1419
            ->willReturn($updateRoute)
1420
        ;
1421
        $routeCollection->add('sylius_product_update', $updateRoute)->shouldBeCalled();
1422
1423
        $bulkDeleteDefaults = [
1424
            '_controller' => 'sylius.controller.product:bulkDeleteAction',
1425
            '_sylius' => [
1426
                'permission' => false,
1427
                'paginate' => false,
1428
                'repository' => [
1429
                    'method' => 'findById',
1430
                    'arguments' => ['$ids'],
1431
                ],
1432
                'vars' => [
1433
                    'foo' => 'bar',
1434
                ],
1435
            ],
1436
        ];
1437
        $routeFactory
1438
            ->createRoute('/products/bulk-delete', $bulkDeleteDefaults, [], [], '', [], ['DELETE'])
1439
            ->willReturn($bulkDeleteRoute)
1440
        ;
1441
        $routeCollection->add('sylius_product_bulk_delete', $bulkDeleteRoute)->shouldBeCalled();
1442
1443
        $deleteDefaults = [
1444
            '_controller' => 'sylius.controller.product:deleteAction',
1445
            '_sylius' => [
1446
                'permission' => false,
1447
                'vars' => [
1448
                    'foo' => 'bar',
1449
                ],
1450
            ],
1451
        ];
1452
        $routeFactory
1453
            ->createRoute('/products/{id}', $deleteDefaults, [], [], '', [], ['DELETE'])
1454
            ->willReturn($deleteRoute)
1455
        ;
1456
        $routeCollection->add('sylius_product_delete', $deleteRoute)->shouldBeCalled();
1457
1458
        $this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection);
1459
    }
1460
1461
    function it_generates_routing_with_custom_permission(
1462
        RegistryInterface $resourceRegistry,
1463
        MetadataInterface $metadata,
1464
        RouteFactoryInterface $routeFactory,
1465
        RouteCollection $routeCollection,
1466
        Route $showRoute,
1467
        Route $indexRoute,
1468
        Route $createRoute,
1469
        Route $updateRoute,
1470
        Route $bulkDeleteRoute,
1471
        Route $deleteRoute
1472
    ): void {
1473
        $resourceRegistry->get('sylius.product')->willReturn($metadata);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...data\MetadataInterface>.

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.

Loading history...
1474
        $metadata->getApplicationName()->willReturn('sylius');
1475
        $metadata->getName()->willReturn('product');
1476
        $metadata->getPluralName()->willReturn('products');
1477
        $metadata->getServiceId('controller')->willReturn('sylius.controller.product');
1478
1479
        $routeFactory->createRouteCollection()->willReturn($routeCollection);
1480
1481
        $configuration =
1482
            <<<EOT
1483
alias: sylius.product
1484
permission: true
1485
EOT;
1486
1487
        $showDefaults = [
1488
            '_controller' => 'sylius.controller.product:showAction',
1489
            '_sylius' => [
1490
                'permission' => true,
1491
            ],
1492
        ];
1493
        $routeFactory
1494
            ->createRoute('/products/{id}', $showDefaults, [], [], '', [], ['GET'])
1495
            ->willReturn($showRoute)
1496
        ;
1497
        $routeCollection->add('sylius_product_show', $showRoute)->shouldBeCalled();
1498
1499
        $indexDefaults = [
1500
            '_controller' => 'sylius.controller.product:indexAction',
1501
            '_sylius' => [
1502
                'permission' => true,
1503
            ],
1504
        ];
1505
        $routeFactory
1506
            ->createRoute('/products/', $indexDefaults, [], [], '', [], ['GET'])
1507
            ->willReturn($indexRoute)
1508
        ;
1509
        $routeCollection->add('sylius_product_index', $indexRoute)->shouldBeCalled();
1510
1511
        $createDefaults = [
1512
            '_controller' => 'sylius.controller.product:createAction',
1513
            '_sylius' => [
1514
                'permission' => true,
1515
            ],
1516
        ];
1517
        $routeFactory
1518
            ->createRoute('/products/new', $createDefaults, [], [], '', [], ['GET', 'POST'])
1519
            ->willReturn($createRoute)
1520
        ;
1521
        $routeCollection->add('sylius_product_create', $createRoute)->shouldBeCalled();
1522
1523
        $updateDefaults = [
1524
            '_controller' => 'sylius.controller.product:updateAction',
1525
            '_sylius' => [
1526
                'permission' => true,
1527
            ],
1528
        ];
1529
        $routeFactory
1530
            ->createRoute('/products/{id}/edit', $updateDefaults, [], [], '', [], ['GET', 'PUT', 'PATCH'])
1531
            ->willReturn($updateRoute)
1532
        ;
1533
        $routeCollection->add('sylius_product_update', $updateRoute)->shouldBeCalled();
1534
1535
        $bulkDeleteDefaults = [
1536
            '_controller' => 'sylius.controller.product:bulkDeleteAction',
1537
            '_sylius' => [
1538
                'permission' => true,
1539
                'paginate' => false,
1540
                'repository' => [
1541
                    'method' => 'findById',
1542
                    'arguments' => ['$ids'],
1543
                ],
1544
            ],
1545
        ];
1546
        $routeFactory
1547
            ->createRoute('/products/bulk-delete', $bulkDeleteDefaults, [], [], '', [], ['DELETE'])
1548
            ->willReturn($bulkDeleteRoute)
1549
        ;
1550
        $routeCollection->add('sylius_product_bulk_delete', $bulkDeleteRoute)->shouldBeCalled();
1551
1552
        $deleteDefaults = [
1553
            '_controller' => 'sylius.controller.product:deleteAction',
1554
            '_sylius' => [
1555
                'permission' => true,
1556
            ],
1557
        ];
1558
        $routeFactory->createRoute('/products/{id}', $deleteDefaults, [], [], '', [], ['DELETE'])
1559
                     ->willReturn($deleteRoute);
1560
        $routeCollection->add('sylius_product_delete', $deleteRoute)->shouldBeCalled();
1561
1562
        $this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection);
1563
    }
1564
1565
    function it_supports_sylius_resource_type(): void
1566
    {
1567
        $this->supports('sylius.product', 'sylius.resource')->shouldReturn(true);
1568
        $this->supports('sylius.product', 'sylius.resource_api')->shouldReturn(true);
1569
        $this->supports('sylius.product', 'abc')->shouldReturn(false);
1570
    }
1571
}
1572