Completed
Push — master ( 9f1cb3...cf412b )
by Kamil
24:31
created

DefaultShippingMethodResolverSpec   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 5
dl 0
loc 61
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 4 1
A it_is_initializable() 0 4 1
A it_implements_a_default_shipping_method_resolver_interface() 0 4 1
A it_returns_first_enabled_shipping_method_from_shipment_order_channel_as_default() 0 19 1
A it_throws_an_exception_if_there_is_no_enabled_shipping_methods() 0 18 1
A it_throws_an_exception_if_passed_shipment_is_not_core_shipment_object() 0 4 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
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)
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $shippingMethodRepository exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
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
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $shippingMethodRepository exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
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,
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $shippingMethodRepository exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
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