Completed
Push — 1.2-symfony4-packages ( fadf23 )
by Kamil
70:47 queued 48:14
created

it_includes_only_specific_routes_if_configured()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 48
Code Lines 35

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 48
rs 9.125
c 0
b 0
f 0
cc 1
eloc 35
nc 1
nop 6
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(
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_excludes_specific_routes_if_configured(
844
        RegistryInterface $resourceRegistry,
845
        MetadataInterface $metadata,
846
        RouteFactoryInterface $routeFactory,
847
        RouteCollection $routeCollection,
848
        Route $indexRoute,
849
        Route $createRoute,
850
        Route $updateRoute
851
    ): void {
852
        $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...
853
        $metadata->getApplicationName()->willReturn('sylius');
854
        $metadata->getName()->willReturn('product');
855
        $metadata->getPluralName()->willReturn('products');
856
        $metadata->getServiceId('controller')->willReturn('sylius.controller.product');
857
858
        $routeFactory->createRouteCollection()->willReturn($routeCollection);
859
860
        $configuration =
861
<<<EOT
862
alias: sylius.product
863
except: ['show', 'delete', 'bulkDelete']
864
EOT;
865
866
        $indexDefaults = [
867
            '_controller' => 'sylius.controller.product:indexAction',
868
            '_sylius' => [
869
                'permission' => false,
870
            ],
871
        ];
872
        $routeFactory
873
            ->createRoute('/products/', $indexDefaults, [], [], '', [], ['GET'])
874
            ->willReturn($indexRoute)
875
        ;
876
        $routeCollection->add('sylius_product_index', $indexRoute)->shouldBeCalled();
877
878
        $createDefaults = [
879
            '_controller' => 'sylius.controller.product:createAction',
880
            '_sylius' => [
881
                'permission' => false,
882
            ],
883
        ];
884
        $routeFactory
885
            ->createRoute('/products/new', $createDefaults, [], [], '', [], ['GET', 'POST'])
886
            ->willReturn($createRoute)
887
        ;
888
        $routeCollection->add('sylius_product_create', $createRoute)->shouldBeCalled();
889
890
        $updateDefaults = [
891
            '_controller' => 'sylius.controller.product:updateAction',
892
            '_sylius' => [
893
                'permission' => false,
894
            ],
895
        ];
896
        $routeFactory
897
            ->createRoute('/products/{id}/edit', $updateDefaults, [], [], '', [], ['GET', 'PUT', 'PATCH'])
898
            ->willReturn($updateRoute)
899
        ;
900
        $routeCollection->add('sylius_product_update', $updateRoute)->shouldBeCalled();
901
902
        $this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection);
903
    }
904
905
    function it_includes_only_specific_routes_if_configured(
906
        RegistryInterface $resourceRegistry,
907
        MetadataInterface $metadata,
908
        RouteFactoryInterface $routeFactory,
909
        RouteCollection $routeCollection,
910
        Route $indexRoute,
911
        Route $createRoute
912
    ): void {
913
        $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...
914
        $metadata->getApplicationName()->willReturn('sylius');
915
        $metadata->getName()->willReturn('product');
916
        $metadata->getPluralName()->willReturn('products');
917
        $metadata->getServiceId('controller')->willReturn('sylius.controller.product');
918
919
        $routeFactory->createRouteCollection()->willReturn($routeCollection);
920
921
        $configuration =
922
<<<EOT
923
alias: sylius.product
924
only: ['create', 'index']
925
EOT;
926
927
        $indexDefaults = [
928
            '_controller' => 'sylius.controller.product:indexAction',
929
            '_sylius' => [
930
                'permission' => false,
931
            ],
932
        ];
933
        $routeFactory
934
            ->createRoute('/products/', $indexDefaults, [], [], '', [], ['GET'])
935
            ->willReturn($indexRoute)
936
        ;
937
        $routeCollection->add('sylius_product_index', $indexRoute)->shouldBeCalled();
938
939
        $createDefaults = [
940
            '_controller' => 'sylius.controller.product:createAction',
941
            '_sylius' => [
942
                'permission' => false,
943
            ],
944
        ];
945
        $routeFactory
946
            ->createRoute('/products/new', $createDefaults, [], [], '', [], ['GET', 'POST'])
947
            ->willReturn($createRoute)
948
        ;
949
        $routeCollection->add('sylius_product_create', $createRoute)->shouldBeCalled();
950
951
        $this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection);
