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\Core\Repository\ShippingMethodRepositoryInterface; |
20
|
|
|
use Sylius\Component\Core\Resolver\DefaultShippingMethodResolver; |
21
|
|
|
use Sylius\Component\Shipping\Exception\UnresolvedDefaultShippingMethodException; |
22
|
|
|
use Sylius\Component\Shipping\Model\ShipmentInterface as BaseShipmentInterface; |
23
|
|
|
use Sylius\Component\Shipping\Resolver\DefaultShippingMethodResolverInterface; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @author Mateusz Zalewski <[email protected]> |
27
|
|
|
*/ |
28
|
|
|
final class DefaultShippingMethodResolverSpec extends ObjectBehavior |
29
|
|
|
{ |
30
|
|
|
function let(ShippingMethodRepositoryInterface $shippingMethodRepository) |
|
|
|
|
31
|
|
|
{ |
32
|
|
|
$this->beConstructedWith($shippingMethodRepository); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
function it_is_initializable() |
36
|
|
|
{ |
37
|
|
|
$this->shouldHaveType(DefaultShippingMethodResolver::class); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
function it_implements_a_default_shipping_method_resolver_interface() |
41
|
|
|
{ |
42
|
|
|
$this->shouldImplement(DefaultShippingMethodResolverInterface::class); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
function it_returns_first_enabled_shipping_method_from_shipment_order_channel_as_default( |
46
|
|
|
ChannelInterface $channel, |
47
|
|
|
OrderInterface $order, |
48
|
|
|
ShipmentInterface $shipment, |
49
|
|
|
ShippingMethodInterface $firstShippingMethod, |
50
|
|
|
ShippingMethodInterface $secondShippingMethod, |
51
|
|
|
ShippingMethodRepositoryInterface $shippingMethodRepository |
|
|
|
|
52
|
|
|
) { |
53
|
|
|
$shipment->getOrder()->willReturn($order); |
54
|
|
|
$order->getChannel()->willReturn($channel); |
55
|
|
|
|
56
|
|
|
$shippingMethodRepository |
57
|
|
|
->findEnabledForChannel($channel) |
58
|
|
|
->willReturn([$firstShippingMethod, $secondShippingMethod]) |
59
|
|
|
; |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
$this->getDefaultShippingMethod($shipment)->shouldReturn($firstShippingMethod); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
function it_throws_an_exception_if_there_is_no_enabled_shipping_methods( |
66
|
|
|
ShippingMethodRepositoryInterface $shippingMethodRepository, |
|
|
|
|
67
|
|
|
ShipmentInterface $shipment, |
68
|
|
|
ChannelInterface $channel, |
69
|
|
|
OrderInterface $order |
70
|
|
|
) { |
71
|
|
|
|
72
|
|
|
$shipment->getOrder()->willReturn($order); |
73
|
|
|
$order->getChannel()->willReturn($channel); |
74
|
|
|
|
75
|
|
|
$shippingMethodRepository |
76
|
|
|
->findEnabledForChannel($channel)->willReturn([]); |
77
|
|
|
|
78
|
|
|
$this |
79
|
|
|
->shouldThrow(UnresolvedDefaultShippingMethodException::class) |
80
|
|
|
->during('getDefaultShippingMethod', [$shipment]) |
81
|
|
|
; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
function it_throws_an_exception_if_passed_shipment_is_not_core_shipment_object(BaseShipmentInterface $shipment) |
85
|
|
|
{ |
86
|
|
|
$this->shouldThrow(\InvalidArgumentException::class)->during('getDefaultShippingMethod', [$shipment]); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.