|
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\Component\Core\Model; |
|
13
|
|
|
|
|
14
|
|
|
use PhpSpec\ObjectBehavior; |
|
15
|
|
|
use Prophecy\Argument; |
|
16
|
|
|
use Sylius\Component\Core\Model\AdjustmentInterface; |
|
17
|
|
|
use Sylius\Component\Core\Model\OrderItemInterface; |
|
18
|
|
|
use Sylius\Component\Core\Model\OrderItemUnit; |
|
19
|
|
|
use Sylius\Component\Core\Model\OrderItemUnitInterface; |
|
20
|
|
|
use Sylius\Component\Core\Model\ProductVariantInterface; |
|
21
|
|
|
use Sylius\Component\Inventory\Model\InventoryUnitInterface; |
|
22
|
|
|
use Sylius\Component\Order\Model\OrderItemUnit as BaseOrderItemUnit; |
|
23
|
|
|
use Sylius\Component\Shipping\Model\ShipmentInterface; |
|
24
|
|
|
use Sylius\Component\Shipping\Model\ShipmentUnitInterface; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @author Mateusz Zalewski <[email protected]> |
|
28
|
|
|
*/ |
|
29
|
|
|
final class OrderItemUnitSpec extends ObjectBehavior |
|
30
|
|
|
{ |
|
31
|
|
|
function let(OrderItemInterface $orderItem) |
|
32
|
|
|
{ |
|
33
|
|
|
$orderItem->getUnitPrice()->willReturn(1000); |
|
34
|
|
|
$orderItem->addUnit(Argument::type(OrderItemUnitInterface::class))->shouldBeCalled(); |
|
35
|
|
|
$this->beConstructedWith($orderItem); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
function it_is_initializable() |
|
39
|
|
|
{ |
|
40
|
|
|
$this->shouldHaveType(OrderItemUnit::class); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
function it_implements_an_order_item_unit_interface() |
|
44
|
|
|
{ |
|
45
|
|
|
$this->shouldImplement(OrderItemUnitInterface::class); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
function it_implements_an_inventory_unit_interface() |
|
49
|
|
|
{ |
|
50
|
|
|
$this->shouldImplement(InventoryUnitInterface::class); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
function it_implements_a_shipment_unit_interface() |
|
54
|
|
|
{ |
|
55
|
|
|
$this->shouldImplement(ShipmentUnitInterface::class); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
function it_is_an_order_item_unit() |
|
59
|
|
|
{ |
|
60
|
|
|
$this->shouldHaveType(BaseOrderItemUnit::class); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
function its_shipment_is_mutable(ShipmentInterface $shipment) |
|
64
|
|
|
{ |
|
65
|
|
|
$this->setShipment($shipment); |
|
66
|
|
|
$this->getShipment()->shouldReturn($shipment); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
function its_created_at_is_mutable(\DateTime $createdAt) |
|
70
|
|
|
{ |
|
71
|
|
|
$this->setCreatedAt($createdAt); |
|
72
|
|
|
$this->getCreatedAt()->shouldReturn($createdAt); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
function its_updated_at_is_mutable(\DateTime $updatedAt) |
|
76
|
|
|
{ |
|
77
|
|
|
$this->setUpdatedAt($updatedAt); |
|
78
|
|
|
$this->getUpdatedAt()->shouldReturn($updatedAt); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
function its_stockable_is_an_order_item_variant(OrderItemInterface $orderItem, ProductVariantInterface $variant) |
|
82
|
|
|
{ |
|
83
|
|
|
$orderItem->getVariant()->willReturn($variant); |
|
84
|
|
|
|
|
85
|
|
|
$this->getStockable()->shouldReturn($variant); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
function its_shippable_is_an_order_item_variant(OrderItemInterface $orderItem, ProductVariantInterface $variant) |
|
89
|
|
|
{ |
|
90
|
|
|
$orderItem->getVariant()->willReturn($variant); |
|
91
|
|
|
|
|
92
|
|
|
$this->getShippable()->shouldReturn($variant); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
function it_returns_0_tax_total_when_there_are_no_tax_adjustments() |
|
96
|
|
|
{ |
|
97
|
|
|
$this->getTaxTotal()->shouldReturn(0); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
function it_returns_a_sum_of_neutral_and_non_neutral_tax_adjustments_as_tax_total( |
|
101
|
|
|
OrderItemInterface $orderItem, |
|
102
|
|
|
AdjustmentInterface $nonNeutralTaxAdjustment, |
|
|
|
|
|
|
103
|
|
|
AdjustmentInterface $neutralTaxAdjustment |
|
104
|
|
|
) { |
|
105
|
|
|
$neutralTaxAdjustment->isNeutral()->willReturn(true); |
|
106
|
|
|
$neutralTaxAdjustment->getType()->willReturn(AdjustmentInterface::TAX_ADJUSTMENT); |
|
107
|
|
|
$neutralTaxAdjustment->getAmount()->willReturn(200); |
|
108
|
|
|
$nonNeutralTaxAdjustment->isNeutral()->willReturn(false); |
|
109
|
|
|
$nonNeutralTaxAdjustment->getType()->willReturn(AdjustmentInterface::TAX_ADJUSTMENT); |
|
110
|
|
|
$nonNeutralTaxAdjustment->getAmount()->willReturn(300); |
|
111
|
|
|
|
|
112
|
|
|
$orderItem->recalculateUnitsTotal()->shouldBeCalled(); |
|
113
|
|
|
$neutralTaxAdjustment->setAdjustable($this)->shouldBeCalled(); |
|
114
|
|
|
$nonNeutralTaxAdjustment->setAdjustable($this)->shouldBeCalled(); |
|
115
|
|
|
$this->addAdjustment($neutralTaxAdjustment); |
|
116
|
|
|
$this->addAdjustment($nonNeutralTaxAdjustment); |
|
117
|
|
|
|
|
118
|
|
|
$this->getTaxTotal()->shouldReturn(500); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
function it_returns_only_sum_of_neutral_and_non_neutral_tax_adjustments_as_tax_total( |
|
122
|
|
|
OrderItemInterface $orderItem, |
|
123
|
|
|
AdjustmentInterface $nonNeutralTaxAdjustment, |
|
|
|
|
|
|
124
|
|
|
AdjustmentInterface $neutralTaxAdjustment, |
|
125
|
|
|
AdjustmentInterface $notTaxAdjustment |
|
126
|
|
|
) { |
|
127
|
|
|
$neutralTaxAdjustment->isNeutral()->willReturn(true); |
|
128
|
|
|
$neutralTaxAdjustment->getType()->willReturn(AdjustmentInterface::TAX_ADJUSTMENT); |
|
129
|
|
|
$neutralTaxAdjustment->getAmount()->willReturn(200); |
|
130
|
|
|
$nonNeutralTaxAdjustment->isNeutral()->willReturn(false); |
|
131
|
|
|
$nonNeutralTaxAdjustment->getType()->willReturn(AdjustmentInterface::TAX_ADJUSTMENT); |
|
132
|
|
|
$nonNeutralTaxAdjustment->getAmount()->willReturn(300); |
|
133
|
|
|
$notTaxAdjustment->isNeutral()->willReturn(false); |
|
134
|
|
|
$notTaxAdjustment->getType()->willReturn(AdjustmentInterface::ORDER_PROMOTION_ADJUSTMENT); |
|
135
|
|
|
$notTaxAdjustment->getAmount()->willReturn(100); |
|
136
|
|
|
|
|
137
|
|
|
$orderItem->recalculateUnitsTotal()->shouldBeCalled(); |
|
138
|
|
|
$neutralTaxAdjustment->setAdjustable($this)->shouldBeCalled(); |
|
139
|
|
|
$nonNeutralTaxAdjustment->setAdjustable($this)->shouldBeCalled(); |
|
140
|
|
|
$notTaxAdjustment->setAdjustable($this)->shouldBeCalled(); |
|
141
|
|
|
$this->addAdjustment($neutralTaxAdjustment); |
|
142
|
|
|
$this->addAdjustment($nonNeutralTaxAdjustment); |
|
143
|
|
|
$this->addAdjustment($notTaxAdjustment); |
|
144
|
|
|
|
|
145
|
|
|
$this->getTaxTotal()->shouldReturn(500); |
|
146
|
|
|
} |
|
147
|
|
|
} |
|
148
|
|
|
|
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.