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

DefaultShippingMethodResolverSpec::let()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 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