Completed
Push — checkout-optimisation ( 4a6bfb...756f29 )
by Kamil
18:24
created

ResourceUpdateHandlerSpec   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 4
dl 0
loc 45
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 4 1
A it_is_initializable() 0 4 1
A it_implements_a_resource_update_handler_interface() 0 4 1
A it_applies_a_state_machine_transition() 0 13 1
A it_does_not_apply_a_state_machine_transition() 0 13 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 Doctrine\Common\Persistence\ObjectManager;
15
use PhpSpec\ObjectBehavior;
16
use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration;
17
use Sylius\Bundle\ResourceBundle\Controller\ResourceUpdateHandler;
18
use Sylius\Bundle\ResourceBundle\Controller\ResourceUpdateHandlerInterface;
19
use Sylius\Bundle\ResourceBundle\Controller\StateMachineInterface;
20
use Sylius\Component\Resource\Model\ResourceInterface;
21
22
/**
23
 * @author Grzegorz Sadowski <[email protected]>
24
 */
25
final class ResourceUpdateHandlerSpec extends ObjectBehavior
26
{
27
    function let(StateMachineInterface $stateMachine)
28
    {
29
        $this->beConstructedWith($stateMachine);
30
    }
31
32
    function it_is_initializable()
33
    {
34
        $this->shouldHaveType(ResourceUpdateHandler::class);
35
    }
36
37
    function it_implements_a_resource_update_handler_interface()
38
    {
39
        $this->shouldImplement(ResourceUpdateHandlerInterface::class);
40
    }
41
42
    function it_applies_a_state_machine_transition(
43
        StateMachineInterface $stateMachine,
44
        ResourceInterface $resource,
45
        RequestConfiguration $configuration,
46
        ObjectManager $manager
47
    ) {
48
        $configuration->hasStateMachine()->willReturn(true);
49
        $stateMachine->apply($configuration, $resource)->shouldBeCalled();
50
51
        $manager->flush()->shouldBeCalled();
52
53
        $this->handle($resource, $configuration, $manager);
54
    }
55
56
    function it_does_not_apply_a_state_machine_transition(
57
        StateMachineInterface $stateMachine,
58
        ResourceInterface $resource,
59
        RequestConfiguration $configuration,
60
        ObjectManager $manager
61
    ) {
62
        $configuration->hasStateMachine()->willReturn(false);
63
        $stateMachine->apply($configuration, $resource)->shouldNotBeCalled();
64
65
        $manager->flush()->shouldBeCalled();
66
67
        $this->handle($resource, $configuration, $manager);
68
    }
69
}
70