Completed
Push — remove-content-bundle ( 201341...8d07b3 )
by Kamil
52:29 queued 32:39
created

ChannelAndCurrencyBasedCalculatorSpec   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 7
c 0
b 0
f 0
lcom 0
cbo 5
dl 0
loc 75
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 4 1
A it_is_initializable() 0 4 1
A it_implements_calculator_interface() 0 4 1
A it_returns_price_for_given_channel_and_currency_from_configuration() 0 16 1
A it_returns_subject_price_if_no_required_configuration_is_set() 0 15 1
A it_throws_exception_if_context_data_is_invalid() 0 19 1
A it_has_type() 0 4 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\Pricing;
13
14
use PhpSpec\ObjectBehavior;
15
use Sylius\Component\Channel\Context\ChannelContextInterface;
16
use Sylius\Component\Core\Model\ChannelInterface;
17
use Sylius\Component\Core\Pricing\Calculators;
18
use Sylius\Component\Core\Pricing\ChannelAndCurrencyBasedCalculator;
19
use Sylius\Component\Currency\Context\CurrencyContextInterface;
20
use Sylius\Component\Currency\Converter\CurrencyConverterInterface;
21
use Sylius\Component\Pricing\Calculator\CalculatorInterface;
22
use Sylius\Component\Pricing\Model\PriceableInterface;
23
24
/**
25
 * @author Mateusz Zalewski <[email protected]>
26
 */
27
final class ChannelAndCurrencyBasedCalculatorSpec extends ObjectBehavior
28
{
29
    function let(CurrencyConverterInterface $currencyConverter)
30
    {
31
        $this->beConstructedWith($currencyConverter);
32
    }
33
34
    function it_is_initializable()
35
    {
36
        $this->shouldHaveType(ChannelAndCurrencyBasedCalculator::class);
37
    }
38
39
    function it_implements_calculator_interface()
40
    {
41
        $this->shouldImplement(CalculatorInterface::class);
42
    }
43
44
    function it_returns_price_for_given_channel_and_currency_from_configuration(
45
        ChannelInterface $channel,
46
        CurrencyConverterInterface $currencyConverter,
47
        PriceableInterface $subject
48
    ) {
49
        $subject->getPricingConfiguration()->willReturn([
50
            'WEB-EU' => ['EUR' => 1000, 'GBP' => 500],
51
            'WEB-GB' => ['EUR' => 10000, 'GBP' => 5000],
52
        ]);
53
54
        $channel->getCode()->willReturn('WEB-EU');
55
56
        $currencyConverter->convertToBase(1000, 'EUR')->willReturn(1250);
57
58
        $this->calculate($subject, [], ['currency' => 'EUR', 'channel' => $channel])->shouldReturn(1250);
59
    }
60
61
    function it_returns_subject_price_if_no_required_configuration_is_set(
62
        ChannelInterface $channel,
63
        PriceableInterface $subject
64
    ) {
65
        $subject->getPricingConfiguration()->willReturn([
66
            'WEB-EU' => ['EUR' => 1000, 'GBP' => 500],
67
            'WEB-GB' => ['GBP' => 10000],
68
        ]);
69
70
        $channel->getCode()->willReturn('WEB-GB');
71
72
        $subject->getPrice()->willReturn(15000);
73
74
        $this->calculate($subject, [], ['currency' => 'EUR', 'channel' => $channel])->shouldReturn(15000);
75
    }
76
77
    function it_throws_exception_if_context_data_is_invalid(
78
        ChannelInterface $channel,
79
        PriceableInterface $subject
80
    ) {
81
        $this
82
            ->shouldThrow(new \InvalidArgumentException('You should configure currency and channel to determine a price.'))
83
            ->during('calculate', [$subject, [], ['channel' => $channel]])
84
        ;
85
86
        $this
87
            ->shouldThrow(new \InvalidArgumentException('You should configure currency and channel to determine a price.'))
88
            ->during('calculate', [$subject, [], ['currency' => 'EUR']])
89
        ;
90
91
        $this
92
            ->shouldThrow(new \InvalidArgumentException('You should configure currency and channel to determine a price.'))
93
            ->during('calculate', [$subject, [], []])
94
        ;
95
    }
96
97
    function it_has_type()
98
    {
99
        $this->getType()->shouldReturn(Calculators::CHANNEL_AND_CURRENCY_BASED);
100
    }
101
}
102