Completed
Push — 1.0-phpstan ( ddfe6c )
by Kamil
23:36
created

OrderItemSpec::it_adds_adjustments_properly()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
nc 1
cc 1
eloc 6
nop 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\Model;
15
16
use Doctrine\Common\Collections\ArrayCollection;
17
use Doctrine\Common\Collections\Collection;
18
use PhpSpec\ObjectBehavior;
19
use Sylius\Component\Order\Model\AdjustableInterface;
20
use Sylius\Component\Order\Model\AdjustmentInterface;
21
use Sylius\Component\Order\Model\OrderInterface;
22
use Sylius\Component\Order\Model\OrderItemInterface;
23
use Sylius\Component\Order\Model\OrderItemUnitInterface;
24
25
final class OrderItemSpec extends ObjectBehavior
26
{
27
    function it_implements_an_order_item_interface(): void
28
    {
29
        $this->shouldImplement(OrderItemInterface::class);
30
    }
31
32
    function it_implements_an_adjustable_interface(): void
33
    {
34
        $this->shouldImplement(AdjustableInterface::class);
35
    }
36
37
    function it_has_no_id_by_default(): void
38
    {
39
        $this->getId()->shouldReturn(null);
40
    }
41
42
    function it_does_not_belong_to_an_order_by_default(): void
43
    {
44
        $this->getOrder()->shouldReturn(null);
45
    }
46
47
    function it_allows_assigning_itself_to_an_order(OrderInterface $order): void
48
    {
49
        $order->hasItem($this)->willReturn(false);
50
        $order->addItem($this)->shouldBeCalled();
51
52
        $this->setOrder($order);
53
        $this->getOrder()->shouldReturn($order);
54
    }
55
56
    function it_allows_detaching_itself_from_an_order(OrderInterface $order): void
57
    {
58
        $order->hasItem($this)->willReturn(false);
59
        $order->addItem($this)->shouldBeCalled();
60
61
        $this->setOrder($order);
62
        $this->getOrder()->shouldReturn($order);
63
64
        $order->hasItem($this)->willReturn(true);
65
        $order->removeItem($this)->shouldBeCalled();
66
67
        $this->setOrder(null);
68
        $this->getOrder()->shouldReturn(null);
69
    }
70
71
    function it_does_not_set_order_if_it_is_already_set(OrderInterface $order): void
72
    {
73
        $order->hasItem($this)->willReturn(false);
74
        $order->addItem($this)->shouldBeCalled();
75
        $this->setOrder($order);
76
        $this->getOrder()->shouldReturn($order);
77
78
        $order->hasItem($this)->willReturn(true);
79
        $this->setOrder($order);
80
        $this->getOrder()->shouldReturn($order);
81
    }
82
83
    function it_has_quantity_equal_to_0_by_default(): void
84
    {
85
        $this->getQuantity()->shouldReturn(0);
86
    }
87
88
    function it_has_unit_price_equal_to_0_by_default(): void
89
    {
90
        $this->getUnitPrice()->shouldReturn(0);
91
    }
92
93
    function its_unit_price_should_accept_only_integer(): void
94
    {
95
        $this->setUnitPrice(4498);
96
        $this->getUnitPrice()->shouldReturn(4498);
97
    }
98
99
    function it_has_total_equal_to_0_by_default(): void
100
    {
101
        $this->getTotal()->shouldReturn(0);
102
    }
103
104
    function it_initializes_adjustments_collection_by_default(): void
105
    {
106
        $this->getAdjustments()->shouldHaveType(Collection::class);
107
    }
108
109
    function it_returns_adjustments_recursively(
110
        AdjustmentInterface $itemAdjustment,
111
        AdjustmentInterface $unitAdjustment1,
112
        AdjustmentInterface $unitAdjustment2,
113
        OrderItemUnitInterface $unit1,
114
        OrderItemUnitInterface $unit2
115
    ): void {
116
        $unit1->getOrderItem()->willReturn($this);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...del\OrderItemInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
117
        $unit1->getTotal()->willReturn(100);
118
        $unit1->getAdjustments(null)->willReturn(new ArrayCollection([$unitAdjustment1->getWrappedObject()]));
0 ignored issues
show
Bug introduced by
The method getWrappedObject() does not seem to exist on object<Sylius\Component\...el\AdjustmentInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
119
120
        $unit2->getOrderItem()->willReturn($this);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...del\OrderItemInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
121
        $unit2->getTotal()->willReturn(100);
122
        $unit2->getAdjustments(null)->willReturn(new ArrayCollection([$unitAdjustment2->getWrappedObject()]));
0 ignored issues
show
Bug introduced by
The method getWrappedObject() does not seem to exist on object<Sylius\Component\...el\AdjustmentInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
123
124
        $this->addUnit($unit1);
125
        $this->addUnit($unit2);
126
127
        $itemAdjustment->setAdjustable($this)->shouldBeCalled();
128
        $itemAdjustment->isNeutral()->willReturn(true);
129
130
        $this->addAdjustment($itemAdjustment);
131
132
        $this->getAdjustmentsRecursively()->shouldIterateAs([$itemAdjustment, $unitAdjustment1, $unitAdjustment2]);
133
    }
134
135
    function it_adds_and_removes_units(OrderItemUnitInterface $orderItemUnit1, OrderItemUnitInterface $orderItemUnit2): void
136
    {
137
        $orderItemUnit1->getOrderItem()->willReturn($this->getWrappedObject());
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...del\OrderItemInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
138
        $orderItemUnit1->getTotal()->willReturn(0);
139
        $orderItemUnit2->getOrderItem()->willReturn($this->getWrappedObject());
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...del\OrderItemInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
140
        $orderItemUnit2->getTotal()->willReturn(0);
141
        $this->getUnits()->shouldHaveType(Collection::class);
142
143
        $this->addUnit($orderItemUnit1);
144
        $this->addUnit($orderItemUnit2);
145
        $this->hasUnit($orderItemUnit1)->shouldReturn(true);
146
        $this->hasUnit($orderItemUnit2)->shouldReturn(true);
147
148
        $this->removeUnit($orderItemUnit1);
149
        $this->hasUnit($orderItemUnit1)->shouldReturn(false);
150
        $this->hasUnit($orderItemUnit2)->shouldReturn(true);
151
    }
152
153
    function it_adds_only_unit_that_is_assigned_to_it(OrderItemUnitInterface $orderItemUnit1, OrderItemInterface $orderItem): void
154
    {
155
        $orderItemUnit1->getOrderItem()->willReturn($orderItem);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...del\OrderItemInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
156
        $this
157
            ->shouldThrow(new \LogicException('This order item unit is assigned to a different order item.'))
158
            ->duringAddUnit($orderItemUnit1)
159
        ;
160
    }
161
162
    function it_recalculates_units_total_on_unit_price_change(
163
        OrderItemUnitInterface $orderItemUnit1,
164
        OrderItemUnitInterface $orderItemUnit2
165
    ): void {
166
        $orderItemUnit1->getOrderItem()->willReturn($this->getWrappedObject());
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...del\OrderItemInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
167
        $orderItemUnit1->getTotal()->willReturn(0, 100);
168
        $orderItemUnit2->getOrderItem()->willReturn($this->getWrappedObject());
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...del\OrderItemInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
169
        $orderItemUnit2->getTotal()->willReturn(0, 100);
170
171
        $this->addUnit($orderItemUnit1);
172
        $this->addUnit($orderItemUnit2);
173
174
        $this->setUnitPrice(100);
175
    }
176
177
    function it_adds_adjustments_properly(AdjustmentInterface $adjustment): void
178
    {
179
        $adjustment->isNeutral()->willReturn(true);
180
        $adjustment->setAdjustable($this)->shouldBeCalled();
181
182
        $this->hasAdjustment($adjustment)->shouldReturn(false);
183
        $this->addAdjustment($adjustment);
184
        $this->hasAdjustment($adjustment)->shouldReturn(true);
185
    }
186
187
    function it_removes_adjustments_properly(AdjustmentInterface $adjustment): void
188
    {
189
        $adjustment->isNeutral()->willReturn(true);
190
        $adjustment->setAdjustable($this)->shouldBeCalled();
191
192
        $this->hasAdjustment($adjustment)->shouldReturn(false);
193
        $this->addAdjustment($adjustment);
194
        $this->hasAdjustment($adjustment)->shouldReturn(true);
195
196
        $adjustment->setAdjustable(null)->shouldBeCalled();
197
        $adjustment->isLocked()->willReturn(false);
198
199
        $this->removeAdjustment($adjustment);
200
        $this->hasAdjustment($adjustment)->shouldReturn(false);
201
    }
202
203
    function it_has_correct_total_based_on_unit_items(
204
        OrderItemUnitInterface $orderItemUnit1,
205
        OrderItemUnitInterface $orderItemUnit2
206
    ): void {
207
        $orderItemUnit1->getOrderItem()->willReturn($this->getWrappedObject());
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...del\OrderItemInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
208
        $orderItemUnit1->getTotal()->willReturn(1499);
209
        $orderItemUnit2->getOrderItem()->willReturn($this->getWrappedObject());
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...del\OrderItemInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
210
        $orderItemUnit2->getTotal()->willReturn(1499);
211
212
        $this->addUnit($orderItemUnit1);
213
        $this->addUnit($orderItemUnit2);
214
        $this->getTotal()->shouldReturn(2998);
215
    }
216
217
    function it_has_correct_total_after_unit_item_remove(
218
        OrderItemUnitInterface $orderItemUnit1,
219
        OrderItemUnitInterface $orderItemUnit2
220
    ): void {
221
        $orderItemUnit1->getOrderItem()->willReturn($this->getWrappedObject());
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...del\OrderItemInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
222
        $orderItemUnit1->getTotal()->willReturn(2000);
223
        $orderItemUnit2->getOrderItem()->willReturn($this->getWrappedObject());
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...del\OrderItemInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
224
        $orderItemUnit2->getTotal()->willReturn(1000);
225
226
        $this->addUnit($orderItemUnit1);
227
        $this->addUnit($orderItemUnit2);
228
        $this->getTotal()->shouldReturn(3000);
229
230
        $this->removeUnit($orderItemUnit2);
231
        $this->getTotal()->shouldReturn(2000);
232
    }
233
234
    function it_has_correct_total_after_negative_adjustment_add(
235
        AdjustmentInterface $adjustment,
236
        OrderItemUnitInterface $orderItemUnit1,
237
        OrderItemUnitInterface $orderItemUnit2
238
    ): void {
239
        $orderItemUnit1->getOrderItem()->willReturn($this->getWrappedObject());
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...del\OrderItemInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
240
        $orderItemUnit1->getTotal()->willReturn(1499);
241
        $orderItemUnit2->getOrderItem()->willReturn($this->getWrappedObject());
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...del\OrderItemInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
242
        $orderItemUnit2->getTotal()->willReturn(1499);
243
244
        $adjustment->isNeutral()->willReturn(false);
245
        $adjustment->getAmount()->willReturn(-1000);
246
        $adjustment->setAdjustable($this)->shouldBeCalled();
247
248
        $this->addUnit($orderItemUnit1);
249
        $this->addUnit($orderItemUnit2);
250
        $this->addAdjustment($adjustment);
251
        $this->getTotal()->shouldReturn(1998);
252
    }
253
254
    function it_has_correct_total_after_adjustment_add_and_remove(AdjustmentInterface $adjustment): void
255
    {
256
        $adjustment->isNeutral()->willReturn(false);
257
        $adjustment->getAmount()->willReturn(200);
258
        $adjustment->setAdjustable($this)->shouldBeCalled();
259
260
        $this->addAdjustment($adjustment);
261
        $this->getTotal()->shouldReturn(200);
262
263
        $adjustment->setAdjustable(null)->shouldBeCalled();
264
        $adjustment->isLocked()->willReturn(false);
265
266
        $this->removeAdjustment($adjustment);
267
        $this->getTotal()->shouldReturn(0);
268
    }
269
270
    function it_has_correct_total_after_neutral_adjustment_add_and_remove(AdjustmentInterface $adjustment): void
271
    {
272
        $adjustment->isNeutral()->willReturn(true);
273
        $adjustment->getAmount()->willReturn(200);
274
        $adjustment->setAdjustable($this)->shouldBeCalled();
275
276
        $this->addAdjustment($adjustment);
277
        $this->getTotal()->shouldReturn(0);
278
279
        $adjustment->setAdjustable(null)->shouldBeCalled();
280
        $adjustment->isLocked()->willReturn(false);
281
282
        $this->removeAdjustment($adjustment);
283
        $this->getTotal()->shouldReturn(0);
284
    }
285
286
    function it_has_0_total_when_adjustment_decreases_total_under_0(
287
        AdjustmentInterface $adjustment,
288
        OrderItemUnitInterface $orderItemUnit1
289
    ): void {
290
        $orderItemUnit1->getOrderItem()->willReturn($this->getWrappedObject());
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...del\OrderItemInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
291
        $orderItemUnit1->getTotal()->willReturn(1499);
292
293
        $adjustment->isNeutral()->willReturn(false);
294
        $adjustment->getAmount()->willReturn(-2000);
295
        $adjustment->setAdjustable($this)->shouldBeCalled();
296
297
        $this->addUnit($orderItemUnit1);
298
        $this->addAdjustment($adjustment);
299
        $this->getTotal()->shouldReturn(0);
300
    }
301
302
    function it_has_correct_total_after_unit_price_change(
303
        OrderItemUnitInterface $orderItemUnit1,
304
        OrderItemUnitInterface $orderItemUnit2
305
    ): void {
306
        $orderItemUnit1->getOrderItem()->willReturn($this->getWrappedObject());
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...del\OrderItemInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
307
        $orderItemUnit1->getTotal()->willReturn(0, 100);
308
        $orderItemUnit2->getOrderItem()->willReturn($this->getWrappedObject());
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...del\OrderItemInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
309
        $orderItemUnit2->getTotal()->willReturn(0, 100);
310
311
        $this->addUnit($orderItemUnit1);
312
        $this->addUnit($orderItemUnit2);
313
314
        $this->setUnitPrice(100);
315
        $this->getTotal()->shouldReturn(200);
316
    }
317
318
    function it_has_correct_total_after_order_item_unit_total_change(
319
        OrderItemUnitInterface $orderItemUnit1,
320
        OrderItemUnitInterface $orderItemUnit2
321
    ): void {
322
        $orderItemUnit1->getOrderItem()->willReturn($this->getWrappedObject());
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...del\OrderItemInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
323
        $orderItemUnit1->getTotal()->willReturn(0);
324
        $orderItemUnit2->getOrderItem()->willReturn($this->getWrappedObject());
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...del\OrderItemInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
325
        $orderItemUnit2->getTotal()->willReturn(0, 100);
326
327
        $this->addUnit($orderItemUnit1);
328
        $this->addUnit($orderItemUnit2);
329
330
        $this->getTotal()->shouldReturn(0);
331
        $this->recalculateUnitsTotal();
332
        $this->getTotal()->shouldReturn(100);
333
    }
334
335
    function it_has_correct_total_after_adjustment_amount_change(
336
        AdjustmentInterface $adjustment1,
337
        AdjustmentInterface $adjustment2
338
    ): void {
339
        $adjustment1->getAmount()->willReturn(100);
340
        $adjustment1->isNeutral()->willReturn(false);
341
        $adjustment1->setAdjustable($this)->shouldBeCalled();
342
        $adjustment2->getAmount()->willReturn(500, 300);
343
        $adjustment2->isNeutral()->willReturn(false);
344
        $adjustment2->setAdjustable($this)->shouldBeCalled();
345
346
        $this->addAdjustment($adjustment1);
347
        $this->addAdjustment($adjustment2);
348
349
        $this->getTotal()->shouldReturn(600);
350
        $this->recalculateAdjustmentsTotal();
351
        $this->getTotal()->shouldReturn(400);
352
    }
353
354
    function it_returns_correct_adjustments_total(
355
        AdjustmentInterface $adjustment1,
356
        AdjustmentInterface $adjustment2
357
    ): void {
358
        $adjustment1->getAmount()->willReturn(100);
359
        $adjustment1->isNeutral()->willReturn(false);
360
        $adjustment1->setAdjustable($this)->shouldBeCalled();
361
        $adjustment2->getAmount()->willReturn(500);
362
        $adjustment2->isNeutral()->willReturn(false);
363
        $adjustment2->setAdjustable($this)->shouldBeCalled();
364
365
        $this->addAdjustment($adjustment1);
366
        $this->addAdjustment($adjustment2);
367
368
        $this->getAdjustmentsTotal()->shouldReturn(600);
369
    }
370
371
    function it_returns_correct_adjustments_total_by_type(
372
        AdjustmentInterface $adjustment1,
373
        AdjustmentInterface $adjustment2,
374
        AdjustmentInterface $adjustment3
375
    ): void {
376
        $adjustment1->getType()->willReturn('tax');
377
        $adjustment1->getAmount()->willReturn(200);
378
        $adjustment1->isNeutral()->willReturn(false);
379
        $adjustment1->setAdjustable($this)->shouldBeCalled();
380
        $adjustment2->getType()->willReturn('tax');
381
        $adjustment2->getAmount()->willReturn(-50);
382
        $adjustment2->isNeutral()->willReturn(false);
383
        $adjustment2->setAdjustable($this)->shouldBeCalled();
384
385
        $adjustment3->getType()->willReturn('promotion');
386
        $adjustment3->getAmount()->willReturn(-1000);
387
        $adjustment3->isNeutral()->willReturn(false);
388
        $adjustment3->setAdjustable($this)->shouldBeCalled();
389
390
        $this->addAdjustment($adjustment1);
391
        $this->addAdjustment($adjustment2);
392
        $this->addAdjustment($adjustment3);
393
394
        $this->getAdjustmentsTotal('tax')->shouldReturn(150);
395
        $this->getAdjustmentsTotal('promotion')->shouldReturn(-1000);
396
        $this->getAdjustmentsTotal('any')->shouldReturn(0);
397
    }
398
399
    function it_returns_correct_adjustments_total_recursively(
400
        AdjustmentInterface $adjustment1,
401
        AdjustmentInterface $taxAdjustment1,
402
        AdjustmentInterface $taxAdjustment2,
403
        OrderItemUnitInterface $orderItemUnit1,
404
        OrderItemUnitInterface $orderItemUnit2
405
    ): void {
406
        $adjustment1->getAmount()->willReturn(200);
407
        $adjustment1->isNeutral()->willReturn(false);
408
        $adjustment1->setAdjustable($this)->shouldBeCalled();
409
410
        $taxAdjustment1->getAmount()->willReturn(150);
411
        $taxAdjustment1->isNeutral()->willReturn(false);
412
        $taxAdjustment2->getAmount()->willReturn(100);
413
        $taxAdjustment2->isNeutral()->willReturn(false);
414
415
        $orderItemUnit1->getOrderItem()->willReturn($this->getWrappedObject());
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...del\OrderItemInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
416
        $orderItemUnit1->getTotal()->willReturn(500);
417
        $orderItemUnit1->getAdjustments(null)->willReturn(new ArrayCollection([$taxAdjustment1->getWrappedObject()]));
0 ignored issues
show
Bug introduced by
The method getWrappedObject() does not seem to exist on object<Sylius\Component\...el\AdjustmentInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
418
        $orderItemUnit2->getOrderItem()->willReturn($this->getWrappedObject());
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...del\OrderItemInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
419
        $orderItemUnit2->getTotal()->willReturn(300);
420
        $orderItemUnit2->getAdjustments(null)->willReturn(new ArrayCollection([$taxAdjustment2->getWrappedObject()]));
0 ignored issues
show
Bug introduced by
The method getWrappedObject() does not seem to exist on object<Sylius\Component\...el\AdjustmentInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
421
422
        $this->addAdjustment($adjustment1);
423
        $this->addUnit($orderItemUnit1);
424
        $this->addUnit($orderItemUnit2);
425
426
        $this->getAdjustmentsTotalRecursively()->shouldReturn(450);
427
    }
428
429
    function it_returns_correct_adjustments_total_by_type_recursively(
430
        AdjustmentInterface $adjustment1,
431
        AdjustmentInterface $promotionAdjustment,
432
        AdjustmentInterface $taxAdjustment1,
433
        AdjustmentInterface $taxAdjustment2,
434
        OrderItemUnitInterface $orderItemUnit1,
435
        OrderItemUnitInterface $orderItemUnit2
436
    ): void {
437
        $adjustment1->getType()->willReturn('tax');
438
        $adjustment1->getAmount()->willReturn(200);
439
        $adjustment1->isNeutral()->willReturn(false);
440
        $adjustment1->setAdjustable($this)->shouldBeCalled();
441
442
        $promotionAdjustment->getAmount()->willReturn(30);
443
        $promotionAdjustment->isNeutral()->willReturn(false);
444
        $taxAdjustment1->getAmount()->willReturn(150);
445
        $taxAdjustment1->isNeutral()->willReturn(false);
446
        $taxAdjustment2->getAmount()->willReturn(100);
447
        $taxAdjustment2->isNeutral()->willReturn(false);
448
449
        $orderItemUnit1->getOrderItem()->willReturn($this->getWrappedObject());
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...del\OrderItemInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
450
        $orderItemUnit1->getTotal()->willReturn(500);
451
        $orderItemUnit1->getAdjustments('tax')->willReturn(new ArrayCollection([$taxAdjustment1->getWrappedObject()]));
0 ignored issues
show
Bug introduced by
The method getWrappedObject() does not seem to exist on object<Sylius\Component\...el\AdjustmentInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
452
        $orderItemUnit1->getAdjustments('promotion')->willReturn(new ArrayCollection([$promotionAdjustment->getWrappedObject()]));
0 ignored issues
show
Bug introduced by
The method getWrappedObject() does not seem to exist on object<Sylius\Component\...el\AdjustmentInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
453
        $orderItemUnit2->getOrderItem()->willReturn($this->getWrappedObject());
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...del\OrderItemInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
454
        $orderItemUnit2->getTotal()->willReturn(300);
455
        $orderItemUnit2->getAdjustments('tax')->willReturn(new ArrayCollection([$taxAdjustment2->getWrappedObject()]));
0 ignored issues
show
Bug introduced by
The method getWrappedObject() does not seem to exist on object<Sylius\Component\...el\AdjustmentInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
456
        $orderItemUnit2->getAdjustments('promotion')->willReturn(new ArrayCollection());
457
458
        $this->addAdjustment($adjustment1);
459
        $this->addUnit($orderItemUnit1);
460
        $this->addUnit($orderItemUnit2);
461
462
        $this->getAdjustmentsTotalRecursively('tax')->shouldReturn(450);
463
        $this->getAdjustmentsTotalRecursively('promotion')->shouldReturn(30);
464
    }
465
466
    function it_can_be_immutable(): void
467
    {
468
        $this->setImmutable(true);
469
        $this->isImmutable()->shouldReturn(true);
470
    }
471
}
472