Completed
Push — 1.2-packages-require-1.2 ( d8563e )
by Kamil
35:32 queued 14:53
created

OrderShowMenuBuilderSpec   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 102
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 102
c 0
b 0
f 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 7 1
A it_creates_an_order_show_menu() 0 47 1
B it_creates_an_order_show_menu_when_cancel_transition_is_impossible() 0 34 1
A it_returns_an_empty_order_show_menu_when_there_is_no_order_in_options() 0 8 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\AdminBundle\Menu;
15
16
use Knp\Menu\FactoryInterface;
17
use Knp\Menu\ItemInterface;
18
use PhpSpec\ObjectBehavior;
19
use Prophecy\Argument;
20
use SM\Factory\FactoryInterface as StateMachineFactoryInterface;
21
use SM\StateMachine\StateMachineInterface;
22
use Sylius\Bundle\UiBundle\Menu\Event\MenuBuilderEvent;
23
use Sylius\Component\Core\Model\OrderInterface;
24
use Sylius\Component\Order\OrderTransitions;
25
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
26
27
final class OrderShowMenuBuilderSpec extends ObjectBehavior
28
{
29
    function let(
30
        FactoryInterface $factory,
31
        EventDispatcherInterface $eventDispatcher,
32
        StateMachineFactoryInterface $stateMachineFactory
33
    ): void {
34
        $this->beConstructedWith($factory, $eventDispatcher, $stateMachineFactory);
35
    }
36
37
    function it_creates_an_order_show_menu(
38
        FactoryInterface $factory,
39
        EventDispatcherInterface $eventDispatcher,
40
        StateMachineFactoryInterface $stateMachineFactory,
41
        ItemInterface $menu,
42
        StateMachineInterface $stateMachine,
43
        OrderInterface $order
44
    ): void {
45
        $factory->createItem('root')->willReturn($menu);
46
47
        $order->getId()->willReturn(7);
48
49
        $menu
50
            ->addChild('order_history', [
51
                'route' => 'sylius_admin_order_history',
52
                'routeParameters' => ['id' => 7],
53
            ])
54
            ->shouldBeCalled()
55
            ->willReturn($menu)
56
        ;
57
        $menu->setAttribute('type', 'link')->shouldBeCalled()->willReturn($menu);
58
        $menu->setLabel('sylius.ui.history')->shouldBeCalled()->willReturn($menu);
59
        $menu->setLabelAttribute('icon', 'history')->shouldBeCalled()->willReturn($menu);
60
61
        $stateMachineFactory->get($order, OrderTransitions::GRAPH)->willReturn($stateMachine);
62
        $stateMachine->can(OrderTransitions::TRANSITION_CANCEL)->willReturn(true);
63
64
        $menu
65
            ->addChild('cancel', [
66
                'route' => 'sylius_admin_order_cancel',
67
                'routeParameters' => ['id' => 7],
68
            ])
69
            ->shouldBeCalled()
70
            ->willReturn($menu)
71
        ;
72
        $menu->setAttribute('type', 'transition')->shouldBeCalled()->willReturn($menu);
73
        $menu->setLabel('sylius.ui.cancel')->shouldBeCalled()->willReturn($menu);
74
        $menu->setLabelAttribute('icon', 'ban')->shouldBeCalled()->willReturn($menu);
75
        $menu->setLabelAttribute('color', 'yellow')->shouldBeCalled()->willReturn($menu);
76
77
        $eventDispatcher
78
            ->dispatch('sylius.menu.admin.order.show', Argument::type(MenuBuilderEvent::class))
79
            ->shouldBeCalled()
80
        ;
81
82
        $this->createMenu(['order' => $order])->shouldReturn($menu);
83
    }
84
85
    function it_creates_an_order_show_menu_when_cancel_transition_is_impossible(
86
        FactoryInterface $factory,
87
        EventDispatcherInterface $eventDispatcher,
88
        StateMachineFactoryInterface $stateMachineFactory,
89
        ItemInterface $menu,
90
        StateMachineInterface $stateMachine,
91
        OrderInterface $order
92
    ): void {
93
        $factory->createItem('root')->willReturn($menu);
94
95
        $order->getId()->willReturn(7);
96
97
        $menu
98
            ->addChild('order_history', [
99
                'route' => 'sylius_admin_order_history',
100
                'routeParameters' => ['id' => 7],
101
            ])
102
            ->shouldBeCalled()
103
            ->willReturn($menu)
104
        ;
105
        $menu->setAttribute('type', 'link')->shouldBeCalled()->willReturn($menu);
106
        $menu->setLabel('sylius.ui.history')->shouldBeCalled()->willReturn($menu);
107
        $menu->setLabelAttribute('icon', 'history')->shouldBeCalled()->willReturn($menu);
108
109
        $stateMachineFactory->get($order, OrderTransitions::GRAPH)->willReturn($stateMachine);
110
        $stateMachine->can(OrderTransitions::TRANSITION_CANCEL)->willReturn(false);
111
112
        $eventDispatcher
113
            ->dispatch('sylius.menu.admin.order.show', Argument::type(MenuBuilderEvent::class))
114
            ->shouldBeCalled()
115
        ;
116
117
        $this->createMenu(['order' => $order])->shouldReturn($menu);
118
    }
119
120
    function it_returns_an_empty_order_show_menu_when_there_is_no_order_in_options(
121
        FactoryInterface $factory,
122
        ItemInterface $menu
123
    ): void {
124
        $factory->createItem('root')->willReturn($menu);
125
126
        $this->createMenu([])->shouldReturn($menu);
127
    }
128
}
129