952
    }
953
954
    function it_throws_an_exception_if_both_excluded_and_includes_routes_configured(): void
955
    {
956
        $configuration =
957
<<<EOT
958
alias: sylius.product
959
except: ['show', 'delete']
960
only: ['create']
961
EOT;
962
963
        $this
964
            ->shouldThrow(\InvalidArgumentException::class)
965
            ->during('load', [$configuration, 'sylius.resource']);
966
    }
967
968
    function it_generates_routing_with_custom_redirect_if_specified(
969
        RegistryInterface $resourceRegistry,
970
        MetadataInterface $metadata,
971
        RouteFactoryInterface $routeFactory,
972
        RouteCollection $routeCollection,
973
        Route $showRoute,
974
        Route $indexRoute,
975
        Route $createRoute,
976
        Route $updateRoute,
977
        Route $bulkDeleteRoute,
978
        Route $deleteRoute
979
    ): void {
980
        $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...
981
        $metadata->getApplicationName()->willReturn('sylius');
982
        $metadata->getName()->willReturn('product');
983
        $metadata->getPluralName()->willReturn('products');
984
        $metadata->getServiceId('controller')->willReturn('sylius.controller.product');
985
986
        $routeFactory->createRouteCollection()->willReturn($routeCollection);
987
988
        $configuration =
989
<<<EOT
990
alias: sylius.product
991
redirect: update
992
EOT;
993
994
        $showDefaults = [
995
            '_controller' => 'sylius.controller.product:showAction',
996
            '_sylius' => [
997
                'permission' => false,
998
            ],
999
        ];
1000
        $routeFactory
1001
            ->createRoute('/products/{id}', $showDefaults, [], [], '', [], ['GET'])
1002
            ->willReturn($showRoute)
1003
        ;
1004
        $routeCollection->add('sylius_product_show', $showRoute)->shouldBeCalled();
1005
1006
        $indexDefaults = [
1007
            '_controller' => 'sylius.controller.product:indexAction',
1008
            '_sylius' => [
1009
                'permission' => false,
1010
            ],
1011
        ];
1012
        $routeFactory
1013
            ->createRoute('/products/', $indexDefaults, [], [], '', [], ['GET'])
1014
            ->willReturn($indexRoute)
1015
        ;
1016
        $routeCollection->add('sylius_product_index', $indexRoute)->shouldBeCalled();
1017
1018
        $createDefaults = [
1019
            '_controller' => 'sylius.controller.product:createAction',
1020
            '_sylius' => [
1021
                'redirect' => 'sylius_product_update',
1022
                'permission' => false,
1023
            ],
1024
        ];
1025
        $routeFactory
1026
            ->createRoute('/products/new', $createDefaults, [], [], '', [], ['GET', 'POST'])
1027
            ->willReturn($createRoute)
1028
        ;
1029
        $routeCollection->add('sylius_product_create', $createRoute)->shouldBeCalled();
1030
1031
        $updateDefaults = [
1032
            '_controller' => 'sylius.controller.product:updateAction',
1033
            '_sylius' => [
1034
                'redirect' => 'sylius_product_update',
1035
                'permission' => false,
1036
            ],
1037
        ];
1038
        $routeFactory
1039
            ->createRoute('/products/{id}/edit', $updateDefaults, [], [], '', [], ['GET', 'PUT', 'PATCH'])
1040
            ->willReturn($updateRoute)
1041
        ;
1042
        $routeCollection->add('sylius_product_update', $updateRoute)->shouldBeCalled();
1043
1044
        $bulkDeleteDefaults = [
1045
            '_controller' => 'sylius.controller.product:bulkDeleteAction',
1046
            '_sylius' => [
1047
                'permission' => false,
1048
                'paginate' => false,
1049
                'repository' => [
1050
                    'method' => 'findById',
1051
                    'arguments' => ['$ids'],
1052
                ],
1053
            ],
1054
        ];
1055
        $routeFactory
1056
            ->createRoute('/products/bulk-delete', $bulkDeleteDefaults, [], [], '', [], ['DELETE'])
1057
            ->willReturn($bulkDeleteRoute)
1058
        ;
1059
        $routeCollection->add('sylius_product_bulk_delete', $bulkDeleteRoute)->shouldBeCalled();
1060
1061
        $deleteDefaults = [
1062
            '_controller' => 'sylius.controller.product:deleteAction',
1063
            '_sylius' => [
1064
                'permission' => false,
1065
            ],
1066
        ];
1067
        $routeFactory
1068
            ->createRoute('/products/{id}', $deleteDefaults, [], [], '', [], ['DELETE'])
1069
            ->willReturn($deleteRoute)
1070
        ;
1071
        $routeCollection->add('sylius_product_delete', $deleteRoute)->shouldBeCalled();
1072
1073
        $this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection);
