Completed
Push — 1.0-symfony2-rename ( d9b26c )
by Kamil
98:47 queued 78:51
created

FlatRateCalculatorSpec   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 5
dl 0
loc 47
c 0
b 0
f 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A it_implements_shipping_calculator_interface() 0 4 1
A it_returns_flat_rate_type() 0 6 1
A it_calculates_the_flat_rate_amount_configured_on_the_method() 0 11 1
A it_throws_a_channel_not_defined_exception_if_channel_code_key_does_not_exist() 0 20 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
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);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...r\Model\OrderInterface>.

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.

Loading history...
44
        $order->getChannel()->willReturn($channel);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...Model\ChannelInterface>.

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.

Loading history...
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);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...r\Model\OrderInterface>.

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.

Loading history...
57
        $shipment->getMethod()->willReturn($shippingMethod);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...hippingMethodInterface>.

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.

Loading history...
58
59
        $order->getChannel()->willReturn($channel);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Sylius\Component\...Model\ChannelInterface>.

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.

Loading history...
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