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\OrderProcessing; |
13
|
|
|
|
14
|
|
|
use Doctrine\Common\Collections\Collection; |
15
|
|
|
use PhpSpec\ObjectBehavior; |
16
|
|
|
use Sylius\Component\Core\Model\OrderInterface; |
17
|
|
|
use Sylius\Component\Core\Model\OrderItemUnitInterface; |
18
|
|
|
use Sylius\Component\Core\Model\ShipmentInterface; |
19
|
|
|
use Sylius\Component\Core\OrderProcessing\OrderShipmentProcessorInterface; |
20
|
|
|
use Sylius\Component\Resource\Factory\FactoryInterface; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @mixin \Sylius\Component\Core\OrderProcessing\OrderShipmentProcessor |
24
|
|
|
* |
25
|
|
|
* @author Paweł Jędrzejewski <[email protected]> |
26
|
|
|
*/ |
27
|
|
|
class OrderShipmentProcessorSpec extends ObjectBehavior |
28
|
|
|
{ |
29
|
|
|
function let(FactoryInterface $shipmentFactory) |
30
|
|
|
{ |
31
|
|
|
$this->beConstructedWith($shipmentFactory); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
function it_is_initializable() |
35
|
|
|
{ |
36
|
|
|
$this->shouldHaveType('Sylius\Component\Core\OrderProcessing\OrderShipmentProcessor'); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
function it_implements_Sylius_shipment_factory_interface() |
40
|
|
|
{ |
41
|
|
|
$this->shouldImplement(OrderShipmentProcessorInterface::class); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
function it_creates_a_single_shipment_and_assigns_all_units_to_it( |
45
|
|
|
FactoryInterface $shipmentFactory, |
46
|
|
|
OrderInterface $order, |
47
|
|
|
ShipmentInterface $shipment, |
48
|
|
|
OrderItemUnitInterface $itemUnit1, |
49
|
|
|
OrderItemUnitInterface $itemUnit2 |
50
|
|
|
) { |
51
|
|
|
$shipmentFactory->createNew()->willReturn($shipment); |
52
|
|
|
|
53
|
|
|
$order->hasShipments()->willReturn(false); |
54
|
|
|
$order->getItemUnits()->willReturn([$itemUnit1, $itemUnit2]); |
55
|
|
|
|
56
|
|
|
$shipment->addUnit($itemUnit1)->shouldBeCalled(); |
57
|
|
|
$shipment->addUnit($itemUnit2)->shouldBeCalled(); |
58
|
|
|
|
59
|
|
|
$order->addShipment($shipment)->shouldBeCalled(); |
60
|
|
|
|
61
|
|
|
$this->processOrderShipment($order); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
function it_adds_new_item_units_to_existing_shipment( |
65
|
|
|
OrderInterface $order, |
66
|
|
|
ShipmentInterface $shipment, |
67
|
|
|
Collection $shipments, |
68
|
|
|
OrderItemUnitInterface $itemUnit, |
69
|
|
|
OrderItemUnitInterface $itemUnitWithoutShipment |
70
|
|
|
) { |
71
|
|
|
$shipments->first()->willReturn($shipment); |
72
|
|
|
|
73
|
|
|
$order->hasShipments()->willReturn(true); |
74
|
|
|
$order->getItemUnits()->willReturn([$itemUnit, $itemUnitWithoutShipment]); |
75
|
|
|
$order->getShipments()->willReturn($shipments); |
76
|
|
|
|
77
|
|
|
$itemUnit->getShipment()->willReturn($shipment); |
78
|
|
|
|
79
|
|
|
$shipment->addUnit($itemUnitWithoutShipment)->shouldBeCalled(); |
80
|
|
|
$shipment->addUnit($itemUnit)->shouldNotBeCalled(); |
81
|
|
|
|
82
|
|
|
$this->processOrderShipment($order); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|