|
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\Calculator; |
|
15
|
|
|
|
|
16
|
|
|
use PhpSpec\ObjectBehavior; |
|
17
|
|
|
use Sylius\Component\Registry\ServiceRegistryInterface; |
|
18
|
|
|
use Sylius\Component\Shipping\Calculator\CalculatorInterface; |
|
19
|
|
|
use Sylius\Component\Shipping\Calculator\DelegatingCalculatorInterface; |
|
20
|
|
|
use Sylius\Component\Shipping\Calculator\UndefinedShippingMethodException; |
|
21
|
|
|
use Sylius\Component\Shipping\Model\ShipmentInterface; |
|
22
|
|
|
use Sylius\Component\Shipping\Model\ShippingMethodInterface; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @author Paweł Jędrzejewski <[email protected]> |
|
26
|
|
|
*/ |
|
27
|
|
|
final class DelegatingCalculatorSpec extends ObjectBehavior |
|
28
|
|
|
{ |
|
29
|
|
|
function let(ServiceRegistryInterface $registry): void |
|
30
|
|
|
{ |
|
31
|
|
|
$this->beConstructedWith($registry); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
function it_implements_delegating_shipping_calculator_interface(): void |
|
35
|
|
|
{ |
|
36
|
|
|
$this->shouldImplement(DelegatingCalculatorInterface::class); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
function it_should_complain_if_shipment_has_no_method_defined(ShipmentInterface $shipment): void |
|
40
|
|
|
{ |
|
41
|
|
|
$shipment->getMethod()->willReturn(null); |
|
42
|
|
|
|
|
43
|
|
|
$this |
|
44
|
|
|
->shouldThrow(UndefinedShippingMethodException::class) |
|
45
|
|
|
->duringCalculate($shipment) |
|
46
|
|
|
; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
function it_should_delegate_calculation_to_a_calculator_defined_on_shipping_method( |
|
50
|
|
|
ServiceRegistryInterface $registry, |
|
51
|
|
|
ShipmentInterface $shipment, |
|
52
|
|
|
ShippingMethodInterface $method, |
|
53
|
|
|
CalculatorInterface $calculator |
|
54
|
|
|
): void { |
|
55
|
|
|
$shipment->getMethod()->willReturn($method); |
|
56
|
|
|
|
|
57
|
|
|
$method->getCalculator()->willReturn('default'); |
|
58
|
|
|
$method->getConfiguration()->willReturn([]); |
|
59
|
|
|
|
|
60
|
|
|
$registry->get('default')->willReturn($calculator); |
|
61
|
|
|
$calculator->calculate($shipment, [])->shouldBeCalled()->willReturn(1000); |
|
62
|
|
|
|
|
63
|
|
|
$this->calculate($shipment, [])->shouldReturn(1000); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|