Completed
Push — pr-9119 ( 4ecfb3 )
by Kamil
31:30
created

OrderItemQuantityModifierSpec   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 5
dl 0
loc 81
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 4 1
A it_implements_an_order_item_quantity_modifier_interface() 0 4 1
A it_adds_proper_number_of_order_item_units_to_an_order_item() 0 10 1
A it_removes_units_if_target_quantity_is_lower_than_current() 0 18 1
A it_does_nothing_if_target_quantity_is_equal_to_current() 0 12 1
A it_does_nothing_if_target_quantity_is_0() 0 12 1
A it_does_nothing_if_target_quantity_is_below_0() 0 12 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\Component\Order\Modifier;
15
16
use Doctrine\Common\Collections\ArrayCollection;
17
use PhpSpec\ObjectBehavior;
18
use Prophecy\Argument;
19
use Sylius\Component\Order\Factory\OrderItemUnitFactoryInterface;
20
use Sylius\Component\Order\Model\OrderItemInterface;
21
use Sylius\Component\Order\Model\OrderItemUnitInterface;
22
use Sylius\Component\Order\Modifier\OrderItemQuantityModifierInterface;
23
24
final class OrderItemQuantityModifierSpec extends ObjectBehavior
25
{
26
    function let(OrderItemUnitFactoryInterface $orderItemUnitFactory): void
27
    {
28
        $this->beConstructedWith($orderItemUnitFactory);
29
    }
30
31
    function it_implements_an_order_item_quantity_modifier_interface(): void
32
    {
33
        $this->shouldImplement(OrderItemQuantityModifierInterface::class);
34
    }
35
36
    function it_adds_proper_number_of_order_item_units_to_an_order_item(
37
        OrderItemUnitFactoryInterface $orderItemUnitFactory,
38
        OrderItemInterface $orderItem
39
    ): void {
40
        $orderItem->getQuantity()->willReturn(1);
41
42
        $orderItemUnitFactory->createForItem($orderItem)->shouldBeCalledTimes(2);
43
44
        $this->modify($orderItem, 3);
45
    }
46
47
    function it_removes_units_if_target_quantity_is_lower_than_current(
48
        OrderItemInterface $orderItem,
49
        OrderItemUnitInterface $unit1,
50
        OrderItemUnitInterface $unit2,
51
        OrderItemUnitInterface $unit3,
52
        OrderItemUnitInterface $unit4
53
    ): void {
54
        $orderItem->getQuantity()->willReturn(4);
55
        $orderItem->getUnits()->willReturn(new ArrayCollection([
56
            $unit1->getWrappedObject(),
57
            $unit2->getWrappedObject(),
58
            $unit3->getWrappedObject(),
59
            $unit4->getWrappedObject(),
60
        ]));
61
        $orderItem->removeUnit($unit1)->shouldBeCalled();
62
63
        $this->modify($orderItem, 3);
64
    }
65
66
    function it_does_nothing_if_target_quantity_is_equal_to_current(
67
        OrderItemUnitFactoryInterface $orderItemUnitFactory,
68
        OrderItemInterface $orderItem
69
    ): void {
70
        $orderItem->getQuantity()->willReturn(3);
71
72
        $orderItemUnitFactory->createForItem(Argument::any())->shouldNotBeCalled();
73
        $orderItem->addUnit(Argument::any())->shouldNotBeCalled();
74
        $orderItem->removeUnit(Argument::any())->shouldNotBeCalled();
75
76
        $this->modify($orderItem, 3);
77
    }
78
79
    function it_does_nothing_if_target_quantity_is_0(
80
        OrderItemUnitFactoryInterface $orderItemUnitFactory,
81
        OrderItemInterface $orderItem
82
    ): void {
83
        $orderItem->getQuantity()->willReturn(3);
84
85
        $orderItemUnitFactory->createForItem(Argument::any())->shouldNotBeCalled();
86
        $orderItem->addUnit(Argument::any())->shouldNotBeCalled();
87
        $orderItem->removeUnit(Argument::any())->shouldNotBeCalled();
88
89
        $this->modify($orderItem, 0);
90
    }
91
92
    function it_does_nothing_if_target_quantity_is_below_0(
93
        OrderItemUnitFactoryInterface $orderItemUnitFactory,
94
        OrderItemInterface $orderItem
95
    ): void {
96
        $orderItem->getQuantity()->willReturn(3);
97
98
        $orderItemUnitFactory->createForItem(Argument::any())->shouldNotBeCalled();
99
        $orderItem->addUnit(Argument::any())->shouldNotBeCalled();
100
        $orderItem->removeUnit(Argument::any())->shouldNotBeCalled();
101
102
        $this->modify($orderItem, -10);
103
    }
104
}
105