Completed
Push — master ( b31cd6...60f5be )
by Kamil
43:45
created

DefaultShippingMethodResolverSpec   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 2
Bugs 2 Features 0
Metric Value
wmc 5
c 2
b 2
f 0
lcom 0
cbo 3
dl 0
loc 40
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 4 1
A it_is_initializable() 0 4 1
A it_implements_default_shipping_method_resolver_interface() 0 4 1
A it_returns_first_enabled_shipping_method_as_default() 0 10 1
A it_throws_exception_if_there_is_no_enabled_shipping_methods() 0 11 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\Shipping\Resolver;
13
14
use PhpSpec\ObjectBehavior;
15
use Sylius\Component\Shipping\Exception\UnresolvedDefaultShippingMethodException;
16
use Sylius\Component\Shipping\Model\ShipmentInterface;
17
use Sylius\Component\Shipping\Model\ShippingMethodInterface;
18
use Sylius\Component\Shipping\Repository\ShippingMethodRepositoryInterface;
19
use Sylius\Component\Shipping\Resolver\DefaultShippingMethodResolverInterface;
20
21
/**
22
 * @author Mateusz Zalewski <[email protected]>
23
 */
24
class DefaultShippingMethodResolverSpec extends ObjectBehavior
25
{
26
    function let(ShippingMethodRepositoryInterface $shippingMethodRepository)
27
    {
28
        $this->beConstructedWith($shippingMethodRepository);
29
    }
30
31
    function it_is_initializable()
32
    {
33
        $this->shouldHaveType('Sylius\Component\Shipping\Resolver\DefaultShippingMethodResolver');
34
    }
35
36
    function it_implements_default_shipping_method_resolver_interface()
37
    {
38
        $this->shouldImplement(DefaultShippingMethodResolverInterface::class);
39
    }
40
41
    function it_returns_first_enabled_shipping_method_as_default(
42
        ShippingMethodInterface $firstShippingMethod,
43
        ShippingMethodInterface $secondShippingMethod,
44
        ShippingMethodRepositoryInterface $shippingMethodRepository,
45
        ShipmentInterface $shipment
46
    ) {
47
        $shippingMethodRepository->findBy(['enabled' => true])->willReturn([$firstShippingMethod, $secondShippingMethod]);
48
49
        $this->getDefaultShippingMethod($shipment)->shouldReturn($firstShippingMethod);
50
    }
51
52
    function it_throws_exception_if_there_is_no_enabled_shipping_methods(
53
        ShippingMethodRepositoryInterface $shippingMethodRepository,
54
        ShipmentInterface $shipment
55
    ) {
56
        $shippingMethodRepository->findBy(['enabled' => true])->willReturn([]);
57
58
        $this
59
            ->shouldThrow(UnresolvedDefaultShippingMethodException::class)
60
            ->during('getDefaultShippingMethod', [$shipment])
61
        ;
62
    }
63
}
64