|
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\StateResolver; |
|
15
|
|
|
|
|
16
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
17
|
|
|
use PhpSpec\ObjectBehavior; |
|
18
|
|
|
use SM\Factory\FactoryInterface; |
|
19
|
|
|
use SM\StateMachine\StateMachineInterface; |
|
20
|
|
|
use Sylius\Component\Core\Model\OrderInterface; |
|
21
|
|
|
use Sylius\Component\Core\Model\ShipmentInterface; |
|
22
|
|
|
use Sylius\Component\Core\OrderShippingStates; |
|
23
|
|
|
use Sylius\Component\Core\OrderShippingTransitions; |
|
24
|
|
|
use Sylius\Component\Order\StateResolver\StateResolverInterface; |
|
25
|
|
|
|
|
26
|
|
|
final class OrderShippingStateResolverSpec extends ObjectBehavior |
|
27
|
|
|
{ |
|
28
|
|
|
function let(FactoryInterface $stateMachineFactory): void |
|
29
|
|
|
{ |
|
30
|
|
|
$this->beConstructedWith($stateMachineFactory); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
function it_implements_an_order_state_resolver_interface(): void |
|
34
|
|
|
{ |
|
35
|
|
|
$this->shouldImplement(StateResolverInterface::class); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
function it_marks_an_order_as_shipped_if_all_shipments_delivered( |
|
39
|
|
|
FactoryInterface $stateMachineFactory, |
|
40
|
|
|
OrderInterface $order, |
|
41
|
|
|
ShipmentInterface $shipment1, |
|
42
|
|
|
ShipmentInterface $shipment2, |
|
43
|
|
|
StateMachineInterface $orderStateMachine |
|
44
|
|
|
): void { |
|
45
|
|
|
$shipments = new ArrayCollection(); |
|
46
|
|
|
$shipments->add($shipment1->getWrappedObject()); |
|
47
|
|
|
$shipments->add($shipment2->getWrappedObject()); |
|
48
|
|
|
|
|
49
|
|
|
$order->getShipments()->willReturn($shipments); |
|
50
|
|
|
$order->getShippingState()->willReturn(OrderShippingStates::STATE_READY); |
|
51
|
|
|
$stateMachineFactory->get($order, OrderShippingTransitions::GRAPH)->willReturn($orderStateMachine); |
|
52
|
|
|
|
|
53
|
|
|
$shipment1->getState()->willReturn(ShipmentInterface::STATE_SHIPPED); |
|
54
|
|
|
$shipment2->getState()->willReturn(ShipmentInterface::STATE_SHIPPED); |
|
55
|
|
|
|
|
56
|
|
|
$orderStateMachine->apply(OrderShippingTransitions::TRANSITION_SHIP)->shouldBeCalled(); |
|
57
|
|
|
|
|
58
|
|
|
$this->resolve($order); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
function it_marks_an_order_as_shipped_if_there_are_no_shipments_to_deliver( |
|
62
|
|
|
FactoryInterface $stateMachineFactory, |
|
63
|
|
|
OrderInterface $order, |
|
64
|
|
|
StateMachineInterface $orderStateMachine |
|
65
|
|
|
): void { |
|
66
|
|
|
$order->getShipments()->willReturn(new ArrayCollection()); |
|
67
|
|
|
$order->getShippingState()->willReturn(OrderShippingStates::STATE_READY); |
|
68
|
|
|
$stateMachineFactory->get($order, OrderShippingTransitions::GRAPH)->willReturn($orderStateMachine); |
|
69
|
|
|
|
|
70
|
|
|
$orderStateMachine->apply(OrderShippingTransitions::TRANSITION_SHIP)->shouldBeCalled(); |
|
71
|
|
|
|
|
72
|
|
|
$this->resolve($order); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
function it_marks_an_order_as_partially_shipped_if_some_shipments_are_delivered( |
|
76
|
|
|
FactoryInterface $stateMachineFactory, |
|
77
|
|
|
OrderInterface $order, |
|
78
|
|
|
ShipmentInterface $shipment1, |
|
79
|
|
|
ShipmentInterface $shipment2, |
|
80
|
|
|
StateMachineInterface $orderStateMachine |
|
81
|
|
|
): void { |
|
82
|
|
|
$shipments = new ArrayCollection(); |
|
83
|
|
|
$shipments->add($shipment1->getWrappedObject()); |
|
84
|
|
|
$shipments->add($shipment2->getWrappedObject()); |
|
85
|
|
|
|
|
86
|
|
|
$order->getShipments()->willReturn($shipments); |
|
87
|
|
|
$order->getShippingState()->willReturn(OrderShippingStates::STATE_READY); |
|
88
|
|
|
$stateMachineFactory->get($order, OrderShippingTransitions::GRAPH)->willReturn($orderStateMachine); |
|
89
|
|
|
|
|
90
|
|
|
$shipment1->getState()->willReturn(ShipmentInterface::STATE_SHIPPED); |
|
91
|
|
|
$shipment2->getState()->willReturn(ShipmentInterface::STATE_CANCELLED); |
|
92
|
|
|
|
|
93
|
|
|
$orderStateMachine->apply(OrderShippingTransitions::TRANSITION_PARTIALLY_SHIP)->shouldBeCalled(); |
|
94
|
|
|
|
|
95
|
|
|
$this->resolve($order); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
function it_does_not_mark_an_order_if_it_is_already_in_this_shipping_state( |
|
99
|
|
|
FactoryInterface $stateMachineFactory, |
|
100
|
|
|
OrderInterface $order, |
|
101
|
|
|
ShipmentInterface $shipment1, |
|
102
|
|
|
ShipmentInterface $shipment2, |
|
103
|
|
|
StateMachineInterface $orderStateMachine |
|
104
|
|
|
): void { |
|
105
|
|
|
$shipments = new ArrayCollection(); |
|
106
|
|
|
$shipments->add($shipment1->getWrappedObject()); |
|
107
|
|
|
$shipments->add($shipment2->getWrappedObject()); |
|
108
|
|
|
|
|
109
|
|
|
$order->getShipments()->willReturn($shipments); |
|
110
|
|
|
$order->getShippingState()->willReturn(OrderShippingStates::STATE_SHIPPED); |
|
111
|
|
|
$stateMachineFactory->get($order, OrderShippingTransitions::GRAPH)->willReturn($orderStateMachine); |
|
112
|
|
|
|
|
113
|
|
|
$shipment1->getState()->willReturn(ShipmentInterface::STATE_SHIPPED); |
|
114
|
|
|
$shipment2->getState()->willReturn(ShipmentInterface::STATE_SHIPPED); |
|
115
|
|
|
|
|
116
|
|
|
$orderStateMachine->apply(OrderShippingTransitions::TRANSITION_SHIP)->shouldNotBeCalled(); |
|
117
|
|
|
|
|
118
|
|
|
$this->resolve($order); |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|