1074
    }
1075
1076
    function it_generates_api_routing_based_on_resource_configuration(
1077
        RegistryInterface $resourceRegistry,
1078
        MetadataInterface $metadata,
1079
        RouteFactoryInterface $routeFactory,
1080
        RouteCollection $routeCollection,
1081
        Route $showRoute,
1082
        Route $indexRoute,
1083
        Route $createRoute,
1084
        Route $updateRoute,
1085
        Route $deleteRoute
1086
    ): void {
1087
        $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...
1088
        $metadata->getApplicationName()->willReturn('sylius');
1089
        $metadata->getName()->willReturn('product');
1090
        $metadata->getPluralName()->willReturn('products');
1091
        $metadata->getServiceId('controller')->willReturn('sylius.controller.product');
1092
1093
        $routeFactory->createRouteCollection()->willReturn($routeCollection);
1094
1095
        $configuration =
1096
<<<EOT
1097
alias: sylius.product
1098
EOT;
1099
1100
        $showDefaults = [
1101
            '_controller' => 'sylius.controller.product:showAction',
1102
            '_sylius' => [
1103
                'serialization_groups' => ['Default', 'Detailed'],
1104
                'permission' => false,
1105
            ],
1106
        ];
1107
        $routeFactory
1108
            ->createRoute('/products/{id}', $showDefaults, [], [], '', [], ['GET'])
1109
            ->willReturn($showRoute)
1110
        ;
1111
        $routeCollection->add('sylius_product_show', $showRoute)->shouldBeCalled();
1112
1113
        $indexDefaults = [
1114
            '_controller' => 'sylius.controller.product:indexAction',
1115
            '_sylius' => [
1116
                'serialization_groups' => ['Default'],
1117
                'permission' => false,
1118
            ],
1119
        ];
1120
        $routeFactory
1121
            ->createRoute('/products/', $indexDefaults, [], [], '', [], ['GET'])
1122
            ->willReturn($indexRoute)
1123
        ;
1124
        $routeCollection->add('sylius_product_index', $indexRoute)->shouldBeCalled();
1125
1126
        $createDefaults = [
1127
            '_controller' => 'sylius.controller.product:createAction',
1128
            '_sylius' => [
1129
                'serialization_groups' => ['Default', 'Detailed'],
1130
                'permission' => false,
1131
            ],
1132
        ];
1133
        $routeFactory
1134
            ->createRoute('/products/', $createDefaults, [], [], '', [], ['POST'])
1135
            ->willReturn($createRoute)
1136
        ;
1137
        $routeCollection->add('sylius_product_create', $createRoute)->shouldBeCalled();
1138
1139
        $updateDefaults = [
1140
            '_controller' => 'sylius.controller.product:updateAction',
1141
            '_sylius' => [
1142
                'serialization_groups' => ['Default', 'Detailed'],
1143
                'permission' => false,
1144
            ],
1145
        ];
1146
        $routeFactory
1147
            ->createRoute('/products/{id}', $updateDefaults, [], [], '', [], ['PUT', 'PATCH'])
1148
            ->willReturn($updateRoute)
1149
        ;
1150
        $routeCollection->add('sylius_product_update', $updateRoute)->shouldBeCalled();
1151
1152
        $deleteDefaults = [
1153
            '_controller' => 'sylius.controller.product:deleteAction',
1154
            '_sylius' => [
1155
                'permission' => false,
1156
                'csrf_protection' => false,
1157
            ],
1158
        ];
1159
        $routeFactory
1160
            ->createRoute('/products/{id}', $deleteDefaults, [], [], '', [], ['DELETE'])
1161
            ->willReturn($deleteRoute)
1162
        ;
1163
        $routeCollection->add('sylius_product_delete', $deleteRoute)->shouldBeCalled();
1164
1165
        $this->load($configuration, 'sylius.resource_api')->shouldReturn($routeCollection);
1166
    }
