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\Core\Model; |
15
|
|
|
|
16
|
|
|
use Doctrine\Common\Collections\Collection; |
17
|
|
|
use PhpSpec\ObjectBehavior; |
18
|
|
|
use Sylius\Component\Channel\Model\ChannelInterface; |
19
|
|
|
use Sylius\Component\Core\Model\AddressInterface; |
20
|
|
|
use Sylius\Component\Core\Model\AdjustmentInterface; |
21
|
|
|
use Sylius\Component\Core\Model\OrderItemInterface; |
22
|
|
|
use Sylius\Component\Core\Model\PaymentInterface; |
23
|
|
|
use Sylius\Component\Core\Model\PromotionInterface; |
24
|
|
|
use Sylius\Component\Core\Model\ShipmentInterface; |
25
|
|
|
use Sylius\Component\Core\OrderCheckoutStates; |
26
|
|
|
use Sylius\Component\Core\OrderShippingStates; |
27
|
|
|
use Sylius\Component\Customer\Model\CustomerInterface; |
28
|
|
|
use Sylius\Component\Order\Model\Order as BaseOrder; |
29
|
|
|
use Sylius\Component\Order\Model\OrderInterface; |
30
|
|
|
use Sylius\Component\Promotion\Model\PromotionCouponInterface; |
31
|
|
|
|
32
|
|
|
final class OrderSpec extends ObjectBehavior |
33
|
|
|
{ |
34
|
|
|
function it_implements_an_order_interface(): void |
35
|
|
|
{ |
36
|
|
|
$this->shouldImplement(OrderInterface::class); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
function it_extends_an_order(): void |
40
|
|
|
{ |
41
|
|
|
$this->shouldHaveType(BaseOrder::class); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
function it_does_not_have_a_customer_defined_by_default(): void |
45
|
|
|
{ |
46
|
|
|
$this->getCustomer()->shouldReturn(null); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
function its_allows_defining_customer(CustomerInterface $customer): void |
50
|
|
|
{ |
51
|
|
|
$this->setCustomer($customer); |
52
|
|
|
$this->getCustomer()->shouldReturn($customer); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
function its_channel_is_mutable(ChannelInterface $channel): void |
56
|
|
|
{ |
57
|
|
|
$this->setChannel($channel); |
58
|
|
|
$this->getChannel()->shouldReturn($channel); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
function it_does_not_have_shipping_address_by_default(): void |
62
|
|
|
{ |
63
|
|
|
$this->getShippingAddress()->shouldReturn(null); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
function it_allows_defining_shipping_address(AddressInterface $address): void |
67
|
|
|
{ |
68
|
|
|
$this->setShippingAddress($address); |
69
|
|
|
$this->getShippingAddress()->shouldReturn($address); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
function it_does_not_have_billing_address_by_default(): void |
73
|
|
|
{ |
74
|
|
|
$this->getBillingAddress()->shouldReturn(null); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
function it_allows_defining_billing_address(AddressInterface $address): void |
78
|
|
|
{ |
79
|
|
|
$this->setBillingAddress($address); |
80
|
|
|
$this->getBillingAddress()->shouldReturn($address); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
function its_checkout_state_is_mutable(): void |
84
|
|
|
{ |
85
|
|
|
$this->setCheckoutState(OrderCheckoutStates::STATE_CART); |
86
|
|
|
$this->getCheckoutState()->shouldReturn(OrderCheckoutStates::STATE_CART); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
function its_payment_state_is_mutable(): void |
90
|
|
|
{ |
91
|
|
|
$this->setPaymentState(PaymentInterface::STATE_COMPLETED); |
92
|
|
|
$this->getPaymentState()->shouldReturn(PaymentInterface::STATE_COMPLETED); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
function it_initializes_item_units_collection_by_default(): void |
96
|
|
|
{ |
97
|
|
|
$this->getItemUnits()->shouldHaveType(Collection::class); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
function it_initializes_shipments_collection_by_default(): void |
101
|
|
|
{ |
102
|
|
|
$this->getShipments()->shouldHaveType(Collection::class); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
function it_adds_shipment_properly(ShipmentInterface $shipment): void |
106
|
|
|
{ |
107
|
|
|
$this->shouldNotHaveShipment($shipment); |
108
|
|
|
|
109
|
|
|
$shipment->setOrder($this)->shouldBeCalled(); |
110
|
|
|
$this->addShipment($shipment); |
111
|
|
|
|
112
|
|
|
$this->shouldHaveShipment($shipment); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
function it_removes_a_shipment_properly(ShipmentInterface $shipment): void |
116
|
|
|
{ |
117
|
|
|
$shipment->setOrder($this)->shouldBeCalled(); |
118
|
|
|
$this->addShipment($shipment); |
119
|
|
|
|
120
|
|
|
$this->shouldHaveShipment($shipment); |
121
|
|
|
|
122
|
|
|
$shipment->setOrder(null)->shouldBeCalled(); |
123
|
|
|
$this->removeShipment($shipment); |
124
|
|
|
|
125
|
|
|
$this->shouldNotHaveShipment($shipment); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
function it_removes_shipments(ShipmentInterface $shipment): void |
129
|
|
|
{ |
130
|
|
|
$this->addShipment($shipment); |
131
|
|
|
$this->hasShipment($shipment)->shouldReturn(true); |
132
|
|
|
|
133
|
|
|
$this->removeShipments(); |
134
|
|
|
|
135
|
|
|
$this->hasShipment($shipment)->shouldReturn(false); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
function it_returns_shipping_adjustments( |
139
|
|
|
AdjustmentInterface $shippingAdjustment, |
140
|
|
|
AdjustmentInterface $taxAdjustment |
141
|
|
|
): void { |
142
|
|
|
$shippingAdjustment->getType()->willReturn(AdjustmentInterface::SHIPPING_ADJUSTMENT); |
143
|
|
|
$shippingAdjustment->setAdjustable($this)->shouldBeCalled(); |
144
|
|
|
$shippingAdjustment->isNeutral()->willReturn(true); |
145
|
|
|
|
146
|
|
|
$taxAdjustment->getType()->willReturn(AdjustmentInterface::TAX_ADJUSTMENT); |
147
|
|
|
$taxAdjustment->setAdjustable($this)->shouldBeCalled(); |
148
|
|
|
$taxAdjustment->isNeutral()->willReturn(true); |
149
|
|
|
|
150
|
|
|
$this->addAdjustment($shippingAdjustment); |
151
|
|
|
$this->addAdjustment($taxAdjustment); |
152
|
|
|
|
153
|
|
|
$this->getAdjustments()->count()->shouldReturn(2); |
154
|
|
|
|
155
|
|
|
$shippingAdjustments = $this->getAdjustments(AdjustmentInterface::SHIPPING_ADJUSTMENT); |
156
|
|
|
$shippingAdjustments->count()->shouldReturn(1); |
157
|
|
|
$shippingAdjustments->first()->shouldReturn($shippingAdjustment); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
function it_removes_shipping_adjustments( |
161
|
|
|
AdjustmentInterface $shippingAdjustment, |
162
|
|
|
AdjustmentInterface $taxAdjustment |
163
|
|
|
): void { |
164
|
|
|
$shippingAdjustment->getType()->willReturn(AdjustmentInterface::SHIPPING_ADJUSTMENT); |
165
|
|
|
$shippingAdjustment->setAdjustable($this)->shouldBeCalled(); |
166
|
|
|
$shippingAdjustment->isNeutral()->willReturn(true); |
167
|
|
|
|
168
|
|
|
$taxAdjustment->getType()->willReturn(AdjustmentInterface::TAX_ADJUSTMENT); |
169
|
|
|
$taxAdjustment->setAdjustable($this)->shouldBeCalled(); |
170
|
|
|
$taxAdjustment->isNeutral()->willReturn(true); |
171
|
|
|
|
172
|
|
|
$this->addAdjustment($shippingAdjustment); |
173
|
|
|
$this->addAdjustment($taxAdjustment); |
174
|
|
|
|
175
|
|
|
$this->getAdjustments()->count()->shouldReturn(2); |
176
|
|
|
|
177
|
|
|
$shippingAdjustment->isLocked()->willReturn(false); |
178
|
|
|
$shippingAdjustment->setAdjustable(null)->shouldBeCalled(); |
179
|
|
|
$this->removeAdjustments(AdjustmentInterface::SHIPPING_ADJUSTMENT); |
180
|
|
|
|
181
|
|
|
$this->getAdjustments()->count()->shouldReturn(1); |
182
|
|
|
$this->getAdjustments(AdjustmentInterface::SHIPPING_ADJUSTMENT)->count()->shouldReturn(0); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
function it_returns_tax_adjustments( |
186
|
|
|
AdjustmentInterface $shippingAdjustment, |
187
|
|
|
AdjustmentInterface $taxAdjustment |
188
|
|
|
): void { |
189
|
|
|
$shippingAdjustment->getType()->willReturn(AdjustmentInterface::SHIPPING_ADJUSTMENT); |
190
|
|
|
$shippingAdjustment->setAdjustable($this)->shouldBeCalled(); |
191
|
|
|
$shippingAdjustment->isNeutral()->willReturn(true); |
192
|
|
|
|
193
|
|
|
$taxAdjustment->getType()->willReturn(AdjustmentInterface::TAX_ADJUSTMENT); |
194
|
|
|
$taxAdjustment->setAdjustable($this)->shouldBeCalled(); |
195
|
|
|
$taxAdjustment->isNeutral()->willReturn(true); |
196
|
|
|
|
197
|
|
|
$this->addAdjustment($shippingAdjustment); |
198
|
|
|
$this->addAdjustment($taxAdjustment); |
199
|
|
|
|
200
|
|
|
$this->getAdjustments()->count()->shouldReturn(2); |
201
|
|
|
|
202
|
|
|
$taxAdjustments = $this->getAdjustments(AdjustmentInterface::TAX_ADJUSTMENT); |
203
|
|
|
$taxAdjustments->count()->shouldReturn(1); |
204
|
|
|
$taxAdjustments->first()->shouldReturn($taxAdjustment); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
function it_removes_tax_adjustments( |
208
|
|
|
AdjustmentInterface $shippingAdjustment, |
209
|
|
|
AdjustmentInterface $taxAdjustment |
210
|
|
|
): void { |
211
|
|
|
$shippingAdjustment->getType()->willReturn(AdjustmentInterface::SHIPPING_ADJUSTMENT); |
212
|
|
|
$shippingAdjustment->setAdjustable($this)->shouldBeCalled(); |
213
|
|
|
$shippingAdjustment->isNeutral()->willReturn(true); |
214
|
|
|
|
215
|
|
|
$taxAdjustment->getType()->willReturn(AdjustmentInterface::TAX_ADJUSTMENT); |
216
|
|
|
$taxAdjustment->setAdjustable($this)->shouldBeCalled(); |
217
|
|
|
$taxAdjustment->isNeutral()->willReturn(true); |
218
|
|
|
|
219
|
|
|
$this->addAdjustment($shippingAdjustment); |
220
|
|
|
$this->addAdjustment($taxAdjustment); |
221
|
|
|
|
222
|
|
|
$this->getAdjustments()->count()->shouldReturn(2); |
223
|
|
|
|
224
|
|
|
$taxAdjustment->isLocked()->willReturn(false); |
225
|
|
|
$taxAdjustment->setAdjustable(null)->shouldBeCalled(); |
226
|
|
|
$this->removeAdjustments(AdjustmentInterface::TAX_ADJUSTMENT); |
227
|
|
|
|
228
|
|
|
$this->getAdjustments()->count()->shouldReturn(1); |
229
|
|
|
$this->getAdjustments(AdjustmentInterface::TAX_ADJUSTMENT)->count()->shouldReturn(0); |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
function it_does_not_have_a_currency_code_defined_by_default(): void |
233
|
|
|
{ |
234
|
|
|
$this->getCurrencyCode()->shouldReturn(null); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
function it_allows_defining_a_currency_code(): void |
238
|
|
|
{ |
239
|
|
|
$this->setCurrencyCode('PLN'); |
240
|
|
|
$this->getCurrencyCode()->shouldReturn('PLN'); |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
function it_has_no_default_locale_code(): void |
244
|
|
|
{ |
245
|
|
|
$this->getLocaleCode()->shouldReturn(null); |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
function its_locale_code_is_mutable(): void |
249
|
|
|
{ |
250
|
|
|
$this->setLocaleCode('en'); |
251
|
|
|
$this->getLocaleCode()->shouldReturn('en'); |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
function it_has_a_cart_shipping_state_by_default(): void |
255
|
|
|
{ |
256
|
|
|
$this->getShippingState()->shouldReturn(OrderShippingStates::STATE_CART); |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
function its_shipping_state_is_mutable(): void |
260
|
|
|
{ |
261
|
|
|
$this->setShippingState(OrderShippingStates::STATE_SHIPPED); |
262
|
|
|
$this->getShippingState()->shouldReturn(OrderShippingStates::STATE_SHIPPED); |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
function it_adds_and_removes_payments(PaymentInterface $payment): void |
266
|
|
|
{ |
267
|
|
|
$payment->getState()->willReturn(PaymentInterface::STATE_NEW); |
268
|
|
|
$payment->setOrder($this)->shouldBeCalled(); |
269
|
|
|
|
270
|
|
|
$this->addPayment($payment); |
271
|
|
|
$this->shouldHavePayment($payment); |
272
|
|
|
|
273
|
|
|
$payment->setOrder(null)->shouldBeCalled(); |
274
|
|
|
|
275
|
|
|
$this->removePayment($payment); |
276
|
|
|
$this->shouldNotHavePayment($payment); |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
function it_returns_last_payment_with_given_state( |
280
|
|
|
PaymentInterface $payment1, |
281
|
|
|
PaymentInterface $payment2, |
282
|
|
|
PaymentInterface $payment3, |
283
|
|
|
PaymentInterface $payment4 |
284
|
|
|
): void { |
285
|
|
|
$payment1->getState()->willReturn(PaymentInterface::STATE_CART); |
286
|
|
|
$payment1->setOrder($this)->shouldBeCalled(); |
287
|
|
|
|
288
|
|
|
$payment2->getState()->willReturn(PaymentInterface::STATE_CANCELLED); |
289
|
|
|
$payment2->setOrder($this)->shouldBeCalled(); |
290
|
|
|
|
291
|
|
|
$payment3->getState()->willReturn(PaymentInterface::STATE_PROCESSING); |
292
|
|
|
$payment3->setOrder($this)->shouldBeCalled(); |
293
|
|
|
|
294
|
|
|
$payment4->getState()->willReturn(PaymentInterface::STATE_FAILED); |
295
|
|
|
$payment4->setOrder($this)->shouldBeCalled(); |
296
|
|
|
|
297
|
|
|
$this->addPayment($payment1); |
298
|
|
|
$this->addPayment($payment2); |
299
|
|
|
$this->addPayment($payment3); |
300
|
|
|
$this->addPayment($payment4); |
301
|
|
|
|
302
|
|
|
$this->getLastPayment(OrderInterface::STATE_CART)->shouldReturn($payment1); |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
function it_returns_a_null_if_there_is_no_payments_after_trying_to_get_last_payment(): void |
306
|
|
|
{ |
307
|
|
|
$this->getLastPayment(OrderInterface::STATE_CART)->shouldReturn(null); |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
function it_returns_last_payment_with_any_state_if_there_is_no_target_state_specified( |
311
|
|
|
PaymentInterface $payment1, |
312
|
|
|
PaymentInterface $payment2, |
313
|
|
|
PaymentInterface $payment3, |
314
|
|
|
PaymentInterface $payment4 |
315
|
|
|
): void { |
316
|
|
|
$payment1->getState()->willReturn(PaymentInterface::STATE_CART); |
317
|
|
|
$payment1->setOrder($this)->shouldBeCalled(); |
318
|
|
|
|
319
|
|
|
$payment2->getState()->willReturn(PaymentInterface::STATE_CANCELLED); |
320
|
|
|
$payment2->setOrder($this)->shouldBeCalled(); |
321
|
|
|
|
322
|
|
|
$payment3->getState()->willReturn(PaymentInterface::STATE_PROCESSING); |
323
|
|
|
$payment3->setOrder($this)->shouldBeCalled(); |
324
|
|
|
|
325
|
|
|
$payment4->getState()->willReturn(PaymentInterface::STATE_FAILED); |
326
|
|
|
$payment4->setOrder($this)->shouldBeCalled(); |
327
|
|
|
|
328
|
|
|
$this->addPayment($payment1); |
329
|
|
|
$this->addPayment($payment2); |
330
|
|
|
$this->addPayment($payment3); |
331
|
|
|
$this->addPayment($payment4); |
332
|
|
|
|
333
|
|
|
$this->getLastPayment()->shouldReturn($payment4); |
334
|
|
|
} |
335
|
|
|
|
336
|
|
|
function it_adds_and_removes_shipments(ShipmentInterface $shipment): void |
337
|
|
|
{ |
338
|
|
|
$shipment->setOrder($this)->shouldBeCalled(); |
339
|
|
|
|
340
|
|
|
$this->addShipment($shipment); |
341
|
|
|
$this->shouldHaveShipment($shipment); |
342
|
|
|
|
343
|
|
|
$shipment->setOrder(null)->shouldBeCalled(); |
344
|
|
|
|
345
|
|
|
$this->removeShipment($shipment); |
346
|
|
|
$this->shouldNotHaveShipment($shipment); |
347
|
|
|
} |
348
|
|
|
|
349
|
|
|
function it_has_a_promotion_coupon(PromotionCouponInterface $coupon): void |
350
|
|
|
{ |
351
|
|
|
$this->setPromotionCoupon($coupon); |
352
|
|
|
$this->getPromotionCoupon()->shouldReturn($coupon); |
353
|
|
|
} |
354
|
|
|
|
355
|
|
|
function it_counts_promotions_subjects(OrderItemInterface $item1, OrderItemInterface $item2): void |
356
|
|
|
{ |
357
|
|
|
$item1->getQuantity()->willReturn(4); |
358
|
|
|
$item1->getTotal()->willReturn(420); |
359
|
|
|
$item1->setOrder($this)->will(function () {}); |
360
|
|
|
|
361
|
|
|
$item2->getQuantity()->willReturn(3); |
362
|
|
|
$item2->getTotal()->willReturn(666); |
363
|
|
|
$item2->setOrder($this)->will(function () {}); |
364
|
|
|
|
365
|
|
|
$this->addItem($item1); |
366
|
|
|
$this->addItem($item2); |
367
|
|
|
|
368
|
|
|
$this->getPromotionSubjectCount()->shouldReturn(7); |
369
|
|
|
} |
370
|
|
|
|
371
|
|
|
function it_adds_and_removes_promotions(PromotionInterface $promotion): void |
372
|
|
|
{ |
373
|
|
|
$this->addPromotion($promotion); |
374
|
|
|
$this->shouldHavePromotion($promotion); |
375
|
|
|
|
376
|
|
|
$this->removePromotion($promotion); |
377
|
|
|
$this->shouldNotHavePromotion($promotion); |
378
|
|
|
} |
379
|
|
|
|
380
|
|
|
function it_returns_0_tax_total_when_there_are_no_items_and_adjustments(): void |
381
|
|
|
{ |
382
|
|
|
$this->getTaxTotal()->shouldReturn(0); |
383
|
|
|
} |
384
|
|
|
|
385
|
|
|
function it_returns_a_tax_of_all_items_as_tax_total_when_there_are_no_tax_adjustments( |
386
|
|
|
OrderItemInterface $orderItem1, |
387
|
|
|
OrderItemInterface $orderItem2 |
388
|
|
|
): void { |
389
|
|
|
$orderItem1->getTotal()->willReturn(1100); |
390
|
|
|
$orderItem1->getTaxTotal()->willReturn(100); |
391
|
|
|
$orderItem2->getTotal()->willReturn(1050); |
392
|
|
|
$orderItem2->getTaxTotal()->willReturn(50); |
393
|
|
|
|
394
|
|
|
$orderItem1->setOrder($this)->shouldBeCalled(); |
395
|
|
|
$orderItem2->setOrder($this)->shouldBeCalled(); |
396
|
|
|
$this->addItem($orderItem1); |
397
|
|
|
$this->addItem($orderItem2); |
398
|
|
|
|
399
|
|
|
$this->getTaxTotal()->shouldReturn(150); |
400
|
|
|
} |
401
|
|
|
|
402
|
|
|
function it_returns_a_tax_of_all_items_and_non_neutral_shipping_tax_as_tax_total( |
403
|
|
|
OrderItemInterface $orderItem1, |
404
|
|
|
OrderItemInterface $orderItem2, |
405
|
|
|
AdjustmentInterface $shippingAdjustment, |
406
|
|
|
AdjustmentInterface $shippingTaxAdjustment |
407
|
|
|
): void { |
408
|
|
|
$orderItem1->getTotal()->willReturn(1100); |
409
|
|
|
$orderItem1->getTaxTotal()->willReturn(100); |
410
|
|
|
$orderItem2->getTotal()->willReturn(1050); |
411
|
|
|
$orderItem2->getTaxTotal()->willReturn(50); |
412
|
|
|
|
413
|
|
|
$shippingAdjustment->getType()->willReturn(AdjustmentInterface::SHIPPING_ADJUSTMENT); |
414
|
|
|
$shippingAdjustment->isNeutral()->willReturn(false); |
415
|
|
|
$shippingAdjustment->getAmount()->willReturn(1000); |
416
|
|
|
$shippingTaxAdjustment->getType()->willReturn(AdjustmentInterface::TAX_ADJUSTMENT); |
417
|
|
|
$shippingTaxAdjustment->isNeutral()->willReturn(false); |
418
|
|
|
$shippingTaxAdjustment->getAmount()->willReturn(70); |
419
|
|
|
|
420
|
|
|
$orderItem1->setOrder($this)->shouldBeCalled(); |
421
|
|
|
$orderItem2->setOrder($this)->shouldBeCalled(); |
422
|
|
|
$this->addItem($orderItem1); |
423
|
|
|
$this->addItem($orderItem2); |
424
|
|
|
|
425
|
|
|
$shippingAdjustment->setAdjustable($this)->shouldBeCalled(); |
426
|
|
|
$this->addAdjustment($shippingAdjustment); |
427
|
|
|
|
428
|
|
|
$shippingTaxAdjustment->setAdjustable($this)->shouldBeCalled(); |
429
|
|
|
$this->addAdjustment($shippingTaxAdjustment); |
430
|
|
|
|
431
|
|
|
$this->getTaxTotal()->shouldReturn(220); |
432
|
|
|
} |
433
|
|
|
|
434
|
|
|
function it_returns_a_tax_of_all_items_and_neutral_shipping_tax_as_tax_total( |
435
|
|
|
OrderItemInterface $orderItem1, |
436
|
|
|
OrderItemInterface $orderItem2, |
437
|
|
|
AdjustmentInterface $shippingAdjustment, |
438
|
|
|
AdjustmentInterface $shippingTaxAdjustment |
439
|
|
|
): void { |
440
|
|
|
$orderItem1->getTotal()->willReturn(1100); |
441
|
|
|
$orderItem1->getTaxTotal()->willReturn(100); |
442
|
|
|
$orderItem2->getTotal()->willReturn(1050); |
443
|
|
|
$orderItem2->getTaxTotal()->willReturn(50); |
444
|
|
|
|
445
|
|
|
$shippingAdjustment->getType()->willReturn(AdjustmentInterface::SHIPPING_ADJUSTMENT); |
446
|
|
|
$shippingAdjustment->isNeutral()->willReturn(false); |
447
|
|
|
$shippingAdjustment->getAmount()->willReturn(1000); |
448
|
|
|
|
449
|
|
|
$shippingTaxAdjustment->getType()->willReturn(AdjustmentInterface::TAX_ADJUSTMENT); |
450
|
|
|
$shippingTaxAdjustment->isNeutral()->willReturn(true); |
451
|
|
|
$shippingTaxAdjustment->getAmount()->willReturn(70); |
452
|
|
|
|
453
|
|
|
$orderItem1->setOrder($this)->shouldBeCalled(); |
454
|
|
|
$orderItem2->setOrder($this)->shouldBeCalled(); |
455
|
|
|
$this->addItem($orderItem1); |
456
|
|
|
$this->addItem($orderItem2); |
457
|
|
|
|
458
|
|
|
$shippingAdjustment->setAdjustable($this)->shouldBeCalled(); |
459
|
|
|
$shippingTaxAdjustment->setAdjustable($this)->shouldBeCalled(); |
460
|
|
|
$this->addAdjustment($shippingAdjustment); |
461
|
|
|
$this->addAdjustment($shippingTaxAdjustment); |
462
|
|
|
|
463
|
|
|
$this->getTaxTotal()->shouldReturn(220); |
464
|
|
|
} |
465
|
|
|
|
466
|
|
|
function it_includes_a_non_neutral_tax_adjustments_in_shipping_total( |
467
|
|
|
AdjustmentInterface $shippingAdjustment, |
468
|
|
|
AdjustmentInterface $shippingTaxAdjustment |
469
|
|
|
): void { |
470
|
|
|
$shippingAdjustment->getType()->willReturn(AdjustmentInterface::SHIPPING_ADJUSTMENT); |
471
|
|
|
$shippingAdjustment->isNeutral()->willReturn(false); |
472
|
|
|
$shippingAdjustment->getAmount()->willReturn(1000); |
473
|
|
|
|
474
|
|
|
$shippingTaxAdjustment->getType()->willReturn(AdjustmentInterface::TAX_ADJUSTMENT); |
475
|
|
|
$shippingTaxAdjustment->isNeutral()->willReturn(false); |
476
|
|
|
$shippingTaxAdjustment->getAmount()->willReturn(70); |
477
|
|
|
|
478
|
|
|
$shippingAdjustment->setAdjustable($this)->shouldBeCalled(); |
479
|
|
|
$shippingTaxAdjustment->setAdjustable($this)->shouldBeCalled(); |
480
|
|
|
$this->addAdjustment($shippingAdjustment); |
481
|
|
|
$this->addAdjustment($shippingTaxAdjustment); |
482
|
|
|
|
483
|
|
|
$this->getShippingTotal()->shouldReturn(1070); |
484
|
|
|
} |
485
|
|
|
|
486
|
|
|
function it_returns_a_shipping_total_decreased_by_shipping_promotion( |
487
|
|
|
AdjustmentInterface $shippingAdjustment, |
488
|
|
|
AdjustmentInterface $shippingTaxAdjustment, |
489
|
|
|
AdjustmentInterface $shippingPromotionAdjustment |
490
|
|
|
): void { |
491
|
|
|
$shippingAdjustment->getType()->willReturn(AdjustmentInterface::SHIPPING_ADJUSTMENT); |
492
|
|
|
$shippingAdjustment->isNeutral()->willReturn(false); |
493
|
|
|
$shippingAdjustment->getAmount()->willReturn(1000); |
494
|
|
|
|
495
|
|
|
$shippingTaxAdjustment->getType()->willReturn(AdjustmentInterface::TAX_ADJUSTMENT); |
496
|
|
|
$shippingTaxAdjustment->isNeutral()->willReturn(false); |
497
|
|
|
$shippingTaxAdjustment->getAmount()->willReturn(70); |
498
|
|
|
|
499
|
|
|
$shippingPromotionAdjustment->getType()->willReturn(AdjustmentInterface::ORDER_SHIPPING_PROMOTION_ADJUSTMENT); |
500
|
|
|
$shippingPromotionAdjustment->isNeutral()->willReturn(false); |
501
|
|
|
$shippingPromotionAdjustment->getAmount()->willReturn(-100); |
502
|
|
|
|
503
|
|
|
$shippingAdjustment->setAdjustable($this)->shouldBeCalled(); |
504
|
|
|
$shippingTaxAdjustment->setAdjustable($this)->shouldBeCalled(); |
505
|
|
|
$shippingPromotionAdjustment->setAdjustable($this)->shouldBeCalled(); |
506
|
|
|
$this->addAdjustment($shippingAdjustment); |
507
|
|
|
$this->addAdjustment($shippingTaxAdjustment); |
508
|
|
|
$this->addAdjustment($shippingPromotionAdjustment); |
509
|
|
|
|
510
|
|
|
$this->getShippingTotal()->shouldReturn(970); |
511
|
|
|
} |
512
|
|
|
|
513
|
|
|
function it_does_not_include_neutral_tax_adjustments_in_shipping_total( |
514
|
|
|
AdjustmentInterface $shippingAdjustment, |
515
|
|
|
AdjustmentInterface $neutralShippingTaxAdjustment |
516
|
|
|
): void { |
517
|
|
|
$shippingAdjustment->getType()->willReturn(AdjustmentInterface::SHIPPING_ADJUSTMENT); |
518
|
|
|
$shippingAdjustment->isNeutral()->willReturn(false); |
519
|
|
|
$shippingAdjustment->getAmount()->willReturn(1000); |
520
|
|
|
|
521
|
|
|
$neutralShippingTaxAdjustment->getType()->willReturn(AdjustmentInterface::TAX_ADJUSTMENT); |
522
|
|
|
$neutralShippingTaxAdjustment->isNeutral()->willReturn(true); |
523
|
|
|
$neutralShippingTaxAdjustment->getAmount()->willReturn(70); |
524
|
|
|
|
525
|
|
|
$shippingAdjustment->setAdjustable($this)->shouldBeCalled(); |
526
|
|
|
$neutralShippingTaxAdjustment->setAdjustable($this)->shouldBeCalled(); |
527
|
|
|
$this->addAdjustment($shippingAdjustment); |
528
|
|
|
$this->addAdjustment($neutralShippingTaxAdjustment); |
529
|
|
|
|
530
|
|
|
$this->getShippingTotal()->shouldReturn(1000); |
531
|
|
|
} |
532
|
|
|
|
533
|
|
|
function it_returns_0_as_promotion_total_when_there_are_no_order_promotion_adjustments(): void |
534
|
|
|
{ |
535
|
|
|
$this->getOrderPromotionTotal()->shouldReturn(0); |
536
|
|
|
} |
537
|
|
|
|
538
|
|
|
function it_returns_a_sum_of_all_order_promotion_adjustments_applied_to_items_as_order_promotion_total( |
539
|
|
|
OrderItemInterface $orderItem1, |
540
|
|
|
OrderItemInterface $orderItem2 |
541
|
|
|
): void { |
542
|
|
|
$orderItem1->getTotal()->willReturn(500); |
543
|
|
|
$orderItem2->getTotal()->willReturn(300); |
544
|
|
|
|
545
|
|
|
$orderItem1->getAdjustmentsTotalRecursively(AdjustmentInterface::ORDER_PROMOTION_ADJUSTMENT)->willReturn(-400); |
546
|
|
|
$orderItem2->getAdjustmentsTotalRecursively(AdjustmentInterface::ORDER_PROMOTION_ADJUSTMENT)->willReturn(-600); |
547
|
|
|
|
548
|
|
|
$orderItem1->setOrder($this)->shouldBeCalled(); |
549
|
|
|
$orderItem2->setOrder($this)->shouldBeCalled(); |
550
|
|
|
$this->addItem($orderItem1); |
551
|
|
|
$this->addItem($orderItem2); |
552
|
|
|
|
553
|
|
|
$this->getOrderPromotionTotal()->shouldReturn(-1000); |
554
|
|
|
} |
555
|
|
|
|
556
|
|
|
function it_does_not_include_a_shipping_promotion_adjustment_in_order_promotion_total( |
557
|
|
|
AdjustmentInterface $shippingPromotionAdjustment, |
558
|
|
|
OrderItemInterface $orderItem1 |
559
|
|
|
): void { |
560
|
|
|
$orderItem1->getTotal()->willReturn(500); |
561
|
|
|
$orderItem1->getAdjustmentsTotalRecursively(AdjustmentInterface::ORDER_PROMOTION_ADJUSTMENT)->willReturn(-400); |
562
|
|
|
|
563
|
|
|
$shippingPromotionAdjustment->getType()->willReturn(AdjustmentInterface::ORDER_PROMOTION_ADJUSTMENT); |
564
|
|
|
$shippingPromotionAdjustment->isNeutral()->willReturn(false); |
565
|
|
|
$shippingPromotionAdjustment->getAmount()->willReturn(-100); |
566
|
|
|
|
567
|
|
|
$orderItem1->setOrder($this)->shouldBeCalled(); |
568
|
|
|
$this->addItem($orderItem1); |
569
|
|
|
|
570
|
|
|
$shippingPromotionAdjustment->setAdjustable($this)->shouldBeCalled(); |
571
|
|
|
$this->addAdjustment($shippingPromotionAdjustment); |
572
|
|
|
|
573
|
|
|
$this->getOrderPromotionTotal()->shouldReturn(-400); |
574
|
|
|
} |
575
|
|
|
|
576
|
|
|
function it_has_a_token_value(): void |
577
|
|
|
{ |
578
|
|
|
$this->setTokenValue('xyzasdxqwe'); |
579
|
|
|
|
580
|
|
|
$this->getTokenValue()->shouldReturn('xyzasdxqwe'); |
581
|
|
|
} |
582
|
|
|
|
583
|
|
|
function it_has_customer_ip(): void |
584
|
|
|
{ |
585
|
|
|
$this->setCustomerIp('172.16.254.1'); |
586
|
|
|
$this->getCustomerIp()->shouldReturn('172.16.254.1'); |
587
|
|
|
} |
588
|
|
|
} |
589
|
|
|
|