Completed
Push — scalar-types/ui ( 162de3 )
by Kamil
22:15
created

it_is_initializable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 0
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
declare(strict_types=1);
13
14
namespace spec\Sylius\Component\Shipping\Resolver;
15
16
use PhpSpec\ObjectBehavior;
17
use Sylius\Component\Shipping\Exception\UnresolvedDefaultShippingMethodException;
18
use Sylius\Component\Shipping\Model\ShipmentInterface;
19
use Sylius\Component\Shipping\Model\ShippingMethodInterface;
20
use Sylius\Component\Shipping\Repository\ShippingMethodRepositoryInterface;
21
use Sylius\Component\Shipping\Resolver\DefaultShippingMethodResolverInterface;
22
23
/**
24
 * @author Mateusz Zalewski <[email protected]>
25
 */
26
final class DefaultShippingMethodResolverSpec extends ObjectBehavior
27
{
28
    function let(ShippingMethodRepositoryInterface $shippingMethodRepository): void
29
    {
30
        $this->beConstructedWith($shippingMethodRepository);
31
    }
32
33
    function it_implements_default_shipping_method_resolver_interface(): void
34
    {
35
        $this->shouldImplement(DefaultShippingMethodResolverInterface::class);
36
    }
37
38
    function it_returns_first_enabled_shipping_method_as_default(
39
        ShippingMethodInterface $firstShippingMethod,
40
        ShippingMethodInterface $secondShippingMethod,
41
        ShippingMethodRepositoryInterface $shippingMethodRepository,
42
        ShipmentInterface $shipment
43
    ): void {
44
        $shippingMethodRepository->findBy(['enabled' => true])->willReturn([$firstShippingMethod, $secondShippingMethod]);
45
46
        $this->getDefaultShippingMethod($shipment)->shouldReturn($firstShippingMethod);
47
    }
48
49
    function it_throws_exception_if_there_is_no_enabled_shipping_methods(
50
        ShippingMethodRepositoryInterface $shippingMethodRepository,
51
        ShipmentInterface $shipment
52
    ): void {
53
        $shippingMethodRepository->findBy(['enabled' => true])->willReturn([]);
54
55
        $this
56
            ->shouldThrow(UnresolvedDefaultShippingMethodException::class)
57
            ->during('getDefaultShippingMethod', [$shipment])
58
        ;
59
    }
60
}
61