|
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
|
|
|
namespace spec\Sylius\Bundle\ResourceBundle\Controller; |
|
13
|
|
|
|
|
14
|
|
|
use PhpSpec\ObjectBehavior; |
|
15
|
|
|
use SM\Factory\FactoryInterface; |
|
16
|
|
|
use SM\StateMachine\StateMachineInterface; |
|
17
|
|
|
use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration; |
|
18
|
|
|
use Sylius\Bundle\ResourceBundle\Controller\StateMachine; |
|
19
|
|
|
use Sylius\Bundle\ResourceBundle\Controller\StateMachineInterface as ResourceStateMachineInterface; |
|
20
|
|
|
use Sylius\Component\Resource\Model\ResourceInterface; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @author Paweł Jędrzejewski <[email protected]> |
|
24
|
|
|
*/ |
|
25
|
|
|
final class StateMachineSpec extends ObjectBehavior |
|
26
|
|
|
{ |
|
27
|
|
|
function let(FactoryInterface $stateMachineFactory) |
|
28
|
|
|
{ |
|
29
|
|
|
$this->beConstructedWith($stateMachineFactory); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
function it_is_initializable() |
|
33
|
|
|
{ |
|
34
|
|
|
$this->shouldHaveType(StateMachine::class); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
function it_implements_state_machine_interface() |
|
38
|
|
|
{ |
|
39
|
|
|
$this->shouldImplement(ResourceStateMachineInterface::class); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
function it_throws_an_exception_if_transition_is_not_defined_during_can(RequestConfiguration $requestConfiguration, ResourceInterface $resource) |
|
43
|
|
|
{ |
|
44
|
|
|
$requestConfiguration->hasStateMachine()->willReturn(false); |
|
45
|
|
|
|
|
46
|
|
|
$this |
|
47
|
|
|
->shouldThrow(new \InvalidArgumentException('State machine must be configured to apply transition, check your routing.')) |
|
48
|
|
|
->during('can', [$requestConfiguration, $resource]) |
|
49
|
|
|
; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
function it_throws_an_exception_if_transition_is_not_defined_during_apply(RequestConfiguration $requestConfiguration, ResourceInterface $resource) |
|
53
|
|
|
{ |
|
54
|
|
|
$requestConfiguration->hasStateMachine()->willReturn(false); |
|
55
|
|
|
|
|
56
|
|
|
$this |
|
57
|
|
|
->shouldThrow(new \InvalidArgumentException('State machine must be configured to apply transition, check your routing.')) |
|
58
|
|
|
->during('apply', [$requestConfiguration, $resource]) |
|
59
|
|
|
; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
function it_returns_if_configured_state_machine_can_transition( |
|
63
|
|
|
RequestConfiguration $requestConfiguration, |
|
64
|
|
|
ResourceInterface $resource, |
|
65
|
|
|
FactoryInterface $stateMachineFactory, |
|
66
|
|
|
StateMachineInterface $stateMachine |
|
67
|
|
|
) { |
|
68
|
|
|
$requestConfiguration->hasStateMachine()->willReturn(true); |
|
69
|
|
|
$requestConfiguration->getStateMachineGraph()->willReturn('sylius_product_review_state'); |
|
70
|
|
|
$requestConfiguration->getStateMachineTransition()->willReturn('reject'); |
|
71
|
|
|
|
|
72
|
|
|
$stateMachineFactory->get($resource, 'sylius_product_review_state')->willReturn($stateMachine); |
|
73
|
|
|
$stateMachine->can('reject')->willReturn(true); |
|
74
|
|
|
|
|
75
|
|
|
$this->can($requestConfiguration, $resource)->shouldReturn(true); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
function it_applies_configured_state_machine_transition( |
|
79
|
|
|
RequestConfiguration $requestConfiguration, |
|
80
|
|
|
ResourceInterface $resource, |
|
81
|
|
|
FactoryInterface $stateMachineFactory, |
|
82
|
|
|
StateMachineInterface $stateMachine |
|
83
|
|
|
) { |
|
84
|
|
|
$requestConfiguration->hasStateMachine()->willReturn(true); |
|
85
|
|
|
$requestConfiguration->getStateMachineGraph()->willReturn('sylius_product_review_state'); |
|
86
|
|
|
$requestConfiguration->getStateMachineTransition()->willReturn('reject'); |
|
87
|
|
|
|
|
88
|
|
|
$stateMachineFactory->get($resource, 'sylius_product_review_state')->willReturn($stateMachine); |
|
89
|
|
|
$stateMachine->apply('reject')->shouldBeCalled(); |
|
90
|
|
|
|
|
91
|
|
|
$this->apply($requestConfiguration, $resource); |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|