Completed
Push — master ( 1ecbe4...2ec63c )
by Kamil
21:52
created

StateMachineSpec   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 5
dl 0
loc 43
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 4 1
A it_is_initializable() 0 4 1
A it_implements_state_machine_interface() 0 4 1
A it_throws_an_exception_if_transition_is_not_defined() 0 9 1
A it_applies_configured_state_machine_transition() 0 15 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
namespace spec\Sylius\Bundle\ResourceBundle\Controller;
13
14
use PhpSpec\ObjectBehavior;
15
use Prophecy\Argument;
16
use SM\Factory\FactoryInterface;
17
use SM\StateMachine\StateMachineInterface;
18
use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration;
19
use Sylius\Bundle\ResourceBundle\Controller\StateMachine;
20
use Sylius\Bundle\ResourceBundle\Controller\StateMachineInterface as ResourceStateMachineInterface;
21
use Sylius\Component\Resource\Model\ResourceInterface;
22
23
/**
24
 * @mixin StateMachine
25
 *
26
 * @author Paweł Jędrzejewski <[email protected]>
27
 */
28
class StateMachineSpec extends ObjectBehavior
29
{
30
    function let(FactoryInterface $stateMachineFactory)
31
    {
32
        $this->beConstructedWith($stateMachineFactory);
33
    }
34
35
    function it_is_initializable()
36
    {
37
        $this->shouldHaveType('Sylius\Bundle\ResourceBundle\Controller\StateMachine');
38
    }
39
40
    function it_implements_state_machine_interface()
41
    {
42
        $this->shouldImplement(ResourceStateMachineInterface::class);
43
    }
44
45
    function it_throws_an_exception_if_transition_is_not_defined(RequestConfiguration $requestConfiguration, ResourceInterface $resource)
46
    {
47
        $requestConfiguration->hasStateMachine()->willReturn(false);
48
49
        $this
50
            ->shouldThrow(new \InvalidArgumentException('State machine must be configured to apply transition, check your routing.'))
51
            ->during('apply', [$requestConfiguration, $resource])
52
        ;
53
    }
54
55
    function it_applies_configured_state_machine_transition(
56
        RequestConfiguration $requestConfiguration,
57
        ResourceInterface $resource,
58
        FactoryInterface $stateMachineFactory,
59
        StateMachineInterface $stateMachine
60
    ) {
61
        $requestConfiguration->hasStateMachine()->willReturn(true);
62
        $requestConfiguration->getStateMachineGraph()->willReturn('sylius_product_review_state');
63
        $requestConfiguration->getStateMachineTransition()->willReturn('reject');
64
65
        $stateMachineFactory->get($resource, 'sylius_product_review_state')->willReturn($stateMachine);
66
        $stateMachine->apply('reject')->shouldBeCalled();
67
68
        $this->apply($requestConfiguration, $resource);
69
    }
70
}
71