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
|
|
|
|