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