1167
1168
    function it_configures_grid_for_index_action_if_specified(
1169
        RegistryInterface $resourceRegistry,
1170
        MetadataInterface $metadata,
1171
        RouteFactoryInterface $routeFactory,
1172
        RouteCollection $routeCollection,
1173
        Route $indexRoute,
1174
        Route $createRoute
1175
    ): void {
1176
        $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...
1177
        $metadata->getApplicationName()->willReturn('sylius');
1178
        $metadata->getName()->willReturn('product');
1179
        $metadata->getPluralName()->willReturn('products');
1180
        $metadata->getServiceId('controller')->willReturn('sylius.controller.product');
1181
1182
        $routeFactory->createRouteCollection()->willReturn($routeCollection);
1183
1184
        $configuration =
1185
<<<EOT
1186
alias: sylius.product
1187
only: ['create', 'index']
1188
grid: sylius_admin_product
1189
EOT;
1190
1191
        $indexDefaults = [
1192
            '_controller' => 'sylius.controller.product:indexAction',
1193
            '_sylius' => [
1194
                'grid' => 'sylius_admin_product',
1195
                'permission' => false,
1196
            ],
1197
        ];
1198
        $routeFactory
1199
            ->createRoute('/products/', $indexDefaults, [], [], '', [], ['GET'])
1200
            ->willReturn($indexRoute)
1201
        ;
1202
        $routeCollection->add('sylius_product_index', $indexRoute)->shouldBeCalled();
1203
1204
        $createDefaults = [
1205
            '_controller' => 'sylius.controller.product:createAction',
1206
            '_sylius' => [
1207
                'permission' => false,
1208
            ],
1209
        ];
1210
        $routeFactory
1211
            ->createRoute('/products/new', $createDefaults, [], [], '', [], ['GET', 'POST'])
1212
            ->willReturn($createRoute)
1213
        ;
1214
        $routeCollection->add('sylius_product_create', $createRoute)->shouldBeCalled();
1215
1216
        $this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection);
1217
    }
