Completed
Push — master ( cfaf77...b5ed7c )
by Kamil
47:11 queued 29:42
created

PerUnitRateCalculatorSpec   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
lcom 0
cbo 5
dl 0
loc 32
rs 10
c 1
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A it_is_initializable() 0 4 1
A it_implements_shipping_calculator_interface() 0 4 1
A it_returns_per_unit_rate_type() 0 6 1
A it_calculates_the_total_with_the_per_unit_amount_configured_on_the_method() 0 12 1
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