Completed
Push — 1.1 ( 9d9074...b5b13c )
by Kamil
23:25
created

ResourceControllerSpec::nullifyDates()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
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\Controller;
15
16
use Doctrine\Common\Persistence\ObjectManager;
17
use FOS\RestBundle\View\View;
18
use PhpSpec\ObjectBehavior;
19
use PhpSpec\Wrapper\Collaborator;
20
use Prophecy\Argument;
21
use Sylius\Bundle\ResourceBundle\Controller\AuthorizationCheckerInterface;
22
use Sylius\Bundle\ResourceBundle\Controller\EventDispatcherInterface;
23
use Sylius\Bundle\ResourceBundle\Controller\FlashHelperInterface;
24
use Sylius\Bundle\ResourceBundle\Controller\NewResourceFactoryInterface;
25
use Sylius\Bundle\ResourceBundle\Controller\RedirectHandlerInterface;
26
use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration;
27
use Sylius\Bundle\ResourceBundle\Controller\RequestConfigurationFactoryInterface;
28
use Sylius\Bundle\ResourceBundle\Controller\ResourceDeleteHandlerInterface;
29
use Sylius\Bundle\ResourceBundle\Controller\ResourceFormFactoryInterface;
30
use Sylius\Bundle\ResourceBundle\Controller\ResourcesCollectionProviderInterface;
31
use Sylius\Bundle\ResourceBundle\Controller\ResourceUpdateHandlerInterface;
32
use Sylius\Bundle\ResourceBundle\Controller\SingleResourceProviderInterface;
33
use Sylius\Bundle\ResourceBundle\Controller\StateMachineInterface;
34
use Sylius\Bundle\ResourceBundle\Controller\ViewHandlerInterface;
35
use Sylius\Bundle\ResourceBundle\Event\ResourceControllerEvent;
36
use Sylius\Component\Resource\Exception\DeleteHandlingException;
37
use Sylius\Component\Resource\Factory\FactoryInterface;
38
use Sylius\Component\Resource\Metadata\MetadataInterface;
39
use Sylius\Component\Resource\Model\ResourceInterface;
40
use Sylius\Component\Resource\Repository\RepositoryInterface;
41
use Sylius\Component\Resource\ResourceActions;
42
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
43
use Symfony\Component\DependencyInjection\ContainerInterface;
44
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
45
use Symfony\Component\Form\Form;
46
use Symfony\Component\Form\FormView;
47
use Symfony\Component\HttpFoundation\ParameterBag;
48
use Symfony\Component\HttpFoundation\Request;
49
use Symfony\Component\HttpFoundation\Response;
50
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
51
use Symfony\Component\HttpKernel\Exception\HttpException;
52
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
53
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
54
use Symfony\Component\Security\Csrf\CsrfToken;
55
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
56
57
final class ResourceControllerSpec extends ObjectBehavior
58
{
59
    function let(
60
        MetadataInterface $metadata,
61
        RequestConfigurationFactoryInterface $requestConfigurationFactory,
62
        ViewHandlerInterface $viewHandler,
63
        RepositoryInterface $repository,
64
        FactoryInterface $factory,
65
        NewResourceFactoryInterface $newResourceFactory,
66
        ObjectManager $manager,
67
        SingleResourceProviderInterface $singleResourceProvider,
68
        ResourcesCollectionProviderInterface $resourcesCollectionProvider,
69
        ResourceFormFactoryInterface $resourceFormFactory,
70
        RedirectHandlerInterface $redirectHandler,
71
        FlashHelperInterface $flashHelper,
72
        AuthorizationCheckerInterface $authorizationChecker,
73
        EventDispatcherInterface $eventDispatcher,
74
        StateMachineInterface $stateMachine,
75
        ResourceUpdateHandlerInterface $resourceUpdateHandler,
76
        ResourceDeleteHandlerInterface $resourceDeleteHandler,
77
        ContainerInterface $container
78
    ): void {
79
        $this->beConstructedWith(
80
            $metadata,
81
            $requestConfigurationFactory,
82
            $viewHandler,
83
            $repository,
84
            $factory,
85
            $newResourceFactory,
86
            $manager,
87
            $singleResourceProvider,
88
            $resourcesCollectionProvider,
89
            $resourceFormFactory,
90
            $redirectHandler,
91
            $flashHelper,
92
            $authorizationChecker,
93
            $eventDispatcher,
94
            $stateMachine,
95
            $resourceUpdateHandler,
96
            $resourceDeleteHandler
97
        );
98
99
        $this->setContainer($container);
100
    }
101
102
    function it_extends_base_Symfony_controller(): void
0 ignored issues
show
Coding Style introduced by
function it_extends_base_Symfony_controller() 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...
103
    {
104
        $this->shouldHaveType(Controller::class);
105
    }
106
107
    function it_throws_a_403_exception_if_user_is_unauthorized_to_view_a_single_resource(
108
        MetadataInterface $metadata,
109
        RequestConfigurationFactoryInterface $requestConfigurationFactory,
110
        RequestConfiguration $configuration,
111
        Request $request,
112
        AuthorizationCheckerInterface $authorizationChecker
113
    ): void {
114
        $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Bundle\Res...r\RequestConfiguration>.

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...
115
        $configuration->hasPermission()->willReturn(true);
116
        $configuration->getPermission(ResourceActions::SHOW)->willReturn('sylius.product.show');
117
118
        $authorizationChecker->isGranted($configuration, 'sylius.product.show')->willReturn(false);
119
120
        $this
121
            ->shouldThrow(new AccessDeniedException())
122
            ->during('showAction', [$request])
123
        ;
124
    }
125
126
    function it_throws_a_404_exception_if_resource_is_not_found_based_on_configuration(
127
        MetadataInterface $metadata,
128
        RequestConfigurationFactoryInterface $requestConfigurationFactory,
129
        RequestConfiguration $configuration,
130
        Request $request,
131
        AuthorizationCheckerInterface $authorizationChecker,
132
        RepositoryInterface $repository,
133
        SingleResourceProviderInterface $singleResourceProvider
134
    ): void {
135
        $metadata->getHumanizedName()->willReturn('product');
136
        $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Bundle\Res...r\RequestConfiguration>.

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...
137
        $configuration->hasPermission()->willReturn(true);
138
        $configuration->getPermission(ResourceActions::SHOW)->willReturn('sylius.product.show');
139
140
        $authorizationChecker->isGranted($configuration, 'sylius.product.show')->willReturn(true);
141
        $singleResourceProvider->get($configuration, $repository)->willReturn(null);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...odel\ResourceInterface>.

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...
142
143
        $this
144
            ->shouldThrow(new NotFoundHttpException('The "product" has not been found'))
145
            ->during('showAction', [$request])
146
        ;
147
    }
148
149
    function it_returns_a_response_for_html_view_of_a_single_resource(
150
        MetadataInterface $metadata,
151
        RequestConfigurationFactoryInterface $requestConfigurationFactory,
152
        RequestConfiguration $configuration,
153
        AuthorizationCheckerInterface $authorizationChecker,
154
        RepositoryInterface $repository,
155
        SingleResourceProviderInterface $singleResourceProvider,
156
        ResourceInterface $resource,
157
        ViewHandlerInterface $viewHandler,
158
        EventDispatcherInterface $eventDispatcher,
159
        Request $request,
160
        Response $response
161
    ): void {
162
        $metadata->getApplicationName()->willReturn('sylius');
163
        $metadata->getName()->willReturn('product');
164
165
        $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Bundle\Res...r\RequestConfiguration>.

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...
166
        $configuration->hasPermission()->willReturn(true);
167
        $configuration->getPermission(ResourceActions::SHOW)->willReturn('sylius.product.show');
168
169
        $authorizationChecker->isGranted($configuration, 'sylius.product.show')->willReturn(true);
170
        $singleResourceProvider->get($configuration, $repository)->willReturn($resource);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...odel\ResourceInterface>.

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...
171
172
        $configuration->isHtmlRequest()->willReturn(true);
173
        $configuration->getTemplate(ResourceActions::SHOW . '.html')->willReturn('SyliusShopBundle:Product:show.html.twig');
174
175
        $eventDispatcher->dispatch(ResourceActions::SHOW, $configuration, $resource)->shouldBeCalled();
176
177
        $expectedView = View::create()
178
            ->setData([
179
                'configuration' => $configuration,
180
                'metadata' => $metadata,
181
                'resource' => $resource,
182
                'product' => $resource,
183
            ])
184
            ->setTemplateVar('product')
185
            ->setTemplate('SyliusShopBundle:Product:show.html.twig')
186
        ;
187
188
        $viewHandler->handle($configuration, Argument::that($this->getViewComparingCallback($expectedView)))->willReturn($response);
189
190
        $this->showAction($request)->shouldReturn($response);
191
    }
192
193
    function it_returns_a_response_for_non_html_view_of_single_resource(
194
        MetadataInterface $metadata,
195
        RequestConfigurationFactoryInterface $requestConfigurationFactory,
196
        RequestConfiguration $configuration,
197
        AuthorizationCheckerInterface $authorizationChecker,
198
        RepositoryInterface $repository,
199
        SingleResourceProviderInterface $singleResourceProvider,
200
        ResourceInterface $resource,
201
        ViewHandlerInterface $viewHandler,
202
        EventDispatcherInterface $eventDispatcher,
203
        Request $request,
204
        Response $response
205
    ): void {
206
        $metadata->getApplicationName()->willReturn('sylius');
207
        $metadata->getName()->willReturn('product');
208
209
        $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Bundle\Res...r\RequestConfiguration>.

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...
210
        $configuration->hasPermission()->willReturn(true);
211
        $configuration->getPermission(ResourceActions::SHOW)->willReturn('sylius.product.show');
212
213
        $authorizationChecker->isGranted($configuration, 'sylius.product.show')->willReturn(true);
214
        $singleResourceProvider->get($configuration, $repository)->willReturn($resource);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...odel\ResourceInterface>.

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...
215
216
        $configuration->isHtmlRequest()->willReturn(false);
217
218
        $eventDispatcher->dispatch(ResourceActions::SHOW, $configuration, $resource)->shouldBeCalled();
219
220
        $expectedView = View::create($resource);
221
222
        $viewHandler->handle($configuration, Argument::that($this->getViewComparingCallback($expectedView)))->willReturn($response);
223
224
        $this->showAction($request)->shouldReturn($response);
225
    }
226
227
    function it_throws_a_403_exception_if_user_is_unauthorized_to_view_an_index_of_resources(
228
        MetadataInterface $metadata,
229
        RequestConfigurationFactoryInterface $requestConfigurationFactory,
230
        RequestConfiguration $configuration,
231
        Request $request,
232
        AuthorizationCheckerInterface $authorizationChecker
233
    ): void {
234
        $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Bundle\Res...r\RequestConfiguration>.

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...
235
        $configuration->hasPermission()->willReturn(true);
236
        $configuration->getPermission(ResourceActions::INDEX)->willReturn('sylius.product.index');
237
238
        $authorizationChecker->isGranted($configuration, 'sylius.product.index')->willReturn(false);
239
240
        $this
241
            ->shouldThrow(new AccessDeniedException())
242
            ->during('indexAction', [$request])
243
        ;
244
    }
245
246
    function it_returns_a_response_for_html_view_of_paginated_resources(
247
        MetadataInterface $metadata,
248
        RequestConfigurationFactoryInterface $requestConfigurationFactory,
249
        RequestConfiguration $configuration,
250
        AuthorizationCheckerInterface $authorizationChecker,
251
        RepositoryInterface $repository,
252
        ResourcesCollectionProviderInterface $resourcesCollectionProvider,
253
        EventDispatcherInterface $eventDispatcher,
254
        ResourceInterface $resource1,
255
        ResourceInterface $resource2,
256
        ViewHandlerInterface $viewHandler,
257
        Request $request,
258
        Response $response
259
    ): void {
260
        $metadata->getApplicationName()->willReturn('sylius');
261
        $metadata->getName()->willReturn('product');
262
        $metadata->getPluralName()->willReturn('products');
263
264
        $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Bundle\Res...r\RequestConfiguration>.

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...
265
        $configuration->hasPermission()->willReturn(true);
266
        $configuration->getPermission(ResourceActions::INDEX)->willReturn('sylius.product.index');
267
268
        $authorizationChecker->isGranted($configuration, 'sylius.product.index')->willReturn(true);
269
270
        $configuration->isHtmlRequest()->willReturn(true);
271
        $configuration->getTemplate(ResourceActions::INDEX . '.html')->willReturn('SyliusShopBundle:Product:index.html.twig');
272
        $resourcesCollectionProvider->get($configuration, $repository)->willReturn([$resource1, $resource2]);
273
274
        $eventDispatcher->dispatchMultiple(ResourceActions::INDEX, $configuration, [$resource1, $resource2])->shouldBeCalled();
275
276
        $expectedView = View::create()
277
            ->setData([
278
                'configuration' => $configuration,
279
                'metadata' => $metadata,
280
                'resources' => [$resource1, $resource2],
281
                'products' => [$resource1, $resource2],
282
            ])
283
            ->setTemplateVar('products')
284
            ->setTemplate('SyliusShopBundle:Product:index.html.twig')
285
        ;
286
287
        $viewHandler->handle($configuration, Argument::that($this->getViewComparingCallback($expectedView)))->willReturn($response);
288
289
        $this->indexAction($request)->shouldReturn($response);
290
    }
291
292
    function it_throws_a_403_exception_if_user_is_unauthorized_to_create_a_new_resource(
293
        MetadataInterface $metadata,
294
        RequestConfigurationFactoryInterface $requestConfigurationFactory,
295
        RequestConfiguration $configuration,
296
        Request $request,
297
        AuthorizationCheckerInterface $authorizationChecker
298
    ): void {
299
        $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Bundle\Res...r\RequestConfiguration>.

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...
300
        $configuration->hasPermission()->willReturn(true);
301
        $configuration->getPermission(ResourceActions::CREATE)->willReturn('sylius.product.create');
302
303
        $authorizationChecker->isGranted($configuration, 'sylius.product.create')->willReturn(false);
304
305
        $this
306
            ->shouldThrow(new AccessDeniedException())
307
            ->during('createAction', [$request])
308
        ;
309
    }
310
311
    function it_returns_a_html_response_for_creating_new_resource_form(
312
        MetadataInterface $metadata,
313
        RequestConfigurationFactoryInterface $requestConfigurationFactory,
314
        RequestConfiguration $configuration,
315
        AuthorizationCheckerInterface $authorizationChecker,
316
        ViewHandlerInterface $viewHandler,
317
        FactoryInterface $factory,
318
        NewResourceFactoryInterface $newResourceFactory,
319
        ResourceInterface $newResource,
320
        ResourceFormFactoryInterface $resourceFormFactory,
321
        EventDispatcherInterface $eventDispatcher,
322
        ResourceControllerEvent $event,
323
        Form $form,
324
        FormView $formView,
325
        Request $request,
326
        Response $response
327
    ): void {
328
        $metadata->getApplicationName()->willReturn('sylius');
329
        $metadata->getName()->willReturn('product');
330
331
        $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Bundle\Res...r\RequestConfiguration>.

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...
332
        $configuration->hasPermission()->willReturn(true);
333
        $configuration->getPermission(ResourceActions::CREATE)->willReturn('sylius.product.create');
334
335
        $authorizationChecker->isGranted($configuration, 'sylius.product.create')->willReturn(true);
336
337
        $configuration->isHtmlRequest()->willReturn(true);
338
        $configuration->getTemplate(ResourceActions::CREATE . '.html')->willReturn('SyliusShopBundle:Product:create.html.twig');
339
340
        $newResourceFactory->create($configuration, $factory)->willReturn($newResource);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...odel\ResourceInterface>.

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...
341
        $resourceFormFactory->create($configuration, $newResource)->willReturn($form);
342
343
        $eventDispatcher->dispatchInitializeEvent(ResourceActions::CREATE, $configuration, $newResource)->willReturn($event);
344
345
        $request->isMethod('POST')->willReturn(false);
346
        $form->createView()->willReturn($formView);
347
348
        $expectedView = View::create()
349
            ->setData([
350
                'configuration' => $configuration,
351
                'metadata' => $metadata,
352
                'resource' => $newResource,
353
                'product' => $newResource,
354
                'form' => $formView,
355
            ])
356
            ->setTemplate('SyliusShopBundle:Product:create.html.twig')
357
        ;
358
359
        $viewHandler->handle($configuration, Argument::that($this->getViewComparingCallback($expectedView)))->willReturn($response);
360
361
        $this->createAction($request)->shouldReturn($response);
362
    }
363
364
    function it_returns_a_html_response_for_invalid_form_during_resource_creation(
365
        MetadataInterface $metadata,
366
        RequestConfigurationFactoryInterface $requestConfigurationFactory,
367
        RequestConfiguration $configuration,
368
        AuthorizationCheckerInterface $authorizationChecker,
369
        ViewHandlerInterface $viewHandler,
370
        FactoryInterface $factory,
371
        NewResourceFactoryInterface $newResourceFactory,
372
        ResourceInterface $newResource,
373
        ResourceFormFactoryInterface $resourceFormFactory,
374
        EventDispatcherInterface $eventDispatcher,
375
        ResourceControllerEvent $event,
376
        Form $form,
377
        FormView $formView,
378
        Request $request,
379
        Response $response
380
    ): void {
381
        $metadata->getApplicationName()->willReturn('sylius');
382
        $metadata->getName()->willReturn('product');
383
384
        $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Bundle\Res...r\RequestConfiguration>.

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...
385
        $configuration->hasPermission()->willReturn(true);
386
        $configuration->getPermission(ResourceActions::CREATE)->willReturn('sylius.product.create');
387
388
        $authorizationChecker->isGranted($configuration, 'sylius.product.create')->willReturn(true);
389
390
        $configuration->isHtmlRequest()->willReturn(true);
391
        $configuration->getTemplate(ResourceActions::CREATE . '.html')->willReturn('SyliusShopBundle:Product:create.html.twig');
392
393
        $newResourceFactory->create($configuration, $factory)->willReturn($newResource);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...odel\ResourceInterface>.

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...
394
        $resourceFormFactory->create($configuration, $newResource)->willReturn($form);
395
396
        $eventDispatcher->dispatchInitializeEvent(ResourceActions::CREATE, $configuration, $newResource)->willReturn($event);
397
398
        $request->isMethod('POST')->willReturn(true);
399
        $form->handleRequest($request)->willReturn($form);
400
        $form->isValid()->willReturn(false);
401
        $form->createView()->willReturn($formView);
402
403
        $expectedView = View::create()
404
            ->setData([
405
                'configuration' => $configuration,
406
                'metadata' => $metadata,
407
                'resource' => $newResource,
408
                'product' => $newResource,
409
                'form' => $formView,
410
            ])
411
            ->setTemplate('SyliusShopBundle:Product:create.html.twig')
412
        ;
413
414
        $viewHandler->handle($configuration, Argument::that($this->getViewComparingCallback($expectedView)))->willReturn($response);
415
416
        $this->createAction($request)->shouldReturn($response);
417
    }
418
419
    function it_returns_a_non_html_response_for_invalid_form_during_resource_creation(
420
        MetadataInterface $metadata,
421
        RequestConfigurationFactoryInterface $requestConfigurationFactory,
422
        RequestConfiguration $configuration,
423
        AuthorizationCheckerInterface $authorizationChecker,
424
        ViewHandlerInterface $viewHandler,
425
        FactoryInterface $factory,
426
        NewResourceFactoryInterface $newResourceFactory,
427
        ResourceInterface $newResource,
428
        ResourceFormFactoryInterface $resourceFormFactory,
429
        Form $form,
430
        Request $request,
431
        Response $response
432
    ): void {
433
        $metadata->getApplicationName()->willReturn('sylius');
434
        $metadata->getName()->willReturn('product');
435
436
        $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Bundle\Res...r\RequestConfiguration>.

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...
437
        $configuration->hasPermission()->willReturn(true);
438
        $configuration->getPermission(ResourceActions::CREATE)->willReturn('sylius.product.create');
439
440
        $authorizationChecker->isGranted($configuration, 'sylius.product.create')->willReturn(true);
441
442
        $configuration->isHtmlRequest()->willReturn(false);
443
        $configuration->getTemplate(ResourceActions::CREATE . '.html')->willReturn('SyliusShopBundle:Product:create.html.twig');
444
445
        $newResourceFactory->create($configuration, $factory)->willReturn($newResource);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...odel\ResourceInterface>.

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...
446
        $resourceFormFactory->create($configuration, $newResource)->willReturn($form);
447
448
        $request->isMethod('POST')->willReturn(true);
449
        $form->handleRequest($request)->willReturn($form);
450
        $form->isValid()->willReturn(false);
451
452
        $expectedView = View::create($form, 400);
453
454
        $viewHandler->handle($configuration, Argument::that($this->getViewComparingCallback($expectedView)))->willReturn($response);
455
456
        $this->createAction($request)->shouldReturn($response);
457
    }
458
459
    function it_does_not_create_the_resource_and_redirects_to_index_for_html_requests_stopped_via_events(
460
        MetadataInterface $metadata,
461
        RequestConfigurationFactoryInterface $requestConfigurationFactory,
462
        RequestConfiguration $configuration,
463
        AuthorizationCheckerInterface $authorizationChecker,
464
        ViewHandlerInterface $viewHandler,
465
        FactoryInterface $factory,
466
        NewResourceFactoryInterface $newResourceFactory,
467
        RepositoryInterface $repository,
468
        ResourceInterface $newResource,
469
        ResourceFormFactoryInterface $resourceFormFactory,
470
        Form $form,
471
        RedirectHandlerInterface $redirectHandler,
472
        FlashHelperInterface $flashHelper,
473
        EventDispatcherInterface $eventDispatcher,
474
        ResourceControllerEvent $event,
475
        Request $request,
476
        Response $redirectResponse
477
    ): void {
478
        $metadata->getApplicationName()->willReturn('sylius');
479
        $metadata->getName()->willReturn('product');
480
481
        $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Bundle\Res...r\RequestConfiguration>.

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...
482
        $configuration->hasPermission()->willReturn(true);
483
        $configuration->getPermission(ResourceActions::CREATE)->willReturn('sylius.product.create');
484
485
        $authorizationChecker->isGranted($configuration, 'sylius.product.create')->willReturn(true);
486
487
        $configuration->isHtmlRequest()->willReturn(true);
488
        $configuration->getTemplate(ResourceActions::CREATE . '.html')->willReturn('SyliusShopBundle:Product:create.html.twig');
489
490
        $newResourceFactory->create($configuration, $factory)->willReturn($newResource);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...odel\ResourceInterface>.

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...
491
        $resourceFormFactory->create($configuration, $newResource)->willReturn($form);
492
493
        $request->isMethod('POST')->willReturn(true);
494
        $form->handleRequest($request)->willReturn($form);
495
        $form->isValid()->willReturn(true);
496
        $form->getData()->willReturn($newResource);
497
498
        $eventDispatcher->dispatchPreEvent(ResourceActions::CREATE, $configuration, $newResource)->willReturn($event);
499
        $event->isStopped()->willReturn(true);
500
501
        $flashHelper->addFlashFromEvent($configuration, $event)->shouldBeCalled();
502
503
        $event->hasResponse()->willReturn(false);
504
505
        $repository->add($newResource)->shouldNotBeCalled();
506
        $eventDispatcher->dispatchPostEvent(ResourceActions::CREATE, $configuration, $newResource)->shouldNotBeCalled();
507
        $flashHelper->addSuccessFlash(Argument::any())->shouldNotBeCalled();
0 ignored issues
show
Bug introduced by
The call to addSuccessFlash() misses a required argument $actionName.

This check looks for function calls that miss required arguments.

Loading history...
508
509
        $redirectHandler->redirectToIndex($configuration, $newResource)->willReturn($redirectResponse);
510
511
        $this->createAction($request)->shouldReturn($redirectResponse);
512
    }
513
514
    function it_does_not_create_the_resource_and_return_response_for_html_requests_stopped_via_events(
515
        MetadataInterface $metadata,
516
        RequestConfigurationFactoryInterface $requestConfigurationFactory,
517
        RequestConfiguration $configuration,
518
        AuthorizationCheckerInterface $authorizationChecker,
519
        FactoryInterface $factory,
520
        NewResourceFactoryInterface $newResourceFactory,
521
        RepositoryInterface $repository,
522
        ResourceInterface $newResource,
523
        ResourceFormFactoryInterface $resourceFormFactory,
524
        Form $form,
525
        FlashHelperInterface $flashHelper,
526
        EventDispatcherInterface $eventDispatcher,
527
        ResourceControllerEvent $event,
528
        Request $request,
529
        Response $response
530
    ): void {
531
        $metadata->getApplicationName()->willReturn('sylius');
532
        $metadata->getName()->willReturn('product');
533
534
        $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Bundle\Res...r\RequestConfiguration>.

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...
535
        $configuration->hasPermission()->willReturn(true);
536
        $configuration->getPermission(ResourceActions::CREATE)->willReturn('sylius.product.create');
537
538
        $authorizationChecker->isGranted($configuration, 'sylius.product.create')->willReturn(true);
539
540
        $configuration->isHtmlRequest()->willReturn(true);
541
        $configuration->getTemplate(ResourceActions::CREATE . '.html')->willReturn('SyliusShopBundle:Product:create.html.twig');
542
543
        $newResourceFactory->create($configuration, $factory)->willReturn($newResource);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...odel\ResourceInterface>.

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...
544
        $resourceFormFactory->create($configuration, $newResource)->willReturn($form);
545
546
        $request->isMethod('POST')->willReturn(true);
547
        $form->handleRequest($request)->willReturn($form);
548
        $form->isValid()->willReturn(true);
549
        $form->getData()->willReturn($newResource);
550
551
        $eventDispatcher->dispatchPreEvent(ResourceActions::CREATE, $configuration, $newResource)->willReturn($event);
552
        $event->isStopped()->willReturn(true);
553
554
        $flashHelper->addFlashFromEvent($configuration, $event)->shouldBeCalled();
555
556
        $event->hasResponse()->willReturn(true);
557
        $event->getResponse()->willReturn($response);
558
559
        $repository->add($newResource)->shouldNotBeCalled();
560
        $eventDispatcher->dispatchPostEvent(ResourceActions::CREATE, $configuration, $newResource)->shouldNotBeCalled();
561
        $flashHelper->addSuccessFlash(Argument::any())->shouldNotBeCalled();
0 ignored issues
show
Bug introduced by
The call to addSuccessFlash() misses a required argument $actionName.

This check looks for function calls that miss required arguments.

Loading history...
562
563
        $this->createAction($request)->shouldReturn($response);
564
    }
565
566
    function it_redirects_to_newly_created_resource(
567
        MetadataInterface $metadata,
568
        RequestConfigurationFactoryInterface $requestConfigurationFactory,
569
        RequestConfiguration $configuration,
570
        AuthorizationCheckerInterface $authorizationChecker,
571
        ViewHandlerInterface $viewHandler,
572
        FactoryInterface $factory,
573
        NewResourceFactoryInterface $newResourceFactory,
574
        RepositoryInterface $repository,
575
        ResourceInterface $newResource,
576
        ResourceFormFactoryInterface $resourceFormFactory,
577
        StateMachineInterface $stateMachine,
578
        Form $form,
579
        RedirectHandlerInterface $redirectHandler,
580
        FlashHelperInterface $flashHelper,
581
        EventDispatcherInterface $eventDispatcher,
582
        ResourceControllerEvent $event,
583
        ResourceControllerEvent $postEvent,
584
        Request $request,
585
        Response $redirectResponse
586
    ): void {
587
        $metadata->getApplicationName()->willReturn('sylius');
588
        $metadata->getName()->willReturn('product');
589
590
        $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Bundle\Res...r\RequestConfiguration>.

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...
591
        $configuration->hasPermission()->willReturn(true);
592
        $configuration->getPermission(ResourceActions::CREATE)->willReturn('sylius.product.create');
593
        $configuration->hasStateMachine()->willReturn(true);
594
595
        $authorizationChecker->isGranted($configuration, 'sylius.product.create')->willReturn(true);
596
597
        $configuration->isHtmlRequest()->willReturn(true);
598
        $configuration->getTemplate(ResourceActions::CREATE . '.html')->willReturn('SyliusShopBundle:Product:create.html.twig');
599
600
        $newResourceFactory->create($configuration, $factory)->willReturn($newResource);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...odel\ResourceInterface>.

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...
601
        $resourceFormFactory->create($configuration, $newResource)->willReturn($form);
602
603
        $request->isMethod('POST')->willReturn(true);
604
        $form->handleRequest($request)->willReturn($form);
605
        $form->isValid()->willReturn(true);
606
        $form->getData()->willReturn($newResource);
607
608
        $eventDispatcher->dispatchPreEvent(ResourceActions::CREATE, $configuration, $newResource)->willReturn($event);
609
        $event->isStopped()->willReturn(false);
610
611
        $stateMachine->apply($configuration, $newResource)->shouldBeCalled();
612
613
        $repository->add($newResource)->shouldBeCalled();
614
        $eventDispatcher->dispatchPostEvent(ResourceActions::CREATE, $configuration, $newResource)->willReturn($postEvent);
615
616
        $postEvent->hasResponse()->willReturn(false);
617
618
        $flashHelper->addSuccessFlash($configuration, ResourceActions::CREATE, $newResource)->shouldBeCalled();
619
        $redirectHandler->redirectToResource($configuration, $newResource)->willReturn($redirectResponse);
620
621
        $this->createAction($request)->shouldReturn($redirectResponse);
622
    }
623
624
    function it_uses_response_from_post_create_event_if_defined(
625
        MetadataInterface $metadata,
626
        RequestConfigurationFactoryInterface $requestConfigurationFactory,
627
        RequestConfiguration $configuration,
628
        AuthorizationCheckerInterface $authorizationChecker,
629
        FactoryInterface $factory,
630
        NewResourceFactoryInterface $newResourceFactory,
631
        RepositoryInterface $repository,
632
        ResourceInterface $newResource,
633
        ResourceFormFactoryInterface $resourceFormFactory,
634
        StateMachineInterface $stateMachine,
635
        Form $form,
636
        FlashHelperInterface $flashHelper,
637
        EventDispatcherInterface $eventDispatcher,
638
        ResourceControllerEvent $event,
639
        ResourceControllerEvent $postEvent,
640
        Request $request,
641
        Response $redirectResponse
642
    ): void {
643
        $metadata->getApplicationName()->willReturn('sylius');
644
        $metadata->getName()->willReturn('product');
645
646
        $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Bundle\Res...r\RequestConfiguration>.

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...
647
        $configuration->hasPermission()->willReturn(true);
648
        $configuration->getPermission(ResourceActions::CREATE)->willReturn('sylius.product.create');
649
        $configuration->hasStateMachine()->willReturn(true);
650
651
        $authorizationChecker->isGranted($configuration, 'sylius.product.create')->willReturn(true);
652
653
        $configuration->isHtmlRequest()->willReturn(true);
654
        $configuration->getTemplate(ResourceActions::CREATE . '.html')->willReturn('SyliusShopBundle:Product:create.html.twig');
655
656
        $newResourceFactory->create($configuration, $factory)->willReturn($newResource);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...odel\ResourceInterface>.

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...
657
        $resourceFormFactory->create($configuration, $newResource)->willReturn($form);
658
659
        $request->isMethod('POST')->willReturn(true);
660
        $form->handleRequest($request)->willReturn($form);
661
        $form->isValid()->willReturn(true);
662
        $form->getData()->willReturn($newResource);
663
664
        $eventDispatcher->dispatchPreEvent(ResourceActions::CREATE, $configuration, $newResource)->willReturn($event);
665
        $event->isStopped()->willReturn(false);
666
667
        $stateMachine->apply($configuration, $newResource)->shouldBeCalled();
668
669
        $repository->add($newResource)->shouldBeCalled();
670
        $eventDispatcher->dispatchPostEvent(ResourceActions::CREATE, $configuration, $newResource)->willReturn($postEvent);
671
        $flashHelper->addSuccessFlash($configuration, ResourceActions::CREATE, $newResource)->shouldBeCalled();
672
673
        $postEvent->hasResponse()->willReturn(true);
674
        $postEvent->getResponse()->willReturn($redirectResponse);
675
676
        $this->createAction($request)->shouldReturn($redirectResponse);
677
    }
678
679
    function it_returns_a_non_html_response_for_correctly_created_resources(
680
        MetadataInterface $metadata,
681
        RequestConfigurationFactoryInterface $requestConfigurationFactory,
682
        RequestConfiguration $configuration,
683
        AuthorizationCheckerInterface $authorizationChecker,
684
        ViewHandlerInterface $viewHandler,
685
        FactoryInterface $factory,
686
        NewResourceFactoryInterface $newResourceFactory,
687
        RepositoryInterface $repository,
688
        ResourceInterface $newResource,
689
        ResourceFormFactoryInterface $resourceFormFactory,
690
        FlashHelperInterface $flashHelper,
691
        EventDispatcherInterface $eventDispatcher,
692
        ResourceControllerEvent $event,
693
        StateMachineInterface $stateMachine,
694
        Form $form,
695
        Request $request,
696
        Response $response
697
    ): void {
698
        $metadata->getApplicationName()->willReturn('sylius');
699
        $metadata->getName()->willReturn('product');
700
701
        $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Bundle\Res...r\RequestConfiguration>.

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...
702
        $configuration->hasPermission()->willReturn(true);
703
        $configuration->getPermission(ResourceActions::CREATE)->willReturn('sylius.product.create');
704
        $configuration->hasStateMachine()->willReturn(true);
705
706
        $authorizationChecker->isGranted($configuration, 'sylius.product.create')->willReturn(true);
707
708
        $configuration->isHtmlRequest()->willReturn(false);
709
        $configuration->getTemplate(ResourceActions::CREATE . '.html')->willReturn('SyliusShopBundle:Product:create.html.twig');
710
711
        $newResourceFactory->create($configuration, $factory)->willReturn($newResource);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...odel\ResourceInterface>.

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...
712
        $resourceFormFactory->create($configuration, $newResource)->willReturn($form);
713
714
        $request->isMethod('POST')->willReturn(true);
715
        $form->handleRequest($request)->willReturn($form);
716
        $form->isValid()->willReturn(true);
717
        $form->getData()->willReturn($newResource);
718
719
        $eventDispatcher->dispatchPreEvent(ResourceActions::CREATE, $configuration, $newResource)->willReturn($event);
720
        $event->isStopped()->willReturn(false);
721
722
        $stateMachine->apply($configuration, $newResource)->shouldBeCalled();
723
724
        $repository->add($newResource)->shouldBeCalled();
725
        $eventDispatcher->dispatchPostEvent(ResourceActions::CREATE, $configuration, $newResource)->shouldBeCalled();
726
727
        $flashHelper->addSuccessFlash(Argument::any())->shouldNotBeCalled();
0 ignored issues
show
Bug introduced by
The call to addSuccessFlash() misses a required argument $actionName.

This check looks for function calls that miss required arguments.

Loading history...
728
729
        $expectedView = View::create($newResource, 201);
730
731
        $viewHandler->handle($configuration, Argument::that($this->getViewComparingCallback($expectedView)))->willReturn($response);
732
733
        $this->createAction($request)->shouldReturn($response);
734
    }
735
736
    function it_does_not_create_the_resource_and_throws_http_exception_for_non_html_requests_stopped_via_event(
737
        MetadataInterface $metadata,
738
        RequestConfigurationFactoryInterface $requestConfigurationFactory,
739
        RequestConfiguration $configuration,
740
        AuthorizationCheckerInterface $authorizationChecker,
741
        FactoryInterface $factory,
742
        NewResourceFactoryInterface $newResourceFactory,
743
        RepositoryInterface $repository,
744
        ResourceInterface $newResource,
745
        ResourceFormFactoryInterface $resourceFormFactory,
746
        FlashHelperInterface $flashHelper,
747
        EventDispatcherInterface $eventDispatcher,
748
        Form $form,
749
        Request $request,
750
        ResourceControllerEvent $event
751
    ): void {
752
        $metadata->getApplicationName()->willReturn('sylius');
753
        $metadata->getName()->willReturn('product');
754
755
        $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Bundle\Res...r\RequestConfiguration>.

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...
756
        $configuration->hasPermission()->willReturn(true);
757
        $configuration->getPermission(ResourceActions::CREATE)->willReturn('sylius.product.create');
758
759
        $authorizationChecker->isGranted($configuration, 'sylius.product.create')->willReturn(true);
760
761
        $configuration->isHtmlRequest()->willReturn(false);
762
        $configuration->getTemplate(ResourceActions::CREATE . '.html')->willReturn('SyliusShopBundle:Product:create.html.twig');
763
764
        $newResourceFactory->create($configuration, $factory)->willReturn($newResource);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...odel\ResourceInterface>.

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...
765
        $resourceFormFactory->create($configuration, $newResource)->willReturn($form);
766
767
        $request->isMethod('POST')->willReturn(true);
768
        $form->handleRequest($request)->willReturn($form);
769
        $form->isValid()->willReturn(true);
770
        $form->getData()->willReturn($newResource);
771
772
        $eventDispatcher->dispatchPreEvent(ResourceActions::CREATE, $configuration, $newResource)->willReturn($event);
773
        $event->isStopped()->willReturn(true);
774
        $event->getMessage()->willReturn('You cannot add a new product right now.');
775
        $event->getErrorCode()->willReturn(500);
776
777
        $repository->add($newResource)->shouldNotBeCalled();
778
        $eventDispatcher->dispatchPostEvent(ResourceActions::CREATE, $configuration, $newResource)->shouldNotBeCalled();
779
        $flashHelper->addSuccessFlash(Argument::any())->shouldNotBeCalled();
0 ignored issues
show
Bug introduced by
The call to addSuccessFlash() misses a required argument $actionName.

This check looks for function calls that miss required arguments.

Loading history...
780
781
        $this
782
            ->shouldThrow(new HttpException(500, 'You cannot add a new product right now.'))
783
            ->during('createAction', [$request])
784
        ;
785
    }
786
787
    function it_throws_a_403_exception_if_user_is_unauthorized_to_edit_a_single_resource(
788
        MetadataInterface $metadata,
789
        RequestConfigurationFactoryInterface $requestConfigurationFactory,
790
        RequestConfiguration $configuration,
791
        Request $request,
792
        AuthorizationCheckerInterface $authorizationChecker
793
    ): void {
794
        $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Bundle\Res...r\RequestConfiguration>.

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...
795
        $configuration->hasPermission()->willReturn(true);
796
        $configuration->getPermission(ResourceActions::UPDATE)->willReturn('sylius.product.update');
797
798
        $authorizationChecker->isGranted($configuration, 'sylius.product.update')->willReturn(false);
799
800
        $this
801
            ->shouldThrow(new AccessDeniedException())
802
            ->during('updateAction', [$request])
803
        ;
804
    }
805
806
    function it_throws_a_404_exception_if_resource_to_update_is_not_found_based_on_configuration(
807
        MetadataInterface $metadata,
808
        RequestConfigurationFactoryInterface $requestConfigurationFactory,
809
        RequestConfiguration $configuration,
810
        Request $request,
811
        AuthorizationCheckerInterface $authorizationChecker,
812
        RepositoryInterface $repository,
813
        SingleResourceProviderInterface $singleResourceProvider
814
    ): void {
815
        $metadata->getHumanizedName()->willReturn('product');
816
        $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Bundle\Res...r\RequestConfiguration>.

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...
817
        $configuration->hasPermission()->willReturn(true);
818
        $configuration->getPermission(ResourceActions::UPDATE)->willReturn('sylius.product.update');
819
820
        $authorizationChecker->isGranted($configuration, 'sylius.product.update')->willReturn(true);
821
        $singleResourceProvider->get($configuration, $repository)->willReturn(null);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...odel\ResourceInterface>.

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...
822
823
        $this
824
            ->shouldThrow(new NotFoundHttpException('The "product" has not been found'))
825
            ->during('updateAction', [$request])
826
        ;
827
    }
828
829
    function it_returns_a_html_response_for_updating_resource_form(
830
        MetadataInterface $metadata,
831
        RequestConfigurationFactoryInterface $requestConfigurationFactory,
832
        RequestConfiguration $configuration,
833
        AuthorizationCheckerInterface $authorizationChecker,
834
        ViewHandlerInterface $viewHandler,
835
        RepositoryInterface $repository,
836
        SingleResourceProviderInterface $singleResourceProvider,
837
        ResourceInterface $resource,
838
        ResourceFormFactoryInterface $resourceFormFactory,
839
        EventDispatcherInterface $eventDispatcher,
840
        ResourceControllerEvent $event,
841
        Form $form,
842
        FormView $formView,
843
        Request $request,
844
        Response $response
845
    ): void {
846
        $metadata->getApplicationName()->willReturn('sylius');
847
        $metadata->getName()->willReturn('product');
848
849
        $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Bundle\Res...r\RequestConfiguration>.

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...
850
        $configuration->hasPermission()->willReturn(true);
851
        $configuration->getPermission(ResourceActions::UPDATE)->willReturn('sylius.product.update');
852
        $configuration->hasStateMachine()->willReturn(false);
853
854
        $authorizationChecker->isGranted($configuration, 'sylius.product.update')->willReturn(true);
855
856
        $configuration->isHtmlRequest()->willReturn(true);
857
        $configuration->getTemplate(ResourceActions::UPDATE . '.html')->willReturn('SyliusShopBundle:Product:update.html.twig');
858
859
        $singleResourceProvider->get($configuration, $repository)->willReturn($resource);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...odel\ResourceInterface>.

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...
860
        $resourceFormFactory->create($configuration, $resource)->willReturn($form);
861
862
        $eventDispatcher->dispatchInitializeEvent(ResourceActions::UPDATE, $configuration, $resource)->willReturn($event);
863
864
        $request->isMethod('PATCH')->willReturn(false);
865
        $request->getMethod()->willReturn('GET');
866
867
        $form->handleRequest($request)->willReturn($form);
868
        $form->createView()->willReturn($formView);
869
870
        $expectedView = View::create()
871
            ->setData([
872
                'configuration' => $configuration,
873
                'metadata' => $metadata,
874
                'resource' => $resource,
875
                'product' => $resource,
876
                'form' => $formView,
877
            ])
878
            ->setTemplate('SyliusShopBundle:Product:update.html.twig')
879
        ;
880
881
        $viewHandler->handle($configuration, Argument::that($this->getViewComparingCallback($expectedView)))->willReturn($response);
882
883
        $this->updateAction($request)->shouldReturn($response);
884
    }
885
886
    function it_returns_a_html_response_for_invalid_form_during_resource_update(
887
        MetadataInterface $metadata,
888
        RequestConfigurationFactoryInterface $requestConfigurationFactory,
889
        RequestConfiguration $configuration,
890
        AuthorizationCheckerInterface $authorizationChecker,
891
        ViewHandlerInterface $viewHandler,
892
        RepositoryInterface $repository,
893
        SingleResourceProviderInterface $singleResourceProvider,
894
        ResourceInterface $resource,
895
        ResourceFormFactoryInterface $resourceFormFactory,
896
        EventDispatcherInterface $eventDispatcher,
897
        ResourceControllerEvent $event,
898
        Form $form,
899
        FormView $formView,
900
        Request $request,
901
        Response $response
902
    ): void {
903
        $metadata->getApplicationName()->willReturn('sylius');
904
        $metadata->getName()->willReturn('product');
905
906
        $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Bundle\Res...r\RequestConfiguration>.

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...
907
        $configuration->hasPermission()->willReturn(true);
908
        $configuration->getPermission(ResourceActions::UPDATE)->willReturn('sylius.product.update');
909
910
        $authorizationChecker->isGranted($configuration, 'sylius.product.update')->willReturn(true);
911
912
        $configuration->isHtmlRequest()->willReturn(true);
913
        $configuration->getTemplate(ResourceActions::UPDATE . '.html')->willReturn('SyliusShopBundle:Product:update.html.twig');
914
915
        $singleResourceProvider->get($configuration, $repository)->willReturn($resource);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...odel\ResourceInterface>.

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...
916
        $resourceFormFactory->create($configuration, $resource)->willReturn($form);
917
918
        $eventDispatcher->dispatchInitializeEvent(ResourceActions::UPDATE, $configuration, $resource)->willReturn($event);
919
920
        $request->isMethod('PATCH')->willReturn(false);
921
        $request->getMethod()->willReturn('PUT');
922
923
        $form->handleRequest($request)->willReturn($form);
924
925
        $form->isValid()->willReturn(false);
926
        $form->createView()->willReturn($formView);
927
928
        $expectedView = View::create()
929
            ->setData([
930
                'configuration' => $configuration,
931
                'metadata' => $metadata,
932
                'resource' => $resource,
933
                'product' => $resource,
934
                'form' => $formView,
935
            ])
936
            ->setTemplate('SyliusShopBundle:Product:update.html.twig')
937
        ;
938
939
        $viewHandler->handle($configuration, Argument::that($this->getViewComparingCallback($expectedView)))->willReturn($response);
940
941
        $this->updateAction($request)->shouldReturn($response);
942
    }
943
944
    function it_returns_a_non_html_response_for_invalid_form_during_resource_update(
945
        MetadataInterface $metadata,
946
        RequestConfigurationFactoryInterface $requestConfigurationFactory,
947
        RequestConfiguration $configuration,
948
        AuthorizationCheckerInterface $authorizationChecker,
949
        ViewHandlerInterface $viewHandler,
950
        RepositoryInterface $repository,
951
        SingleResourceProviderInterface $singleResourceProvider,
952
        ResourceInterface $resource,
953
        ResourceFormFactoryInterface $resourceFormFactory,
954
        Form $form,
955
        Request $request,
956
        Response $response
957
    ): void {
958
        $metadata->getApplicationName()->willReturn('sylius');
959
        $metadata->getName()->willReturn('product');
960
961
        $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Bundle\Res...r\RequestConfiguration>.

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...
962
        $configuration->hasPermission()->willReturn(true);
963
        $configuration->getPermission(ResourceActions::UPDATE)->willReturn('sylius.product.update');
964
        $configuration->isHtmlRequest()->willReturn(false);
965
966
        $authorizationChecker->isGranted($configuration, 'sylius.product.update')->willReturn(true);
967
968
        $singleResourceProvider->get($configuration, $repository)->willReturn($resource);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...odel\ResourceInterface>.

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...
969
        $resourceFormFactory->create($configuration, $resource)->willReturn($form);
970
971
        $request->isMethod('PATCH')->willReturn(true);
972
        $request->getMethod()->willReturn('PATCH');
973
974
        $form->handleRequest($request)->willReturn($form);
975
        $form->isValid()->willReturn(false);
976
977
        $expectedView = View::create($form, 400);
978
        $viewHandler->handle($configuration, Argument::that($this->getViewComparingCallback($expectedView)))->willReturn($response);
979
980
        $this->updateAction($request)->shouldReturn($response);
981
    }
982
983
    function it_does_not_update_the_resource_and_redirects_to_resource_for_html_request_if_stopped_via_event(
984
        MetadataInterface $metadata,
985
        RequestConfigurationFactoryInterface $requestConfigurationFactory,
986
        RequestConfiguration $configuration,
987
        AuthorizationCheckerInterface $authorizationChecker,
988
        ObjectManager $manager,
989
        RepositoryInterface $repository,
990
        SingleResourceProviderInterface $singleResourceProvider,
991
        ResourceInterface $resource,
992
        ResourceFormFactoryInterface $resourceFormFactory,
993
        Form $form,
994
        EventDispatcherInterface $eventDispatcher,
995
        RedirectHandlerInterface $redirectHandler,
996
        FlashHelperInterface $flashHelper,
997
        ResourceControllerEvent $event,
998
        Request $request,
999
        Response $redirectResponse
1000
    ): void {
1001
        $metadata->getApplicationName()->willReturn('sylius');
1002
        $metadata->getName()->willReturn('product');
1003
1004
        $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Bundle\Res...r\RequestConfiguration>.

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...
1005
        $configuration->hasPermission()->willReturn(true);
1006
        $configuration->getPermission(ResourceActions::UPDATE)->willReturn('sylius.product.update');
1007
1008
        $authorizationChecker->isGranted($configuration, 'sylius.product.update')->willReturn(true);
1009
1010
        $configuration->isHtmlRequest()->willReturn(true);
1011
1012
        $singleResourceProvider->get($configuration, $repository)->willReturn($resource);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...odel\ResourceInterface>.

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...
1013
        $resourceFormFactory->create($configuration, $resource)->willReturn($form);
1014
1015
        $request->isMethod('PATCH')->willReturn(false);
1016
        $request->getMethod()->willReturn('PUT');
1017
1018
        $form->handleRequest($request)->willReturn($form);
1019
1020
        $form->isSubmitted()->willReturn(true);
1021
        $form->isValid()->willReturn(true);
1022
        $form->getData()->willReturn($resource);
1023
1024
        $eventDispatcher->dispatchPreEvent(ResourceActions::UPDATE, $configuration, $resource)->willReturn($event);
1025
        $event->isStopped()->willReturn(true);
1026
        $event->hasResponse()->willReturn(false);
1027
        $flashHelper->addFlashFromEvent($configuration, $event)->shouldBeCalled();
1028
1029
        $manager->flush()->shouldNotBeCalled();
1030
        $eventDispatcher->dispatchPostEvent(Argument::any())->shouldNotBeCalled();
0 ignored issues
show
Bug introduced by
The call to dispatchPostEvent() misses some required arguments starting with $requestConfiguration.
Loading history...
1031
        $flashHelper->addSuccessFlash(Argument::any())->shouldNotBeCalled();
0 ignored issues
show
Bug introduced by
The call to addSuccessFlash() misses a required argument $actionName.

This check looks for function calls that miss required arguments.

Loading history...
1032
1033
        $redirectHandler->redirectToResource($configuration, $resource)->willReturn($redirectResponse);
1034
1035
        $this->updateAction($request)->shouldReturn($redirectResponse);
1036
    }
1037
1038
    function it_redirects_to_updated_resource(
1039
        MetadataInterface $metadata,
1040
        RequestConfigurationFactoryInterface $requestConfigurationFactory,
1041
        RepositoryInterface $repository,
1042
        ObjectManager $manager,
1043
        SingleResourceProviderInterface $singleResourceProvider,
1044
        ResourceFormFactoryInterface $resourceFormFactory,
1045
        RedirectHandlerInterface $redirectHandler,
1046
        FlashHelperInterface $flashHelper,
1047
        AuthorizationCheckerInterface $authorizationChecker,
1048
        EventDispatcherInterface $eventDispatcher,
1049
        ResourceUpdateHandlerInterface $resourceUpdateHandler,
1050
        RequestConfiguration $configuration,
1051
        ResourceInterface $resource,
1052
        Form $form,
1053
        ResourceControllerEvent $preEvent,
1054
        ResourceControllerEvent $postEvent,
1055
        Request $request,
1056
        Response $redirectResponse
1057
    ): void {
1058
        $metadata->getApplicationName()->willReturn('sylius');
1059
        $metadata->getName()->willReturn('product');
1060
1061
        $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Bundle\Res...r\RequestConfiguration>.

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...
1062
        $configuration->hasPermission()->willReturn(true);
1063
        $configuration->getPermission(ResourceActions::UPDATE)->willReturn('sylius.product.update');
1064
        $configuration->hasStateMachine()->willReturn(false);
1065
1066
        $authorizationChecker->isGranted($configuration, 'sylius.product.update')->willReturn(true);
1067
1068
        $configuration->isHtmlRequest()->willReturn(true);
1069
        $configuration->getTemplate(ResourceActions::UPDATE . '.html')->willReturn('SyliusShopBundle:Product:update.html.twig');
1070
1071
        $singleResourceProvider->get($configuration, $repository)->willReturn($resource);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...odel\ResourceInterface>.

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...
1072
        $resourceFormFactory->create($configuration, $resource)->willReturn($form);
1073
1074
        $request->isMethod('PATCH')->willReturn(false);
1075
        $request->getMethod()->willReturn('PUT');
1076
1077
        $form->handleRequest($request)->willReturn($form);
1078
1079
        $form->isSubmitted()->willReturn(true);
1080
        $form->isValid()->willReturn(true);
1081
        $form->getData()->willReturn($resource);
1082
1083
        $eventDispatcher->dispatchPreEvent(ResourceActions::UPDATE, $configuration, $resource)->willReturn($preEvent);
1084
        $preEvent->isStopped()->willReturn(false);
1085
1086
        $resourceUpdateHandler->handle($resource, $configuration, $manager)->shouldBeCalled();
1087
        $eventDispatcher->dispatchPostEvent(ResourceActions::UPDATE, $configuration, $resource)->willReturn($postEvent);
1088
1089
        $postEvent->hasResponse()->willReturn(false);
1090
1091
        $flashHelper->addSuccessFlash($configuration, ResourceActions::UPDATE, $resource)->shouldBeCalled();
1092
        $redirectHandler->redirectToResource($configuration, $resource)->willReturn($redirectResponse);
1093
1094
        $this->updateAction($request)->shouldReturn($redirectResponse);
1095
    }
1096
1097
    function it_uses_response_from_post_update_event_if_defined(
1098
        MetadataInterface $metadata,
1099
        RequestConfigurationFactoryInterface $requestConfigurationFactory,
1100
        RepositoryInterface $repository,
1101
        ObjectManager $manager,
1102
        SingleResourceProviderInterface $singleResourceProvider,
1103
        ResourceFormFactoryInterface $resourceFormFactory,
1104
        RedirectHandlerInterface $redirectHandler,
1105
        FlashHelperInterface $flashHelper,
1106
        AuthorizationCheckerInterface $authorizationChecker,
1107
        EventDispatcherInterface $eventDispatcher,
1108
        ResourceUpdateHandlerInterface $resourceUpdateHandler,
1109
        RequestConfiguration $configuration,
1110
        ResourceInterface $resource,
1111
        Form $form,
1112
        ResourceControllerEvent $preEvent,
1113
        ResourceControllerEvent $postEvent,
1114
        Request $request,
1115
        Response $redirectResponse
1116
    ): void {
1117
        $metadata->getApplicationName()->willReturn('sylius');
1118
        $metadata->getName()->willReturn('product');
1119
1120
        $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Bundle\Res...r\RequestConfiguration>.

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...
1121
        $configuration->hasPermission()->willReturn(true);
1122
        $configuration->getPermission(ResourceActions::UPDATE)->willReturn('sylius.product.update');
1123
        $configuration->hasStateMachine()->willReturn(false);
1124
1125
        $authorizationChecker->isGranted($configuration, 'sylius.product.update')->willReturn(true);
1126
1127
        $configuration->isHtmlRequest()->willReturn(true);
1128
        $configuration->getTemplate(ResourceActions::UPDATE . '.html')->willReturn('SyliusShopBundle:Product:update.html.twig');
1129
1130
        $singleResourceProvider->get($configuration, $repository)->willReturn($resource);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...odel\ResourceInterface>.

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...
1131
        $resourceFormFactory->create($configuration, $resource)->willReturn($form);
1132
1133
        $request->isMethod('PATCH')->willReturn(false);
1134
        $request->getMethod()->willReturn('PUT');
1135
1136
        $form->handleRequest($request)->willReturn($form);
1137
1138
        $form->isSubmitted()->willReturn(true);
1139
        $form->isValid()->willReturn(true);
1140
        $form->getData()->willReturn($resource);
1141
1142
        $eventDispatcher->dispatchPreEvent(ResourceActions::UPDATE, $configuration, $resource)->willReturn($preEvent);
1143
        $preEvent->isStopped()->willReturn(false);
1144
1145
        $resourceUpdateHandler->handle($resource, $configuration, $manager)->shouldBeCalled();
1146
        $flashHelper->addSuccessFlash($configuration, ResourceActions::UPDATE, $resource)->shouldBeCalled();
1147
        $eventDispatcher->dispatchPostEvent(ResourceActions::UPDATE, $configuration, $resource)->willReturn($postEvent);
1148
1149
        $postEvent->hasResponse()->willReturn(true);
1150
        $postEvent->getResponse()->willReturn($redirectResponse);
1151
1152
        $redirectHandler->redirectToResource($configuration, $resource)->shouldNotBeCalled();
1153
1154
        $this->updateAction($request)->shouldReturn($redirectResponse);
1155
    }
1156
1157
    function it_returns_a_non_html_response_for_correctly_updated_resource(
1158
        MetadataInterface $metadata,
1159
        ParameterBagInterface $parameterBag,
1160
        RequestConfigurationFactoryInterface $requestConfigurationFactory,
1161
        ViewHandlerInterface $viewHandler,
1162
        RepositoryInterface $repository,
1163
        ObjectManager $manager,
1164
        SingleResourceProviderInterface $singleResourceProvider,
1165
        ResourceFormFactoryInterface $resourceFormFactory,
1166
        AuthorizationCheckerInterface $authorizationChecker,
1167
        EventDispatcherInterface $eventDispatcher,
1168
        ResourceUpdateHandlerInterface $resourceUpdateHandler,
1169
        RequestConfiguration $configuration,
1170
        ResourceInterface $resource,
1171
        ResourceControllerEvent $event,
1172
        Form $form,
1173
        Request $request,
1174
        Response $response
1175
    ): void {
1176
        $metadata->getApplicationName()->willReturn('sylius');
1177
        $metadata->getName()->willReturn('product');
1178
1179
        $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Bundle\Res...r\RequestConfiguration>.

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...
1180
        $configuration->hasPermission()->willReturn(true);
1181
        $configuration->getPermission(ResourceActions::UPDATE)->willReturn('sylius.product.update');
1182
        $configuration->isHtmlRequest()->willReturn(false);
1183
        $configuration->hasStateMachine()->willReturn(false);
1184
1185
        $configuration->getParameters()->willReturn($parameterBag);
1186
        $parameterBag->get('return_content', false)->willReturn(false);
1187
1188
        $authorizationChecker->isGranted($configuration, 'sylius.product.update')->willReturn(true);
1189
1190
        $singleResourceProvider->get($configuration, $repository)->willReturn($resource);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...odel\ResourceInterface>.

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...
1191
        $resourceFormFactory->create($configuration, $resource)->willReturn($form);
1192
1193
        $request->isMethod('PATCH')->willReturn(false);
1194
        $request->getMethod()->willReturn('PUT');
1195
1196
        $form->handleRequest($request)->willReturn($form);
1197
        $form->isValid()->willReturn(true);
1198
        $form->getData()->willReturn($resource);
1199
1200
        $eventDispatcher->dispatchPreEvent(ResourceActions::UPDATE, $configuration, $resource)->willReturn($event);
1201
        $event->isStopped()->willReturn(false);
1202
1203
        $resourceUpdateHandler->handle($resource, $configuration, $manager)->shouldBeCalled();
1204
        $eventDispatcher->dispatchPostEvent(ResourceActions::UPDATE, $configuration, $resource)->shouldBeCalled();
1205
1206
        $expectedView = View::create(null, 204);
1207
        $viewHandler->handle($configuration, Argument::that($this->getViewComparingCallback($expectedView)))->willReturn($response);
1208
1209
        $this->updateAction($request)->shouldReturn($response);
1210
    }
1211
1212
    function it_does_not_update_the_resource_throws_a_http_exception_for_non_html_requests_stopped_via_event(
1213
        MetadataInterface $metadata,
1214
        RequestConfigurationFactoryInterface $requestConfigurationFactory,
1215
        RequestConfiguration $configuration,
1216
        AuthorizationCheckerInterface $authorizationChecker,
1217
        ObjectManager $manager,
1218
        RepositoryInterface $repository,
1219
        SingleResourceProviderInterface $singleResourceProvider,
1220
        ResourceInterface $resource,
1221
        ResourceFormFactoryInterface $resourceFormFactory,
1222
        EventDispatcherInterface $eventDispatcher,
1223
        ResourceControllerEvent $event,
1224
        Form $form,
1225
        Request $request
1226
    ): void {
1227
        $metadata->getApplicationName()->willReturn('sylius');
1228
        $metadata->getName()->willReturn('product');
1229
1230
        $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Bundle\Res...r\RequestConfiguration>.

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...
1231
        $configuration->hasPermission()->willReturn(true);
1232
        $configuration->getPermission(ResourceActions::UPDATE)->willReturn('sylius.product.update');
1233
        $configuration->isHtmlRequest()->willReturn(false);
1234
1235
        $authorizationChecker->isGranted($configuration, 'sylius.product.update')->willReturn(true);
1236
1237
        $singleResourceProvider->get($configuration, $repository)->willReturn($resource);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...odel\ResourceInterface>.

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...
1238
        $resourceFormFactory->create($configuration, $resource)->willReturn($form);
1239
1240
        $request->isMethod('PATCH')->willReturn(false);
1241
        $request->getMethod()->willReturn('PUT');
1242
1243
        $form->handleRequest($request)->willReturn($form);
1244
        $form->isValid()->willReturn(true);
1245
        $form->getData()->willReturn($resource);
1246
1247
        $eventDispatcher->dispatchPreEvent(ResourceActions::UPDATE, $configuration, $resource)->willReturn($event);
1248
        $event->isStopped()->willReturn(true);
1249
        $event->getMessage()->willReturn('Cannot update this channel.');
1250
        $event->getErrorCode()->willReturn(500);
1251
1252
        $manager->flush()->shouldNotBeCalled();
1253
        $eventDispatcher->dispatchPostEvent(Argument::any())->shouldNotBeCalled();
0 ignored issues
show
Bug introduced by
The call to dispatchPostEvent() misses some required arguments starting with $requestConfiguration.
Loading history...
1254
1255
        $this
1256
            ->shouldThrow(new HttpException(500, 'Cannot update this channel.'))
1257
            ->during('updateAction', [$request])
1258
        ;
1259
    }
1260
1261
    function it_applies_state_machine_transition_to_updated_resource_if_configured(
1262
        MetadataInterface $metadata,
1263
        RequestConfigurationFactoryInterface $requestConfigurationFactory,
1264
        RepositoryInterface $repository,
1265
        ObjectManager $manager,
1266
        SingleResourceProviderInterface $singleResourceProvider,
1267
        ResourceFormFactoryInterface $resourceFormFactory,
1268
        RedirectHandlerInterface $redirectHandler,
1269
        FlashHelperInterface $flashHelper,
1270
        AuthorizationCheckerInterface $authorizationChecker,
1271
        EventDispatcherInterface $eventDispatcher,
1272
        ResourceUpdateHandlerInterface $resourceUpdateHandler,
1273
        RequestConfiguration $configuration,
1274
        ResourceInterface $resource,
1275
        Form $form,
1276
        ResourceControllerEvent $preEvent,
1277
        ResourceControllerEvent $postEvent,
1278
        Request $request,
1279
        Response $redirectResponse
1280
    ): void {
1281
        $metadata->getApplicationName()->willReturn('sylius');
1282
        $metadata->getName()->willReturn('product');
1283
1284
        $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Bundle\Res...r\RequestConfiguration>.

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...
1285
        $configuration->hasPermission()->willReturn(true);
1286
        $configuration->getPermission(ResourceActions::UPDATE)->willReturn('sylius.product.update');
1287
        $configuration->hasStateMachine()->willReturn(true);
1288
1289
        $authorizationChecker->isGranted($configuration, 'sylius.product.update')->willReturn(true);
1290
1291
        $configuration->isHtmlRequest()->willReturn(true);
1292
        $configuration->getTemplate(ResourceActions::UPDATE)->willReturn('SyliusShopBundle:Product:update.html.twig');
1293
1294
        $singleResourceProvider->get($configuration, $repository)->willReturn($resource);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...odel\ResourceInterface>.

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...
1295
        $resourceFormFactory->create($configuration, $resource)->willReturn($form);
1296
1297
        $request->isMethod('PATCH')->willReturn(false);
1298
        $request->getMethod()->willReturn('PUT');
1299
1300
        $form->handleRequest($request)->willReturn($form);
1301
1302
        $form->isSubmitted()->willReturn(true);
1303
        $form->isValid()->willReturn(true);
1304
        $form->getData()->willReturn($resource);
1305
1306
        $eventDispatcher->dispatchPreEvent(ResourceActions::UPDATE, $configuration, $resource)->willReturn($preEvent);
1307
        $preEvent->isStopped()->willReturn(false);
1308
1309
        $resourceUpdateHandler->handle($resource, $configuration, $manager)->shouldBeCalled();
1310
        $eventDispatcher->dispatchPostEvent(ResourceActions::UPDATE, $configuration, $resource)->willReturn($postEvent);
1311
1312
        $postEvent->hasResponse()->willReturn(false);
1313
1314
        $flashHelper->addSuccessFlash($configuration, ResourceActions::UPDATE, $resource)->shouldBeCalled();
1315
        $redirectHandler->redirectToResource($configuration, $resource)->willReturn($redirectResponse);
1316
1317
        $this->updateAction($request)->shouldReturn($redirectResponse);
1318
    }
1319
1320
    function it_throws_a_403_exception_if_user_is_unauthorized_to_delete_multiple_resources(
1321
        MetadataInterface $metadata,
1322
        RequestConfigurationFactoryInterface $requestConfigurationFactory,
1323
        RequestConfiguration $configuration,
1324
        Request $request,
1325
        AuthorizationCheckerInterface $authorizationChecker
1326
    ): void {
1327
        $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Bundle\Res...r\RequestConfiguration>.

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...
1328
        $configuration->hasPermission()->willReturn(true);
1329
        $configuration->getPermission(ResourceActions::BULK_DELETE)->willReturn('sylius.product.bulk_delete');
1330
1331
        $authorizationChecker->isGranted($configuration, 'sylius.product.bulk_delete')->willReturn(false);
1332
1333
        $this
1334
            ->shouldThrow(new AccessDeniedException())
1335
            ->during('bulkDeleteAction', [$request])
1336
        ;
1337
    }
1338
1339
    function it_deletes_multiple_resources_and_redirects_to_index_for_html_request(
1340
        MetadataInterface $metadata,
1341
        RequestConfigurationFactoryInterface $requestConfigurationFactory,
1342
        RequestConfiguration $configuration,
1343
        AuthorizationCheckerInterface $authorizationChecker,
1344
        RepositoryInterface $repository,
1345
        ResourcesCollectionProviderInterface $resourcesCollectionProvider,
1346
        ResourceInterface $firstResource,
1347
        ResourceInterface $secondResource,
1348
        RedirectHandlerInterface $redirectHandler,
1349
        FlashHelperInterface $flashHelper,
1350
        EventDispatcherInterface $eventDispatcher,
1351
        CsrfTokenManagerInterface $csrfTokenManager,
1352
        ContainerInterface $container,
1353
        ResourceControllerEvent $firstPreEvent,
1354
        ResourceControllerEvent $secondPreEvent,
1355
        ResourceControllerEvent $firstPostEvent,
1356
        ResourceControllerEvent $secondPostEvent,
1357
        ResourceDeleteHandlerInterface $resourceDeleteHandler,
1358
        Request $request,
1359
        Response $redirectResponse
1360
    ): void {
1361
        $metadata->getApplicationName()->willReturn('sylius');
1362
        $metadata->getName()->willReturn('product');
1363
1364
        $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Bundle\Res...r\RequestConfiguration>.

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...
1365
        $configuration->hasPermission()->willReturn(true);
1366
        $configuration->getPermission(ResourceActions::BULK_DELETE)->willReturn('sylius.product.bulk_delete');
1367
        $request->request = new ParameterBag(['_csrf_token' => 'xyz']);
1368
1369
        $container->has('security.csrf.token_manager')->willReturn(true);
1370
        $container->get('security.csrf.token_manager')->willReturn($csrfTokenManager);
1371
        $csrfTokenManager->isTokenValid(new CsrfToken('bulk_delete', 'xyz'))->willReturn(true);
1372
1373
        $eventDispatcher
1374
            ->dispatchMultiple(ResourceActions::BULK_DELETE, $configuration, [$firstResource, $secondResource])
1375
            ->shouldBeCalled()
1376
        ;
1377
1378
        $authorizationChecker->isGranted($configuration, 'sylius.product.bulk_delete')->willReturn(true);
1379
        $resourcesCollectionProvider->get($configuration, $repository)->willReturn([$firstResource, $secondResource]);
1380
1381
        $configuration->isHtmlRequest()->willReturn(true);
1382
        $configuration->isCsrfProtectionEnabled()->willReturn(true);
1383
1384
        $eventDispatcher
1385
            ->dispatchPreEvent(ResourceActions::DELETE, $configuration, $firstResource)
1386
            ->willReturn($firstPreEvent)
1387
        ;
1388
        $firstPreEvent->isStopped()->willReturn(false);
1389
1390
        $resourceDeleteHandler->handle($firstResource, $repository)->shouldBeCalled();
1391
1392
        $eventDispatcher
1393
            ->dispatchPostEvent(ResourceActions::DELETE, $configuration, $firstResource)
1394
            ->willReturn($firstPostEvent)
1395
        ;
1396
        $firstPostEvent->hasResponse()->willReturn(false);
1397
1398
        $eventDispatcher
1399
            ->dispatchPreEvent(ResourceActions::DELETE, $configuration, $secondResource)
1400
            ->willReturn($secondPreEvent)
1401
        ;
1402
        $secondPreEvent->isStopped()->willReturn(false);
1403
1404
        $resourceDeleteHandler->handle($secondResource, $repository)->shouldBeCalled();
1405
1406
        $eventDispatcher
1407
            ->dispatchPostEvent(ResourceActions::DELETE, $configuration, $secondResource)
1408
            ->willReturn($secondPostEvent)
1409
        ;
1410
        $secondPostEvent->hasResponse()->willReturn(false);
1411
1412
        $flashHelper->addSuccessFlash($configuration, ResourceActions::BULK_DELETE)->shouldBeCalled();
1413
1414
        $redirectHandler->redirectToIndex($configuration)->willReturn($redirectResponse);
1415
1416
        $this->bulkDeleteAction($request)->shouldReturn($redirectResponse);
1417
    }
1418
1419
    function it_throws_a_403_exception_if_user_is_unauthorized_to_delete_a_single_resource(
1420
        MetadataInterface $metadata,
1421
        RequestConfigurationFactoryInterface $requestConfigurationFactory,
1422
        RequestConfiguration $configuration,
1423
        Request $request,
1424
        AuthorizationCheckerInterface $authorizationChecker
1425
    ): void {
1426
        $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Bundle\Res...r\RequestConfiguration>.

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...
1427
        $configuration->hasPermission()->willReturn(true);
1428
        $configuration->getPermission(ResourceActions::DELETE)->willReturn('sylius.product.delete');
1429
1430
        $authorizationChecker->isGranted($configuration, 'sylius.product.delete')->willReturn(false);
1431
1432
        $this
1433
            ->shouldThrow(new AccessDeniedException())
1434
            ->during('deleteAction', [$request])
1435
        ;
1436
    }
1437
1438
    function it_throws_a_404_exception_if_resource_for_deletion_is_not_found_based_on_configuration(
1439
        MetadataInterface $metadata,
1440
        RequestConfigurationFactoryInterface $requestConfigurationFactory,
1441
        RequestConfiguration $configuration,
1442
        Request $request,
1443
        AuthorizationCheckerInterface $authorizationChecker,
1444
        RepositoryInterface $repository,
1445
        SingleResourceProviderInterface $singleResourceProvider
1446
    ): void {
1447
        $metadata->getHumanizedName()->willReturn('product');
1448
        $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Bundle\Res...r\RequestConfiguration>.

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...
1449
        $configuration->hasPermission()->willReturn(true);
1450
        $configuration->getPermission(ResourceActions::DELETE)->willReturn('sylius.product.delete');
1451
1452
        $authorizationChecker->isGranted($configuration, 'sylius.product.delete')->willReturn(true);
1453
        $singleResourceProvider->get($configuration, $repository)->willReturn(null);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...odel\ResourceInterface>.

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...
1454
1455
        $this
1456
            ->shouldThrow(new NotFoundHttpException('The "product" has not been found'))
1457
            ->during('deleteAction', [$request])
1458
        ;
1459
    }
1460
1461
    function it_deletes_a_resource_and_redirects_to_index_by_for_html_request(
1462
        MetadataInterface $metadata,
1463
        RequestConfigurationFactoryInterface $requestConfigurationFactory,
1464
        RequestConfiguration $configuration,
1465
        AuthorizationCheckerInterface $authorizationChecker,
1466
        RepositoryInterface $repository,
1467
        SingleResourceProviderInterface $singleResourceProvider,
1468
        ResourceInterface $resource,
1469
        RedirectHandlerInterface $redirectHandler,
1470
        FlashHelperInterface $flashHelper,
1471
        EventDispatcherInterface $eventDispatcher,
1472
        CsrfTokenManagerInterface $csrfTokenManager,
1473
        ContainerInterface $container,
1474
        ResourceControllerEvent $event,
1475
        ResourceControllerEvent $postEvent,
1476
        ResourceDeleteHandlerInterface $resourceDeleteHandler,
1477
        Request $request,
1478
        Response $redirectResponse
1479
    ): void {
1480
        $metadata->getApplicationName()->willReturn('sylius');
1481
        $metadata->getName()->willReturn('product');
1482
1483
        $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Bundle\Res...r\RequestConfiguration>.

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...
1484
        $configuration->hasPermission()->willReturn(true);
1485
        $configuration->getPermission(ResourceActions::DELETE)->willReturn('sylius.product.delete');
1486
        $request->request = new ParameterBag(['_csrf_token' => 'xyz']);
1487
1488
        $container->has('security.csrf.token_manager')->willReturn(true);
1489
        $container->get('security.csrf.token_manager')->willReturn($csrfTokenManager);
1490
        $csrfTokenManager->isTokenValid(new CsrfToken(1, 'xyz'))->willReturn(true);
1491
1492
        $authorizationChecker->isGranted($configuration, 'sylius.product.delete')->willReturn(true);
1493
        $singleResourceProvider->get($configuration, $repository)->willReturn($resource);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...odel\ResourceInterface>.

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...
1494
        $resource->getId()->willReturn(1);
1495
1496
        $configuration->isHtmlRequest()->willReturn(true);
1497
        $configuration->isCsrfProtectionEnabled()->willReturn(true);
1498
1499
        $eventDispatcher->dispatchPreEvent(ResourceActions::DELETE, $configuration, $resource)->willReturn($event);
1500
        $event->isStopped()->willReturn(false);
1501
1502
        $resourceDeleteHandler->handle($resource, $repository)->shouldBeCalled();
1503
        $eventDispatcher->dispatchPostEvent(ResourceActions::DELETE, $configuration, $resource)->willReturn($postEvent);
1504
1505
        $postEvent->hasResponse()->willReturn(false);
1506
1507
        $flashHelper->addSuccessFlash($configuration, ResourceActions::DELETE, $resource)->shouldBeCalled();
1508
        $redirectHandler->redirectToIndex($configuration, $resource)->willReturn($redirectResponse);
1509
1510
        $this->deleteAction($request)->shouldReturn($redirectResponse);
1511
    }
1512
1513
    function it_uses_response_from_post_delete_event_if_defined(
1514
        MetadataInterface $metadata,
1515
        RequestConfigurationFactoryInterface $requestConfigurationFactory,
1516
        RequestConfiguration $configuration,
1517
        AuthorizationCheckerInterface $authorizationChecker,
1518
        RepositoryInterface $repository,
1519
        SingleResourceProviderInterface $singleResourceProvider,
1520
        ResourceInterface $resource,
1521
        FlashHelperInterface $flashHelper,
1522
        EventDispatcherInterface $eventDispatcher,
1523
        CsrfTokenManagerInterface $csrfTokenManager,
1524
        ContainerInterface $container,
1525
        ResourceControllerEvent $event,
1526
        ResourceControllerEvent $postEvent,
1527
        ResourceDeleteHandlerInterface $resourceDeleteHandler,
1528
        Request $request,
1529
        Response $redirectResponse
1530
    ): void {
1531
        $metadata->getApplicationName()->willReturn('sylius');
1532
        $metadata->getName()->willReturn('product');
1533
1534
        $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Bundle\Res...r\RequestConfiguration>.

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...
1535
        $configuration->hasPermission()->willReturn(true);
1536
        $configuration->getPermission(ResourceActions::DELETE)->willReturn('sylius.product.delete');
1537
        $request->request = new ParameterBag(['_csrf_token' => 'xyz']);
1538
1539
        $container->has('security.csrf.token_manager')->willReturn(true);
1540
        $container->get('security.csrf.token_manager')->willReturn($csrfTokenManager);
1541
        $csrfTokenManager->isTokenValid(new CsrfToken(1, 'xyz'))->willReturn(true);
1542
1543
        $authorizationChecker->isGranted($configuration, 'sylius.product.delete')->willReturn(true);
1544
        $singleResourceProvider->get($configuration, $repository)->willReturn($resource);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...odel\ResourceInterface>.

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...
1545
        $resource->getId()->willReturn(1);
1546
1547
        $configuration->isHtmlRequest()->willReturn(true);
1548
        $configuration->isCsrfProtectionEnabled()->willReturn(true);
1549
1550
        $eventDispatcher->dispatchPreEvent(ResourceActions::DELETE, $configuration, $resource)->willReturn($event);
1551
        $event->isStopped()->willReturn(false);
1552
1553
        $resourceDeleteHandler->handle($resource, $repository)->shouldBeCalled();
1554
        $eventDispatcher->dispatchPostEvent(ResourceActions::DELETE, $configuration, $resource)->willReturn($postEvent);
1555
1556
        $flashHelper->addSuccessFlash($configuration, ResourceActions::DELETE, $resource)->shouldBeCalled();
1557
1558
        $postEvent->hasResponse()->willReturn(true);
1559
        $postEvent->getResponse()->willReturn($redirectResponse);
1560
1561
        $this->deleteAction($request)->shouldReturn($redirectResponse);
1562
    }
1563
1564
    function it_does_not_delete_a_resource_and_redirects_to_index_for_html_requests_stopped_via_event(
1565
        MetadataInterface $metadata,
1566
        RequestConfigurationFactoryInterface $requestConfigurationFactory,
1567
        RequestConfiguration $configuration,
1568
        AuthorizationCheckerInterface $authorizationChecker,
1569
        RepositoryInterface $repository,
1570
        SingleResourceProviderInterface $singleResourceProvider,
1571
        ResourceInterface $resource,
1572
        RedirectHandlerInterface $redirectHandler,
1573
        FlashHelperInterface $flashHelper,
1574
        EventDispatcherInterface $eventDispatcher,
1575
        CsrfTokenManagerInterface $csrfTokenManager,
1576
        ContainerInterface $container,
1577
        ResourceControllerEvent $event,
1578
        ResourceDeleteHandlerInterface $resourceDeleteHandler,
1579
        Request $request,
1580
        Response $redirectResponse
1581
    ): void {
1582
        $metadata->getApplicationName()->willReturn('sylius');
1583
        $metadata->getName()->willReturn('product');
1584
1585
        $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Bundle\Res...r\RequestConfiguration>.

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...
1586
        $configuration->hasPermission()->willReturn(true);
1587
        $configuration->getPermission(ResourceActions::DELETE)->willReturn('sylius.product.delete');
1588
        $request->request = new ParameterBag(['_csrf_token' => 'xyz']);
1589
1590
        $container->has('security.csrf.token_manager')->willReturn(true);
1591
        $container->get('security.csrf.token_manager')->willReturn($csrfTokenManager);
1592
        $csrfTokenManager->isTokenValid(new CsrfToken(1, 'xyz'))->willReturn(true);
1593
1594
        $authorizationChecker->isGranted($configuration, 'sylius.product.delete')->willReturn(true);
1595
        $singleResourceProvider->get($configuration, $repository)->willReturn($resource);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...odel\ResourceInterface>.

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...
1596
        $resource->getId()->willReturn(1);
1597
1598
        $configuration->isHtmlRequest()->willReturn(true);
1599
        $configuration->isCsrfProtectionEnabled()->willReturn(true);
1600
1601
        $eventDispatcher->dispatchPreEvent(ResourceActions::DELETE, $configuration, $resource)->willReturn($event);
1602
        $event->isStopped()->willReturn(true);
1603
        $event->hasResponse()->willReturn(false);
1604
1605
        $resourceDeleteHandler->handle($resource, $repository)->shouldNotBeCalled();
1606
        $eventDispatcher->dispatchPostEvent(ResourceActions::DELETE, $configuration, $resource)->shouldNotBeCalled();
1607
        $flashHelper->addSuccessFlash($configuration, ResourceActions::DELETE, $resource)->shouldNotBeCalled();
1608
1609
        $flashHelper->addFlashFromEvent($configuration, $event)->shouldBeCalled();
1610
        $redirectHandler->redirectToIndex($configuration, $resource)->willReturn($redirectResponse);
1611
1612
        $this->deleteAction($request)->shouldReturn($redirectResponse);
1613
    }
1614
1615
    function it_does_not_delete_a_resource_and_uses_response_from_event_if_defined(
1616
        MetadataInterface $metadata,
1617
        RequestConfigurationFactoryInterface $requestConfigurationFactory,
1618
        RequestConfiguration $configuration,
1619
        AuthorizationCheckerInterface $authorizationChecker,
1620
        RepositoryInterface $repository,
1621
        SingleResourceProviderInterface $singleResourceProvider,
1622
        ResourceInterface $resource,
1623
        RedirectHandlerInterface $redirectHandler,
1624
        FlashHelperInterface $flashHelper,
1625
        EventDispatcherInterface $eventDispatcher,
1626
        CsrfTokenManagerInterface $csrfTokenManager,
1627
        ContainerInterface $container,
1628
        ResourceControllerEvent $event,
1629
        ResourceDeleteHandlerInterface $resourceDeleteHandler,
1630
        Request $request,
1631
        Response $redirectResponse
1632
    ): void {
1633
        $metadata->getApplicationName()->willReturn('sylius');
1634
        $metadata->getName()->willReturn('product');
1635
1636
        $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Bundle\Res...r\RequestConfiguration>.

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...
1637
        $configuration->hasPermission()->willReturn(true);
1638
        $configuration->getPermission(ResourceActions::DELETE)->willReturn('sylius.product.delete');
1639
        $request->request = new ParameterBag(['_csrf_token' => 'xyz']);
1640
1641
        $container->has('security.csrf.token_manager')->willReturn(true);
1642
        $container->get('security.csrf.token_manager')->willReturn($csrfTokenManager);
1643
        $csrfTokenManager->isTokenValid(new CsrfToken(1, 'xyz'))->willReturn(true);
1644
1645
        $authorizationChecker->isGranted($configuration, 'sylius.product.delete')->willReturn(true);
1646
        $singleResourceProvider->get($configuration, $repository)->willReturn($resource);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...odel\ResourceInterface>.

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...
1647
        $resource->getId()->willReturn(1);
1648
1649
        $configuration->isHtmlRequest()->willReturn(true);
1650
        $configuration->isCsrfProtectionEnabled()->willReturn(true);
1651
1652
        $eventDispatcher->dispatchPreEvent(ResourceActions::DELETE, $configuration, $resource)->willReturn($event);
1653
        $event->isStopped()->willReturn(true);
1654
1655
        $flashHelper->addFlashFromEvent($configuration, $event)->shouldBeCalled();
1656
1657
        $event->hasResponse()->willReturn(true);
1658
        $event->getResponse()->willReturn($redirectResponse);
1659
1660
        $resourceDeleteHandler->handle($resource, $repository)->shouldNotBeCalled();
1661
        $eventDispatcher->dispatchPostEvent(ResourceActions::DELETE, $configuration, $resource)->shouldNotBeCalled();
1662
        $flashHelper->addSuccessFlash($configuration, ResourceActions::DELETE, $resource)->shouldNotBeCalled();
1663
1664
        $redirectHandler->redirectToIndex($configuration, $resource)->shouldNotBeCalled();
1665
1666
        $this->deleteAction($request)->shouldReturn($redirectResponse);
1667
    }
1668
1669
    function it_does_not_correctly_delete_a_resource_and_returns_500_for_not_html_response(
1670
        MetadataInterface $metadata,
1671
        RequestConfigurationFactoryInterface $requestConfigurationFactory,
1672
        RequestConfiguration $configuration,
1673
        AuthorizationCheckerInterface $authorizationChecker,
1674
        ViewHandlerInterface $viewHandler,
1675
        RepositoryInterface $repository,
1676
        SingleResourceProviderInterface $singleResourceProvider,
1677
        ResourceInterface $resource,
1678
        EventDispatcherInterface $eventDispatcher,
1679
        CsrfTokenManagerInterface $csrfTokenManager,
1680
        ContainerInterface $container,
1681
        ResourceControllerEvent $event,
1682
        ResourceDeleteHandlerInterface $resourceDeleteHandler,
1683
        Request $request,
1684
        Response $response
1685
    ): void {
1686
        $metadata->getApplicationName()->willReturn('sylius');
1687
        $metadata->getName()->willReturn('product');
1688
1689
        $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Bundle\Res...r\RequestConfiguration>.

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...
1690
        $configuration->hasPermission()->willReturn(true);
1691
        $configuration->getPermission(ResourceActions::DELETE)->willReturn('sylius.product.delete');
1692
        $request->request = new ParameterBag(['_csrf_token' => 'xyz']);
1693
1694
        $container->has('security.csrf.token_manager')->willReturn(true);
1695
        $container->get('security.csrf.token_manager')->willReturn($csrfTokenManager);
1696
        $csrfTokenManager->isTokenValid(new CsrfToken(1, 'xyz'))->willReturn(true);
1697
1698
        $authorizationChecker->isGranted($configuration, 'sylius.product.delete')->willReturn(true);
1699
        $singleResourceProvider->get($configuration, $repository)->willReturn($resource);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...odel\ResourceInterface>.

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...
1700
        $resource->getId()->willReturn(1);
1701
1702
        $configuration->isHtmlRequest()->willReturn(false);
1703
        $configuration->isCsrfProtectionEnabled()->willReturn(true);
1704
1705
        $eventDispatcher->dispatchPreEvent(ResourceActions::DELETE, $configuration, $resource)->willReturn($event);
1706
        $event->isStopped()->willReturn(false);
1707
1708
        $resourceDeleteHandler->handle($resource, $repository)->willThrow(new DeleteHandlingException());
1709
1710
        $eventDispatcher->dispatchPostEvent(ResourceActions::DELETE, $configuration, $resource)->shouldNotBeCalled();
1711
1712
        $expectedView = View::create(null, 500);
1713
1714
        $viewHandler->handle($configuration, Argument::that($this->getViewComparingCallback($expectedView)))->willReturn($response);
1715
1716
        $this->deleteAction($request)->shouldReturn($response);
1717
    }
1718
1719
    function it_deletes_a_resource_and_returns_204_for_non_html_requests(
1720
        MetadataInterface $metadata,
1721
        RequestConfigurationFactoryInterface $requestConfigurationFactory,
1722
        RequestConfiguration $configuration,
1723
        AuthorizationCheckerInterface $authorizationChecker,
1724
        ViewHandlerInterface $viewHandler,
1725
        RepositoryInterface $repository,
1726
        SingleResourceProviderInterface $singleResourceProvider,
1727
        ResourceInterface $resource,
1728
        EventDispatcherInterface $eventDispatcher,
1729
        CsrfTokenManagerInterface $csrfTokenManager,
1730
        ContainerInterface $container,
1731
        ResourceControllerEvent $event,
1732
        ResourceDeleteHandlerInterface $resourceDeleteHandler,
1733
        Request $request,
1734
        Response $response
1735
    ): void {
1736
        $metadata->getApplicationName()->willReturn('sylius');
1737
        $metadata->getName()->willReturn('product');
1738
1739
        $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Bundle\Res...r\RequestConfiguration>.

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...
1740
        $configuration->hasPermission()->willReturn(true);
1741
        $configuration->getPermission(ResourceActions::DELETE)->willReturn('sylius.product.delete');
1742
        $request->request = new ParameterBag(['_csrf_token' => 'xyz']);
1743
1744
        $container->has('security.csrf.token_manager')->willReturn(true);
1745
        $container->get('security.csrf.token_manager')->willReturn($csrfTokenManager);
1746
        $csrfTokenManager->isTokenValid(new CsrfToken(1, 'xyz'))->willReturn(true);
1747
1748
        $authorizationChecker->isGranted($configuration, 'sylius.product.delete')->willReturn(true);
1749
        $singleResourceProvider->get($configuration, $repository)->willReturn($resource);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...odel\ResourceInterface>.

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...
1750
        $resource->getId()->willReturn(1);
1751
1752
        $configuration->isHtmlRequest()->willReturn(false);
1753
        $configuration->isCsrfProtectionEnabled()->willReturn(true);
1754
1755
        $eventDispatcher->dispatchPreEvent(ResourceActions::DELETE, $configuration, $resource)->willReturn($event);
1756
        $event->isStopped()->willReturn(false);
1757
1758
        $resourceDeleteHandler->handle($resource, $repository)->shouldBeCalled();
1759
        $eventDispatcher->dispatchPostEvent(ResourceActions::DELETE, $configuration, $resource)->shouldBeCalled();
1760
1761
        $expectedView = View::create(null, 204);
1762
1763
        $viewHandler->handle($configuration, Argument::that($this->getViewComparingCallback($expectedView)))->willReturn($response);
1764
1765
        $this->deleteAction($request)->shouldReturn($response);
1766
    }
1767
1768
    function it_does_not_delete_a_resource_and_throws_http_exception_for_non_html_requests_stopped_via_event(
1769
        MetadataInterface $metadata,
1770
        RequestConfigurationFactoryInterface $requestConfigurationFactory,
1771
        RequestConfiguration $configuration,
1772
        AuthorizationCheckerInterface $authorizationChecker,
1773
        RepositoryInterface $repository,
1774
        SingleResourceProviderInterface $singleResourceProvider,
1775
        ResourceInterface $resource,
1776
        FlashHelperInterface $flashHelper,
1777
        EventDispatcherInterface $eventDispatcher,
1778
        CsrfTokenManagerInterface $csrfTokenManager,
1779
        ContainerInterface $container,
1780
        ResourceControllerEvent $event,
1781
        ResourceDeleteHandlerInterface $resourceDeleteHandler,
1782
        Request $request
1783
    ): void {
1784
        $metadata->getApplicationName()->willReturn('sylius');
1785
        $metadata->getName()->willReturn('product');
1786
1787
        $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Bundle\Res...r\RequestConfiguration>.

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...
1788
        $configuration->hasPermission()->willReturn(true);
1789
        $configuration->getPermission(ResourceActions::DELETE)->willReturn('sylius.product.delete');
1790
        $request->request = new ParameterBag(['_csrf_token' => 'xyz']);
1791
1792
        $container->has('security.csrf.token_manager')->willReturn(true);
1793
        $container->get('security.csrf.token_manager')->willReturn($csrfTokenManager);
1794
        $csrfTokenManager->isTokenValid(new CsrfToken(1, 'xyz'))->willReturn(true);
1795
1796
        $authorizationChecker->isGranted($configuration, 'sylius.product.delete')->willReturn(true);
1797
        $singleResourceProvider->get($configuration, $repository)->willReturn($resource);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...odel\ResourceInterface>.

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...
1798
        $resource->getId()->willReturn(1);
1799
1800
        $configuration->isHtmlRequest()->willReturn(false);
1801
        $configuration->isCsrfProtectionEnabled()->willReturn(true);
1802
1803
        $eventDispatcher->dispatchPreEvent(ResourceActions::DELETE, $configuration, $resource)->willReturn($event);
1804
        $event->isStopped()->willReturn(true);
1805
        $event->getMessage()->willReturn('Cannot delete this product.');
1806
        $event->getErrorCode()->willReturn(500);
1807
1808
        $resourceDeleteHandler->handle($resource, $repository)->shouldNotBeCalled();
1809
1810
        $eventDispatcher->dispatchPostEvent(Argument::any())->shouldNotBeCalled();
0 ignored issues
show
Bug introduced by
The call to dispatchPostEvent() misses some required arguments starting with $requestConfiguration.
Loading history...
1811
        $flashHelper->addSuccessFlash(Argument::any())->shouldNotBeCalled();
0 ignored issues
show
Bug introduced by
The call to addSuccessFlash() misses a required argument $actionName.

This check looks for function calls that miss required arguments.

Loading history...
1812
        $flashHelper->addFlashFromEvent(Argument::any())->shouldNotBeCalled();
0 ignored issues
show
Bug introduced by
The call to addFlashFromEvent() misses a required argument $event.

This check looks for function calls that miss required arguments.

Loading history...
1813
1814
        $this
1815
            ->shouldThrow(new HttpException(500, 'Cannot delete this product.'))
1816
            ->during('deleteAction', [$request])
1817
        ;
1818
    }
1819
1820
    function it_throws_a_403_exception_if_csrf_token_is_invalid_during_delete_action(
1821
        MetadataInterface $metadata,
1822
        RequestConfigurationFactoryInterface $requestConfigurationFactory,
1823
        RequestConfiguration $configuration,
1824
        AuthorizationCheckerInterface $authorizationChecker,
1825
        RepositoryInterface $repository,
1826
        SingleResourceProviderInterface $singleResourceProvider,
1827
        ResourceInterface $resource,
1828
        FlashHelperInterface $flashHelper,
1829
        EventDispatcherInterface $eventDispatcher,
1830
        CsrfTokenManagerInterface $csrfTokenManager,
1831
        ContainerInterface $container,
1832
        ResourceControllerEvent $event,
1833
        ResourceDeleteHandlerInterface $resourceDeleteHandler,
1834
        Request $request
1835
    ): void {
1836
        $metadata->getApplicationName()->willReturn('sylius');
1837
        $metadata->getName()->willReturn('product');
1838
1839
        $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Bundle\Res...r\RequestConfiguration>.

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...
1840
        $configuration->hasPermission()->willReturn(true);
1841
        $configuration->getPermission(ResourceActions::DELETE)->willReturn('sylius.product.delete');
1842
        $request->request = new ParameterBag(['_csrf_token' => 'xyz']);
1843
1844
        $container->has('security.csrf.token_manager')->willReturn(true);
1845
        $container->get('security.csrf.token_manager')->willReturn($csrfTokenManager);
1846
        $csrfTokenManager->isTokenValid(new CsrfToken(1, 'xyz'))->willReturn(false);
1847
1848
        $authorizationChecker->isGranted($configuration, 'sylius.product.delete')->willReturn(true);
1849
        $singleResourceProvider->get($configuration, $repository)->willReturn($resource);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...odel\ResourceInterface>.

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...
1850
        $resource->getId()->willReturn(1);
1851
1852
        $configuration->isHtmlRequest()->willReturn(true);
1853
        $configuration->isCsrfProtectionEnabled()->willReturn(true);
1854
1855
        $eventDispatcher->dispatchPreEvent(ResourceActions::DELETE, $configuration, $resource)->willReturn($event);
1856
        $event->isStopped()->shouldNotBeCalled();
1857
1858
        $resourceDeleteHandler->handle($resource, $repository)->shouldNotBeCalled();
1859
1860
        $eventDispatcher->dispatchPostEvent(Argument::any())->shouldNotBeCalled();
0 ignored issues
show
Bug introduced by
The call to dispatchPostEvent() misses some required arguments starting with $requestConfiguration.
Loading history...
1861
        $flashHelper->addSuccessFlash(Argument::any())->shouldNotBeCalled();
0 ignored issues
show
Bug introduced by
The call to addSuccessFlash() misses a required argument $actionName.

This check looks for function calls that miss required arguments.

Loading history...
1862
        $flashHelper->addFlashFromEvent(Argument::any())->shouldNotBeCalled();
0 ignored issues
show
Bug introduced by
The call to addFlashFromEvent() misses a required argument $event.

This check looks for function calls that miss required arguments.

Loading history...
1863
1864
        $this
1865
            ->shouldThrow(new HttpException(403, 'Invalid csrf token.'))
1866
            ->during('deleteAction', [$request])
1867
        ;
1868
    }
1869
1870
    function it_throws_a_403_exception_if_user_is_unauthorized_to_apply_state_machine_transition_on_resource(
1871
        MetadataInterface $metadata,
1872
        RequestConfigurationFactoryInterface $requestConfigurationFactory,
1873
        RequestConfiguration $configuration,
1874
        Request $request,
1875
        AuthorizationCheckerInterface $authorizationChecker
1876
    ): void {
1877
        $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Bundle\Res...r\RequestConfiguration>.

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...
1878
        $configuration->hasPermission()->willReturn(true);
1879
        $configuration->getPermission(ResourceActions::UPDATE)->willReturn('sylius.product.update');
1880
1881
        $authorizationChecker->isGranted($configuration, 'sylius.product.update')->willReturn(false);
1882
1883
        $this
1884
            ->shouldThrow(new AccessDeniedException())
1885
            ->during('applyStateMachineTransitionAction', [$request])
1886
        ;
1887
    }
1888
1889
    function it_throws_a_404_exception_if_resource_is_not_found_when_trying_to_apply_state_machine_transition(
1890
        MetadataInterface $metadata,
1891
        RequestConfigurationFactoryInterface $requestConfigurationFactory,
1892
        RequestConfiguration $configuration,
1893
        Request $request,
1894
        AuthorizationCheckerInterface $authorizationChecker,
1895
        RepositoryInterface $repository,
1896
        SingleResourceProviderInterface $singleResourceProvider
1897
    ): void {
1898
        $metadata->getHumanizedName()->willReturn('product');
1899
        $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Bundle\Res...r\RequestConfiguration>.

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...
1900
        $configuration->hasPermission()->willReturn(true);
1901
        $configuration->getPermission(ResourceActions::UPDATE)->willReturn('sylius.product.update');
1902
1903
        $authorizationChecker->isGranted($configuration, 'sylius.product.update')->willReturn(true);
1904
        $singleResourceProvider->get($configuration, $repository)->willReturn(null);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...odel\ResourceInterface>.

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...
1905
1906
        $this
1907
            ->shouldThrow(new NotFoundHttpException('The "product" has not been found'))
1908
            ->during('applyStateMachineTransitionAction', [$request])
1909
        ;
1910
    }
1911
1912
    function it_does_not_apply_state_machine_transition_on_resource_if_not_applicable_and_returns_400_bad_request(
1913
        MetadataInterface $metadata,
1914
        RequestConfigurationFactoryInterface $requestConfigurationFactory,
1915
        RequestConfiguration $configuration,
1916
        AuthorizationCheckerInterface $authorizationChecker,
1917
        RepositoryInterface $repository,
1918
        ObjectManager $objectManager,
1919
        StateMachineInterface $stateMachine,
1920
        SingleResourceProviderInterface $singleResourceProvider,
1921
        ResourceInterface $resource,
1922
        FlashHelperInterface $flashHelper,
1923
        EventDispatcherInterface $eventDispatcher,
1924
        CsrfTokenManagerInterface $csrfTokenManager,
1925
        ContainerInterface $container,
1926
        ResourceControllerEvent $event,
1927
        Request $request
1928
    ): void {
1929
        $metadata->getApplicationName()->willReturn('sylius');
1930
        $metadata->getName()->willReturn('product');
1931
1932
        $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Bundle\Res...r\RequestConfiguration>.

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...
1933
        $configuration->hasPermission()->willReturn(true);
1934
        $configuration->getPermission(ResourceActions::UPDATE)->willReturn('sylius.product.update');
1935
        $configuration->isCsrfProtectionEnabled()->willReturn(true);
1936
        $request->get('_csrf_token')->willReturn('xyz');
1937
1938
        $container->has('security.csrf.token_manager')->willReturn(true);
1939
        $container->get('security.csrf.token_manager')->willReturn($csrfTokenManager);
1940
        $csrfTokenManager->isTokenValid(new CsrfToken('1', 'xyz'))->willReturn(true);
1941
1942
        $authorizationChecker->isGranted($configuration, 'sylius.product.update')->willReturn(true);
1943
        $singleResourceProvider->get($configuration, $repository)->willReturn($resource);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...odel\ResourceInterface>.

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...
1944
1945
        $resource->getId()->willReturn('1');
1946
1947
        $configuration->isHtmlRequest()->willReturn(true);
1948
1949
        $eventDispatcher->dispatchPreEvent(ResourceActions::UPDATE, $configuration, $resource)->willReturn($event);
1950
        $event->isStopped()->willReturn(false);
1951
1952
        $stateMachine->can($configuration, $resource)->willReturn(false);
1953
1954
        $stateMachine->apply($configuration, $resource)->shouldNotBeCalled();
1955
        $objectManager->flush()->shouldNotBeCalled();
1956
1957
        $eventDispatcher->dispatchPostEvent(Argument::any())->shouldNotBeCalled();
0 ignored issues
show
Bug introduced by
The call to dispatchPostEvent() misses some required arguments starting with $requestConfiguration.
Loading history...
1958
        $flashHelper->addSuccessFlash(Argument::any())->shouldNotBeCalled();
0 ignored issues
show
Bug introduced by
The call to addSuccessFlash() misses a required argument $actionName.

This check looks for function calls that miss required arguments.

Loading history...
1959
        $flashHelper->addFlashFromEvent(Argument::any())->shouldNotBeCalled();
0 ignored issues
show
Bug introduced by
The call to addFlashFromEvent() misses a required argument $event.

This check looks for function calls that miss required arguments.

Loading history...
1960
1961
        $this
1962
            ->shouldThrow(new BadRequestHttpException())
1963
            ->during('applyStateMachineTransitionAction', [$request])
1964
        ;
1965
    }
1966
1967
    function it_applies_state_machine_transition_to_resource_and_redirects_for_html_request(
1968
        MetadataInterface $metadata,
1969
        RequestConfigurationFactoryInterface $requestConfigurationFactory,
1970
        RepositoryInterface $repository,
1971
        ObjectManager $manager,
1972
        SingleResourceProviderInterface $singleResourceProvider,
1973
        RedirectHandlerInterface $redirectHandler,
1974
        FlashHelperInterface $flashHelper,
1975
        AuthorizationCheckerInterface $authorizationChecker,
1976
        EventDispatcherInterface $eventDispatcher,
1977
        CsrfTokenManagerInterface $csrfTokenManager,
1978
        ContainerInterface $container,
1979
        StateMachineInterface $stateMachine,
1980
        ResourceUpdateHandlerInterface $resourceUpdateHandler,
1981
        RequestConfiguration $configuration,
1982
        ResourceInterface $resource,
1983
        ResourceControllerEvent $event,
1984
        ResourceControllerEvent $postEvent,
1985
        Request $request,
1986
        Response $redirectResponse
1987
    ): void {
1988
        $metadata->getApplicationName()->willReturn('sylius');
1989
        $metadata->getName()->willReturn('product');
1990
1991
        $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Bundle\Res...r\RequestConfiguration>.

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...
1992
        $configuration->hasPermission()->willReturn(true);
1993
        $configuration->getPermission(ResourceActions::UPDATE)->willReturn('sylius.product.update');
1994
        $configuration->isCsrfProtectionEnabled()->willReturn(true);
1995
        $request->get('_csrf_token')->willReturn('xyz');
1996
1997
        $container->has('security.csrf.token_manager')->willReturn(true);
1998
        $container->get('security.csrf.token_manager')->willReturn($csrfTokenManager);
1999
        $csrfTokenManager->isTokenValid(new CsrfToken('1', 'xyz'))->willReturn(true);
2000
2001
        $authorizationChecker->isGranted($configuration, 'sylius.product.update')->willReturn(true);
2002
        $singleResourceProvider->get($configuration, $repository)->willReturn($resource);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...odel\ResourceInterface>.

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...
2003
2004
        $resource->getId()->willReturn('1');
2005
2006
        $configuration->isHtmlRequest()->willReturn(true);
2007
2008
        $eventDispatcher->dispatchPreEvent(ResourceActions::UPDATE, $configuration, $resource)->willReturn($event);
2009
        $event->isStopped()->willReturn(false);
2010
2011
        $stateMachine->can($configuration, $resource)->willReturn(true);
2012
        $resourceUpdateHandler->handle($resource, $configuration, $manager)->shouldBeCalled();
2013
2014
        $flashHelper->addSuccessFlash($configuration, ResourceActions::UPDATE, $resource)->shouldBeCalled();
2015
2016
        $eventDispatcher->dispatchPostEvent(ResourceActions::UPDATE, $configuration, $resource)->willReturn($postEvent);
2017
2018
        $postEvent->hasResponse()->willReturn(false);
2019
2020
        $redirectHandler->redirectToResource($configuration, $resource)->willReturn($redirectResponse);
2021
2022
        $this->applyStateMachineTransitionAction($request)->shouldReturn($redirectResponse);
2023
    }
2024
2025
    function it_uses_response_from_post_apply_state_machine_transition_event_if_defined(
2026
        MetadataInterface $metadata,
2027
        RequestConfigurationFactoryInterface $requestConfigurationFactory,
2028
        RepositoryInterface $repository,
2029
        ObjectManager $manager,
2030
        SingleResourceProviderInterface $singleResourceProvider,
2031
        FlashHelperInterface $flashHelper,
2032
        AuthorizationCheckerInterface $authorizationChecker,
2033
        EventDispatcherInterface $eventDispatcher,
2034
        CsrfTokenManagerInterface $csrfTokenManager,
2035
        ContainerInterface $container,
2036
        StateMachineInterface $stateMachine,
2037
        ResourceUpdateHandlerInterface $resourceUpdateHandler,
2038
        RequestConfiguration $configuration,
2039
        ResourceInterface $resource,
2040
        ResourceControllerEvent $event,
2041
        ResourceControllerEvent $postEvent,
2042
        Request $request,
2043
        Response $redirectResponse
2044
    ): void {
2045
        $metadata->getApplicationName()->willReturn('sylius');
2046
        $metadata->getName()->willReturn('product');
2047
2048
        $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Bundle\Res...r\RequestConfiguration>.

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...
2049
        $configuration->hasPermission()->willReturn(true);
2050
        $configuration->getPermission(ResourceActions::UPDATE)->willReturn('sylius.product.update');
2051
        $configuration->isCsrfProtectionEnabled()->willReturn(true);
2052
        $request->get('_csrf_token')->willReturn('xyz');
2053
2054
        $container->has('security.csrf.token_manager')->willReturn(true);
2055
        $container->get('security.csrf.token_manager')->willReturn($csrfTokenManager);
2056
        $csrfTokenManager->isTokenValid(new CsrfToken('1', 'xyz'))->willReturn(true);
2057
2058
        $authorizationChecker->isGranted($configuration, 'sylius.product.update')->willReturn(true);
2059
        $singleResourceProvider->get($configuration, $repository)->willReturn($resource);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...odel\ResourceInterface>.

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...
2060
2061
        $resource->getId()->willReturn('1');
2062
2063
        $configuration->isHtmlRequest()->willReturn(true);
2064
2065
        $eventDispatcher->dispatchPreEvent(ResourceActions::UPDATE, $configuration, $resource)->willReturn($event);
2066
        $event->isStopped()->willReturn(false);
2067
2068
        $stateMachine->can($configuration, $resource)->willReturn(true);
2069
        $resourceUpdateHandler->handle($resource, $configuration, $manager)->shouldBeCalled();
2070
2071
        $flashHelper->addSuccessFlash($configuration, ResourceActions::UPDATE, $resource)->shouldBeCalled();
2072
2073
        $eventDispatcher->dispatchPostEvent(ResourceActions::UPDATE, $configuration, $resource)->willReturn($postEvent);
2074
2075
        $postEvent->hasResponse()->willReturn(true);
2076
        $postEvent->getResponse()->willReturn($redirectResponse);
2077
2078
        $this->applyStateMachineTransitionAction($request)->shouldReturn($redirectResponse);
2079
    }
2080
2081
    function it_does_not_apply_state_machine_transition_on_resource_and_redirects_for_html_requests_stopped_via_event(
2082
        MetadataInterface $metadata,
2083
        RequestConfigurationFactoryInterface $requestConfigurationFactory,
2084
        RequestConfiguration $configuration,
2085
        AuthorizationCheckerInterface $authorizationChecker,
2086
        StateMachineInterface $stateMachine,
2087
        ObjectManager $manager,
2088
        RepositoryInterface $repository,
2089
        SingleResourceProviderInterface $singleResourceProvider,
2090
        ResourceInterface $resource,
2091
        RedirectHandlerInterface $redirectHandler,
2092
        FlashHelperInterface $flashHelper,
2093
        EventDispatcherInterface $eventDispatcher,
2094
        CsrfTokenManagerInterface $csrfTokenManager,
2095
        ContainerInterface $container,
2096
        ResourceControllerEvent $event,
2097
        Request $request,
2098
        Response $redirectResponse
2099
    ): void {
2100
        $metadata->getApplicationName()->willReturn('sylius');
2101
        $metadata->getName()->willReturn('product');
2102
2103
        $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Bundle\Res...r\RequestConfiguration>.

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...
2104
        $configuration->hasPermission()->willReturn(true);
2105
        $configuration->getPermission(ResourceActions::UPDATE)->willReturn('sylius.product.update');
2106
        $configuration->isCsrfProtectionEnabled()->willReturn(true);
2107
        $request->get('_csrf_token')->willReturn('xyz');
2108
2109
        $container->has('security.csrf.token_manager')->willReturn(true);
2110
        $container->get('security.csrf.token_manager')->willReturn($csrfTokenManager);
2111
        $csrfTokenManager->isTokenValid(new CsrfToken('1', 'xyz'))->willReturn(true);
2112
2113
        $authorizationChecker->isGranted($configuration, 'sylius.product.update')->willReturn(true);
2114
        $singleResourceProvider->get($configuration, $repository)->willReturn($resource);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...odel\ResourceInterface>.

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...
2115
2116
        $resource->getId()->willReturn('1');
2117
2118
        $configuration->isHtmlRequest()->willReturn(true);
2119
2120
        $eventDispatcher->dispatchPreEvent(ResourceActions::UPDATE, $configuration, $resource)->willReturn($event);
2121
        $event->isStopped()->willReturn(true);
2122
2123
        $manager->flush()->shouldNotBeCalled();
2124
        $stateMachine->apply($resource)->shouldNotBeCalled();
0 ignored issues
show
Bug introduced by
The call to apply() misses a required argument $resource.

This check looks for function calls that miss required arguments.

Loading history...
2125
2126
        $eventDispatcher->dispatchPostEvent(ResourceActions::UPDATE, $configuration, $resource)->shouldNotBeCalled();
2127
        $flashHelper->addSuccessFlash($configuration, ResourceActions::UPDATE, $resource)->shouldNotBeCalled();
2128
2129
        $event->hasResponse()->willReturn(false);
2130
2131
        $flashHelper->addFlashFromEvent($configuration, $event)->shouldBeCalled();
2132
        $redirectHandler->redirectToResource($configuration, $resource)->willReturn($redirectResponse);
2133
2134
        $this->applyStateMachineTransitionAction($request)->shouldReturn($redirectResponse);
2135
    }
2136
2137
    function it_does_not_apply_state_machine_transition_on_resource_and_return_event_response_for_html_requests_stopped_via_event(
2138
        MetadataInterface $metadata,
2139
        RequestConfigurationFactoryInterface $requestConfigurationFactory,
2140
        RequestConfiguration $configuration,
2141
        AuthorizationCheckerInterface $authorizationChecker,
2142
        StateMachineInterface $stateMachine,
2143
        ObjectManager $manager,
2144
        RepositoryInterface $repository,
2145
        SingleResourceProviderInterface $singleResourceProvider,
2146
        ResourceInterface $resource,
2147
        FlashHelperInterface $flashHelper,
2148
        EventDispatcherInterface $eventDispatcher,
2149
        CsrfTokenManagerInterface $csrfTokenManager,
2150
        ContainerInterface $container,
2151
        ResourceControllerEvent $event,
2152
        Request $request,
2153
        Response $response
2154
    ): void {
2155
        $metadata->getApplicationName()->willReturn('sylius');
2156
        $metadata->getName()->willReturn('product');
2157
2158
        $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Bundle\Res...r\RequestConfiguration>.

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...
2159
        $configuration->hasPermission()->willReturn(true);
2160
        $configuration->getPermission(ResourceActions::UPDATE)->willReturn('sylius.product.update');
2161
        $configuration->isCsrfProtectionEnabled()->willReturn(true);
2162
        $request->get('_csrf_token')->willReturn('xyz');
2163
2164
        $container->has('security.csrf.token_manager')->willReturn(true);
2165
        $container->get('security.csrf.token_manager')->willReturn($csrfTokenManager);
2166
        $csrfTokenManager->isTokenValid(new CsrfToken('1', 'xyz'))->willReturn(true);
2167
2168
        $authorizationChecker->isGranted($configuration, 'sylius.product.update')->willReturn(true);
2169
        $singleResourceProvider->get($configuration, $repository)->willReturn($resource);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...odel\ResourceInterface>.

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...
2170
2171
        $resource->getId()->willReturn('1');
2172
2173
        $configuration->isHtmlRequest()->willReturn(true);
2174
2175
        $eventDispatcher->dispatchPreEvent(ResourceActions::UPDATE, $configuration, $resource)->willReturn($event);
2176
        $event->isStopped()->willReturn(true);
2177
2178
        $manager->flush()->shouldNotBeCalled();
2179
        $stateMachine->apply($resource)->shouldNotBeCalled();
0 ignored issues
show
Bug introduced by
The call to apply() misses a required argument $resource.

This check looks for function calls that miss required arguments.

Loading history...
2180
2181
        $eventDispatcher->dispatchPostEvent(ResourceActions::UPDATE, $configuration, $resource)->shouldNotBeCalled();
2182
        $flashHelper->addSuccessFlash($configuration, ResourceActions::UPDATE, $resource)->shouldNotBeCalled();
2183
2184
        $flashHelper->addFlashFromEvent($configuration, $event)->shouldBeCalled();
2185
2186
        $event->hasResponse()->willReturn(true);
2187
        $event->getResponse()->willReturn($response);
2188
2189
        $this->applyStateMachineTransitionAction($request)->shouldReturn($response);
2190
    }
2191
2192
    function it_applies_state_machine_transition_on_resource_and_returns_200_for_non_html_requests(
2193
        MetadataInterface $metadata,
2194
        ParameterBagInterface $parameterBag,
2195
        RequestConfigurationFactoryInterface $requestConfigurationFactory,
2196
        ViewHandlerInterface $viewHandler,
2197
        RepositoryInterface $repository,
2198
        ObjectManager $manager,
2199
        SingleResourceProviderInterface $singleResourceProvider,
2200
        AuthorizationCheckerInterface $authorizationChecker,
2201
        EventDispatcherInterface $eventDispatcher,
2202
        StateMachineInterface $stateMachine,
2203
        ResourceUpdateHandlerInterface $resourceUpdateHandler,
2204
        RequestConfiguration $configuration,
2205
        ResourceInterface $resource,
2206
        ResourceControllerEvent $event,
2207
        Request $request,
2208
        Response $response
2209
    ): void {
2210
        $metadata->getApplicationName()->willReturn('sylius');
2211
        $metadata->getName()->willReturn('product');
2212
2213
        $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Bundle\Res...r\RequestConfiguration>.

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...
2214
        $configuration->getParameters()->willReturn($parameterBag);
2215
        $configuration->hasPermission()->willReturn(true);
2216
        $configuration->getPermission(ResourceActions::UPDATE)->willReturn('sylius.product.update');
2217
        $configuration->isCsrfProtectionEnabled()->willReturn(false);
2218
2219
        $parameterBag->get('return_content', true)->willReturn(true);
2220
2221
        $authorizationChecker->isGranted($configuration, 'sylius.product.update')->willReturn(true);
2222
        $singleResourceProvider->get($configuration, $repository)->willReturn($resource);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...odel\ResourceInterface>.

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...
2223
2224
        $configuration->isHtmlRequest()->willReturn(false);
2225
2226
        $eventDispatcher->dispatchPreEvent(ResourceActions::UPDATE, $configuration, $resource)->willReturn($event);
2227
        $event->isStopped()->willReturn(false);
2228
2229
        $stateMachine->can($configuration, $resource)->willReturn(true);
2230
        $resourceUpdateHandler->handle($resource, $configuration, $manager)->shouldBeCalled();
2231
2232
        $eventDispatcher->dispatchPostEvent(ResourceActions::UPDATE, $configuration, $resource)->shouldBeCalled();
2233
2234
        $expectedView = View::create($resource, 200);
2235
2236
        $viewHandler->handle($configuration, Argument::that($this->getViewComparingCallback($expectedView)))->willReturn($response);
2237
2238
        $this->applyStateMachineTransitionAction($request)->shouldReturn($response);
2239
    }
2240
2241
    function it_applies_state_machine_transition_on_resource_and_returns_204_for_non_html_requests_if_additional_option_added(
2242
        MetadataInterface $metadata,
2243
        ParameterBagInterface $parameterBag,
2244
        RequestConfigurationFactoryInterface $requestConfigurationFactory,
2245
        ViewHandlerInterface $viewHandler,
2246
        RepositoryInterface $repository,
2247
        ObjectManager $manager,
2248
        SingleResourceProviderInterface $singleResourceProvider,
2249
        AuthorizationCheckerInterface $authorizationChecker,
2250
        EventDispatcherInterface $eventDispatcher,
2251
        StateMachineInterface $stateMachine,
2252
        ResourceUpdateHandlerInterface $resourceUpdateHandler,
2253
        RequestConfiguration $configuration,
2254
        ResourceInterface $resource,
2255
        ResourceControllerEvent $event,
2256
        Request $request,
2257
        Response $response
2258
    ): void {
2259
        $metadata->getApplicationName()->willReturn('sylius');
2260
        $metadata->getName()->willReturn('product');
2261
2262
        $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Bundle\Res...r\RequestConfiguration>.

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...
2263
        $configuration->getParameters()->willReturn($parameterBag);
2264
        $configuration->hasPermission()->willReturn(true);
2265
        $configuration->getPermission(ResourceActions::UPDATE)->willReturn('sylius.product.update');
2266
        $configuration->isCsrfProtectionEnabled()->willReturn(false);
2267
2268
        $parameterBag->get('return_content', true)->willReturn(false);
2269
2270
        $authorizationChecker->isGranted($configuration, 'sylius.product.update')->willReturn(true);
2271
        $singleResourceProvider->get($configuration, $repository)->willReturn($resource);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...odel\ResourceInterface>.

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...
2272
2273
        $configuration->isHtmlRequest()->willReturn(false);
2274
2275
        $eventDispatcher->dispatchPreEvent(ResourceActions::UPDATE, $configuration, $resource)->willReturn($event);
2276
        $event->isStopped()->willReturn(false);
2277
2278
        $stateMachine->can($configuration, $resource)->willReturn(true);
2279
        $resourceUpdateHandler->handle($resource, $configuration, $manager)->shouldBeCalled();
2280
2281
        $eventDispatcher->dispatchPostEvent(ResourceActions::UPDATE, $configuration, $resource)->shouldBeCalled();
2282
2283
        $expectedView = View::create(null, 204);
2284
2285
        $viewHandler->handle($configuration, Argument::that($this->getViewComparingCallback($expectedView)))->willReturn($response);
2286
2287
        $this->applyStateMachineTransitionAction($request)->shouldReturn($response);
2288
    }
2289
2290
    function it_does_not_apply_state_machine_transition_resource_and_throws_http_exception_for_non_html_requests_stopped_via_event(
2291
        MetadataInterface $metadata,
2292
        RequestConfigurationFactoryInterface $requestConfigurationFactory,
2293
        RequestConfiguration $configuration,
2294
        AuthorizationCheckerInterface $authorizationChecker,
2295
        RepositoryInterface $repository,
2296
        ObjectManager $objectManager,
2297
        StateMachineInterface $stateMachine,
2298
        SingleResourceProviderInterface $singleResourceProvider,
2299
        ResourceInterface $resource,
2300
        FlashHelperInterface $flashHelper,
2301
        EventDispatcherInterface $eventDispatcher,
2302
        ResourceControllerEvent $event,
2303
        Request $request
2304
    ): void {
2305
        $metadata->getApplicationName()->willReturn('sylius');
2306
        $metadata->getName()->willReturn('product');
2307
2308
        $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Bundle\Res...r\RequestConfiguration>.

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...
2309
        $configuration->hasPermission()->willReturn(true);
2310
        $configuration->getPermission(ResourceActions::UPDATE)->willReturn('sylius.product.update');
2311
        $configuration->isCsrfProtectionEnabled()->willReturn(false);
2312
2313
        $authorizationChecker->isGranted($configuration, 'sylius.product.update')->willReturn(true);
2314
        $singleResourceProvider->get($configuration, $repository)->willReturn($resource);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...odel\ResourceInterface>.

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...
2315
2316
        $configuration->isHtmlRequest()->willReturn(false);
2317
2318
        $eventDispatcher->dispatchPreEvent(ResourceActions::UPDATE, $configuration, $resource)->willReturn($event);
2319
        $event->isStopped()->willReturn(true);
2320
        $event->getMessage()->willReturn('Cannot approve this product.');
2321
        $event->getErrorCode()->willReturn(500);
2322
2323
        $stateMachine->apply($configuration, $resource)->shouldNotBeCalled();
2324
        $objectManager->flush()->shouldNotBeCalled();
2325
2326
        $eventDispatcher->dispatchPostEvent(Argument::any())->shouldNotBeCalled();
0 ignored issues
show
Bug introduced by
The call to dispatchPostEvent() misses some required arguments starting with $requestConfiguration.
Loading history...
2327
        $flashHelper->addSuccessFlash(Argument::any())->shouldNotBeCalled();
0 ignored issues
show
Bug introduced by
The call to addSuccessFlash() misses a required argument $actionName.

This check looks for function calls that miss required arguments.

Loading history...
2328
        $flashHelper->addFlashFromEvent(Argument::any())->shouldNotBeCalled();
0 ignored issues
show
Bug introduced by
The call to addFlashFromEvent() misses a required argument $event.

This check looks for function calls that miss required arguments.

Loading history...
2329
2330
        $this
2331
            ->shouldThrow(new HttpException(500, 'Cannot approve this product.'))
2332
            ->during('applyStateMachineTransitionAction', [$request])
2333
        ;
2334
    }
2335
2336
    /**
2337
     * {@inheritdoc}
2338
     */
2339
    private function getViewComparingCallback(View $expectedView)
2340
    {
2341
        return function ($value) use ($expectedView) {
2342
            if (!$value instanceof View) {
0 ignored issues
show
Bug introduced by
The class FOS\RestBundle\View\View does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
2343
                return false;
2344
            }
2345
2346
            // Need to unwrap phpspec's Collaborators to ensure proper comparison.
2347
            $this->unwrapViewData($expectedView);
2348
            $this->nullifyDates($value);
2349
            $this->nullifyDates($expectedView);
2350
2351
            return
2352
                $expectedView->getStatusCode() === $value->getStatusCode() &&
2353
                $expectedView->getHeaders() === $value->getHeaders() &&
2354
                $expectedView->getEngine() === $value->getEngine() &&
2355
                $expectedView->getFormat() === $value->getFormat() &&
2356
                $expectedView->getData() === $value->getData() &&
2357
                $expectedView->getTemplate() === $value->getTemplate() &&
2358
                $expectedView->getTemplateVar() === $value->getTemplateVar()
2359
            ;
2360
        };
2361
    }
2362
2363
    /**
2364
     * @param View $view
2365
     */
2366
    private function unwrapViewData(View $view)
2367
    {
2368
        $view->setData($this->unwrapIfCollaborator($view->getData()));
2369
    }
2370
2371
    /**
2372
     * @param mixed $value
2373
     *
2374
     * @return mixed
2375
     */
2376
    private function unwrapIfCollaborator($value)
2377
    {
2378
        if (null === $value) {
2379
            return null;
2380
        }
2381
2382
        if ($value instanceof Collaborator) {
0 ignored issues
show
Bug introduced by
The class PhpSpec\Wrapper\Collaborator does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
2383
            return $value->getWrappedObject();
2384
        }
2385
2386
        if (is_array($value)) {
2387
            foreach ($value as $key => $childValue) {
2388
                $value[$key] = $this->unwrapIfCollaborator($childValue);
2389
            }
2390
        }
2391
2392
        return $value;
2393
    }
2394
2395
    /**
2396
     * @param View $view
2397
     */
2398
    private function nullifyDates(View $view)
2399
    {
2400
        $headers = $view->getHeaders();
2401
        unset($headers['date']);
2402
        $view->setHeaders($headers);
2403
    }
2404
}
2405