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\Resolver; |
13
|
|
|
|
14
|
|
|
use PhpSpec\ObjectBehavior; |
15
|
|
|
use Sylius\Component\Core\Model\ChannelInterface; |
16
|
|
|
use Sylius\Component\Core\Model\OrderInterface; |
17
|
|
|
use Sylius\Component\Core\Model\ShipmentInterface; |
18
|
|
|
use Sylius\Component\Core\Model\ShippingMethodInterface; |
19
|
|
|
use Sylius\Component\Shipping\Exception\UnresolvedDefaultShippingMethodException; |
20
|
|
|
use Sylius\Component\Shipping\Repository\ShippingMethodRepositoryInterface; |
21
|
|
|
use Sylius\Component\Shipping\Resolver\DefaultShippingMethodResolverInterface; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @author Mateusz Zalewski <[email protected]> |
25
|
|
|
*/ |
26
|
|
|
class DefaultShippingMethodResolverSpec extends ObjectBehavior |
27
|
|
|
{ |
28
|
|
|
function let(ShippingMethodRepositoryInterface $shippingMethodRepository) |
29
|
|
|
{ |
30
|
|
|
$this->beConstructedWith($shippingMethodRepository); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
function it_is_initializable() |
34
|
|
|
{ |
35
|
|
|
$this->shouldHaveType('Sylius\Component\Core\Resolver\DefaultShippingMethodResolver'); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
function it_implements_default_shipping_method_resolver_interface() |
39
|
|
|
{ |
40
|
|
|
$this->shouldImplement(DefaultShippingMethodResolverInterface::class); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
function it_returns_first_enabled_shipping_method_from_shipment_order_channel_as_default( |
44
|
|
|
ChannelInterface $channel, |
45
|
|
|
OrderInterface $order, |
46
|
|
|
ShipmentInterface $shipment, |
47
|
|
|
ShippingMethodInterface $firstShippingMethod, |
48
|
|
|
ShippingMethodInterface $secondShippingMethod, |
49
|
|
|
ShippingMethodInterface $thirdShippingMethod, |
50
|
|
|
ShippingMethodRepositoryInterface $shippingMethodRepository |
51
|
|
|
) { |
52
|
|
|
$shippingMethodRepository |
53
|
|
|
->findBy(['enabled' => true]) |
54
|
|
|
->willReturn([$firstShippingMethod, $secondShippingMethod, $thirdShippingMethod]) |
55
|
|
|
; |
56
|
|
|
|
57
|
|
|
$shipment->getOrder()->willReturn($order); |
58
|
|
|
$order->getChannel()->willReturn($channel); |
59
|
|
|
|
60
|
|
|
$channel->hasShippingMethod($firstShippingMethod)->willReturn(false); |
61
|
|
|
$channel->hasShippingMethod($secondShippingMethod)->willReturn(true); |
62
|
|
|
$channel->hasShippingMethod($thirdShippingMethod)->willReturn(true); |
63
|
|
|
|
64
|
|
|
$this->getDefaultShippingMethod($shipment)->shouldReturn($secondShippingMethod); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
function it_throws_exception_if_there_is_no_enabled_shipping_methods( |
68
|
|
|
ShippingMethodRepositoryInterface $shippingMethodRepository, |
69
|
|
|
ShipmentInterface $shipment |
70
|
|
|
) { |
71
|
|
|
$shippingMethodRepository->findBy(['enabled' => true])->willReturn([]); |
72
|
|
|
|
73
|
|
|
$this |
74
|
|
|
->shouldThrow(UnresolvedDefaultShippingMethodException::class) |
75
|
|
|
->during('getDefaultShippingMethod', [$shipment]) |
76
|
|
|
; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
function it_throws_exception_if_there_is_no_enabled_shipping_methods_for_channel( |
80
|
|
|
ChannelInterface $channel, |
81
|
|
|
OrderInterface $order, |
82
|
|
|
ShipmentInterface $shipment, |
83
|
|
|
ShippingMethodInterface $firstShippingMethod, |
84
|
|
|
ShippingMethodInterface $secondShippingMethod, |
85
|
|
|
ShippingMethodInterface $thirdShippingMethod, |
86
|
|
|
ShippingMethodRepositoryInterface $shippingMethodRepository |
87
|
|
|
) { |
88
|
|
|
$shippingMethodRepository |
89
|
|
|
->findBy(['enabled' => true]) |
90
|
|
|
->willReturn([$firstShippingMethod, $secondShippingMethod, $thirdShippingMethod]) |
91
|
|
|
; |
92
|
|
|
|
93
|
|
|
$shipment->getOrder()->willReturn($order); |
94
|
|
|
$order->getChannel()->willReturn($channel); |
95
|
|
|
|
96
|
|
|
$channel->hasShippingMethod($firstShippingMethod)->willReturn(false); |
97
|
|
|
$channel->hasShippingMethod($secondShippingMethod)->willReturn(false); |
98
|
|
|
$channel->hasShippingMethod($thirdShippingMethod)->willReturn(false); |
99
|
|
|
|
100
|
|
|
$this |
101
|
|
|
->shouldThrow(UnresolvedDefaultShippingMethodException::class) |
102
|
|
|
->during('getDefaultShippingMethod', [$shipment]) |
103
|
|
|
; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
function it_throws_exception_if_passed_shipment_is_not_core_shipment_object( |
107
|
|
|
\Sylius\Component\Shipping\Model\ShipmentInterface $shipment |
108
|
|
|
) { |
109
|
|
|
$this->shouldThrow(\InvalidArgumentException::class)->during('getDefaultShippingMethod', [$shipment]); |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|