|
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\Core\Shipping\Calculator; |
|
13
|
|
|
|
|
14
|
|
|
use PhpSpec\ObjectBehavior; |
|
15
|
|
|
use Sylius\Component\Channel\Context\ChannelContextInterface; |
|
16
|
|
|
use Sylius\Component\Core\Model\ChannelInterface; |
|
17
|
|
|
use Sylius\Component\Core\Model\OrderInterface; |
|
18
|
|
|
use Sylius\Component\Core\Model\ShipmentInterface; |
|
19
|
|
|
use Sylius\Component\Core\Shipping\Calculator\PerUnitRateCalculator; |
|
20
|
|
|
use Sylius\Component\Shipping\Calculator\CalculatorInterface; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @author Grzegorz Sadowski <[email protected]> |
|
24
|
|
|
*/ |
|
25
|
|
|
final class PerUnitRateCalculatorSpec extends ObjectBehavior |
|
26
|
|
|
{ |
|
27
|
|
|
function it_is_initializable() |
|
28
|
|
|
{ |
|
29
|
|
|
$this->shouldHaveType(PerUnitRateCalculator::class); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
function it_implements_shipping_calculator_interface() |
|
33
|
|
|
{ |
|
34
|
|
|
$this->shouldImplement(CalculatorInterface::class); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
function it_returns_per_unit_rate_type(CalculatorInterface $calculator) |
|
38
|
|
|
{ |
|
39
|
|
|
$calculator->getType()->willReturn('per_unit_rate'); |
|
40
|
|
|
|
|
41
|
|
|
$this->getType()->shouldReturn('per_unit_rate'); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
function it_calculates_the_total_with_the_per_unit_amount_configured_on_the_method( |
|
45
|
|
|
ShipmentInterface $shipment, |
|
46
|
|
|
OrderInterface $order, |
|
47
|
|
|
ChannelInterface $channel |
|
48
|
|
|
) { |
|
49
|
|
|
$shipment->getOrder()->willReturn($order); |
|
50
|
|
|
$order->getChannel()->willReturn($channel); |
|
51
|
|
|
$channel->getCode()->willReturn('WEB'); |
|
52
|
|
|
$shipment->getShippingUnitCount()->willReturn(10); |
|
53
|
|
|
|
|
54
|
|
|
$this->calculate($shipment, ['WEB' => ['amount' => 200]])->shouldReturn(2000); |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|