1218
1219
    function it_generates_routing_with_custom_variables(
1220
        RegistryInterface $resourceRegistry,
1221
        MetadataInterface $metadata,
1222
        RouteFactoryInterface $routeFactory,
1223
        RouteCollection $routeCollection,
1224
        Route $showRoute,
1225
        Route $indexRoute,
1226
        Route $createRoute,
1227
        Route $updateRoute,
1228
        Route $deleteRoute,
1229
        Route $bulkDeleteRoute
1230
    ): void {
1231
        $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...
1232
        $metadata->getApplicationName()->willReturn('sylius');
1233
        $metadata->getName()->willReturn('product');
1234
        $metadata->getPluralName()->willReturn('products');
1235
        $metadata->getServiceId('controller')->willReturn('sylius.controller.product');
1236
1237
        $routeFactory->createRouteCollection()->willReturn($routeCollection);
1238
1239
        $configuration =
1240
<<<EOT
1241
alias: sylius.product
1242
vars:
1243
    all:
1244
        foo: bar
1245
    create:
1246
        bar: foo
1247
    update:
1248
        abc: xyz
1249
EOT;
1250
1251
        $showDefaults = [
1252
            '_controller' => 'sylius.controller.product:showAction',
1253
            '_sylius' => [
1254
                'permission' => false,
1255
                'vars' => [
1256
                    'foo' => 'bar',
1257
                ],
1258
            ],
1259
        ];
1260
        $routeFactory
1261
            ->createRoute('/products/{id}', $showDefaults, [], [], '', [], ['GET'])
1262
            ->willReturn($showRoute)
1263
        ;
1264
        $routeCollection->add('sylius_product_show', $showRoute)->shouldBeCalled();
1265
1266
        $indexDefaults = [
1267
            '_controller' => 'sylius.controller.product:indexAction',
1268
            '_sylius' => [
1269
                'permission' => false,
1270
                'vars' => [
1271
                    'foo' => 'bar',
1272
                ],
1273
            ],
1274
        ];
1275
        $routeFactory
1276
            ->createRoute('/products/', $indexDefaults, [], [], '', [], ['GET'])
1277
            ->willReturn($indexRoute)
1278
        ;
1279
        $routeCollection->add('sylius_product_index', $indexRoute)->shouldBeCalled();
1280
1281
        $createDefaults = [
1282
            '_controller' => 'sylius.controller.product:createAction',
1283
            '_sylius' => [
1284
                'permission' => false,
1285
                'vars' => [
1286
                    'foo' => 'bar',
1287
                    'bar' => 'foo',
1288
                ],
1289
            ],
1290
        ];
1291
        $routeFactory
1292
            ->createRoute('/products/new', $createDefaults, [], [], '', [], ['GET', 'POST'])
1293
            ->willReturn($createRoute)
1294
        ;
1295
        $routeCollection->add('sylius_product_create', $createRoute)->shouldBeCalled();
1296
1297
        $updateDefaults = [
1298
            '_controller' => 'sylius.controller.product:updateAction',
1299
            '_sylius' => [
1300
                'permission' => false,
1301
                'vars' => [
1302
                    'foo' => 'bar',
1303
                    'abc' => 'xyz',
1304
                ],
1305
            ],
1306
        ];
1307
        $routeFactory
1308
            ->createRoute('/products/{id}/edit', $updateDefaults, [], [], '', [], ['GET', 'PUT', 'PATCH'])
1309
            ->willReturn($updateRoute)
1310
        ;
1311
        $routeCollection->add('sylius_product_update', $updateRoute)->shouldBeCalled();
1312
1313
        $bulkDeleteDefaults = [
1314
            '_controller' => 'sylius.controller.product:bulkDeleteAction',
1315
            '_sylius' => [
1316
                'permission' => false,
1317
                'paginate' => false,
1318
                'repository' => [
1319
                    'method' => 'findById',
1320
                    'arguments' => ['$ids'],
1321
                ],
1322
                'vars' => [
1323
                    'foo' => 'bar',
1324
                ],
1325
            ],
1326
        ];
1327
        $routeFactory
1328
            ->createRoute('/products/bulk-delete', $bulkDeleteDefaults, [], [], '', [], ['DELETE'])
1329
            ->willReturn($bulkDeleteRoute)
1330
        ;
1331
        $routeCollection->add('sylius_product_bulk_delete', $bulkDeleteRoute)->shouldBeCalled();
1332
1333
        $deleteDefaults = [
1334
            '_controller' => 'sylius.controller.product:deleteAction',
1335
            '_sylius' => [
1336
                'permission' => false,
1337
                'vars' => [
1338
                    'foo' => 'bar',
1339
                ],
1340
            ],
1341
        ];
1342
        $routeFactory
1343
            ->createRoute('/products/{id}', $deleteDefaults, [], [], '', [], ['DELETE'])
1344
            ->willReturn($deleteRoute)
1345
        ;
1346
        $routeCollection->add('sylius_product_delete', $deleteRoute)->shouldBeCalled();
1347
1348
        $this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection);
1349
    }
