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\Core\Shipping\Calculator; |
15
|
|
|
|
16
|
|
|
use PhpSpec\ObjectBehavior; |
17
|
|
|
use Sylius\Component\Core\Exception\MissingChannelConfigurationException; |
18
|
|
|
use Sylius\Component\Core\Model\ChannelInterface; |
19
|
|
|
use Sylius\Component\Core\Model\OrderInterface; |
20
|
|
|
use Sylius\Component\Core\Model\ShipmentInterface; |
21
|
|
|
use Sylius\Component\Core\Model\ShippingMethodInterface; |
22
|
|
|
use Sylius\Component\Shipping\Calculator\CalculatorInterface; |
23
|
|
|
|
24
|
|
|
final class FlatRateCalculatorSpec extends ObjectBehavior |
25
|
|
|
{ |
26
|
|
|
function it_implements_shipping_calculator_interface(): void |
27
|
|
|
{ |
28
|
|
|
$this->shouldImplement(CalculatorInterface::class); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
function it_returns_flat_rate_type(CalculatorInterface $calculator): void |
32
|
|
|
{ |
33
|
|
|
$calculator->getType()->willReturn('flat_rate'); |
34
|
|
|
|
35
|
|
|
$this->getType()->shouldReturn('flat_rate'); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
function it_calculates_the_flat_rate_amount_configured_on_the_method( |
39
|
|
|
ShipmentInterface $shipment, |
40
|
|
|
OrderInterface $order, |
41
|
|
|
ChannelInterface $channel |
42
|
|
|
): void { |
43
|
|
|
$shipment->getOrder()->willReturn($order); |
|
|
|
|
44
|
|
|
$order->getChannel()->willReturn($channel); |
|
|
|
|
45
|
|
|
$channel->getCode()->willReturn('WEB'); |
46
|
|
|
|
47
|
|
|
$this->calculate($shipment, ['WEB' => ['amount' => 1500]])->shouldReturn(1500); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
function it_throws_a_channel_not_defined_exception_if_channel_code_key_does_not_exist( |
51
|
|
|
ShipmentInterface $shipment, |
52
|
|
|
OrderInterface $order, |
53
|
|
|
ChannelInterface $channel, |
54
|
|
|
ShippingMethodInterface $shippingMethod |
55
|
|
|
): void { |
56
|
|
|
$shipment->getOrder()->willReturn($order); |
|
|
|
|
57
|
|
|
$shipment->getMethod()->willReturn($shippingMethod); |
|
|
|
|
58
|
|
|
|
59
|
|
|
$order->getChannel()->willReturn($channel); |
|
|
|
|
60
|
|
|
$channel->getCode()->willReturn('WEB'); |
61
|
|
|
$channel->getName()->willReturn('WEB'); |
62
|
|
|
|
63
|
|
|
$shippingMethod->getName()->willReturn('UPS'); |
64
|
|
|
|
65
|
|
|
$this |
66
|
|
|
->shouldThrow(MissingChannelConfigurationException::class) |
67
|
|
|
->during('calculate', [$shipment, ['amount' => 1500]]) |
68
|
|
|
; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.