1350
1351
    function it_generates_routing_with_custom_permission(
1352
        RegistryInterface $resourceRegistry,
1353
        MetadataInterface $metadata,
1354
        RouteFactoryInterface $routeFactory,
1355
        RouteCollection $routeCollection,
1356
        Route $showRoute,
1357
        Route $indexRoute,
1358
        Route $createRoute,
1359
        Route $updateRoute,
1360
        Route $bulkDeleteRoute,
1361
        Route $deleteRoute
1362
    ): void {
1363
        $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...
1364
        $metadata->getApplicationName()->willReturn('sylius');
1365
        $metadata->getName()->willReturn('product');
1366
        $metadata->getPluralName()->willReturn('products');
1367
        $metadata->getServiceId('controller')->willReturn('sylius.controller.product');
1368
1369
        $routeFactory->createRouteCollection()->willReturn($routeCollection);
1370
1371
        $configuration =
1372
            <<<EOT
1373
alias: sylius.product
1374
permission: true
1375
EOT;
1376
1377
        $showDefaults = [
1378
            '_controller' => 'sylius.controller.product:showAction',
1379
            '_sylius' => [
1380
                'permission' => true,
1381
            ],
1382
        ];
1383
        $routeFactory
1384
            ->createRoute('/products/{id}', $showDefaults, [], [], '', [], ['GET'])
1385
            ->willReturn($showRoute)
1386
        ;
1387
        $routeCollection->add('sylius_product_show', $showRoute)->shouldBeCalled();
1388
1389
        $indexDefaults = [
1390
            '_controller' => 'sylius.controller.product:indexAction',
1391
            '_sylius' => [
1392
                'permission' => true,
1393
            ],
1394
        ];
1395
        $routeFactory
1396
            ->createRoute('/products/', $indexDefaults, [], [], '', [], ['GET'])
1397
            ->willReturn($indexRoute)
1398
        ;
1399
        $routeCollection->add('sylius_product_index', $indexRoute)->shouldBeCalled();
1400
1401
        $createDefaults = [
1402
            '_controller' => 'sylius.controller.product:createAction',
1403
            '_sylius' => [
1404
                'permission' => true,
1405
            ],
1406
        ];
1407
        $routeFactory
1408
            ->createRoute('/products/new', $createDefaults, [], [], '', [], ['GET', 'POST'])
1409
            ->willReturn($createRoute)
1410
        ;
1411
        $routeCollection->add('sylius_product_create', $createRoute)->shouldBeCalled();
1412
1413
        $updateDefaults = [
1414
            '_controller' => 'sylius.controller.product:updateAction',
1415
            '_sylius' => [
1416
                'permission' => true,
1417
            ],
1418
        ];
1419
        $routeFactory
1420
            ->createRoute('/products/{id}/edit', $updateDefaults, [], [], '', [], ['GET', 'PUT', 'PATCH'])
1421
            ->willReturn($updateRoute)
1422
        ;
1423
        $routeCollection->add('sylius_product_update', $updateRoute)->shouldBeCalled();
1424
1425
        $bulkDeleteDefaults = [
1426
            '_controller' => 'sylius.controller.product:bulkDeleteAction',
1427
            '_sylius' => [
1428
                'permission' => true,
1429
                'paginate' => false,
1430
                'repository' => [
1431
                    'method' => 'findById',
1432
                    'arguments' => ['$ids'],
1433
                ],
1434
            ],
1435
        ];
1436
        $routeFactory
1437
            ->createRoute('/products/bulk-delete', $bulkDeleteDefaults, [], [], '', [], ['DELETE'])
1438
            ->willReturn($bulkDeleteRoute)
1439
        ;
1440
        $routeCollection->add('sylius_product_bulk_delete', $bulkDeleteRoute)->shouldBeCalled();
1441
1442
        $deleteDefaults = [
1443
            '_controller' => 'sylius.controller.product:deleteAction',
1444
            '_sylius' => [
1445
                'permission' => true,
1446
            ],
1447
        ];
1448
        $routeFactory->createRoute('/products/{id}', $deleteDefaults, [], [], '', [], ['DELETE'])
1449
                     ->willReturn($deleteRoute);
1450
        $routeCollection->add('sylius_product_delete', $deleteRoute)->shouldBeCalled();
1451
1452
        $this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection);
1453
    }
1454
1455
    function it_supports_sylius_resource_type(): void
1456
    {
1457
        $this->supports('sylius.product', 'sylius.resource')->shouldReturn(true);
1458
        $this->supports('sylius.product', 'sylius.resource_api')->shouldReturn(true);
1459
        $this->supports('sylius.product', 'abc')->shouldReturn(false);
1460
    }
1461
}
1462