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\Currency\Context; |
13
|
|
|
|
14
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
15
|
|
|
use PhpSpec\ObjectBehavior; |
16
|
|
|
use Sylius\Component\Channel\Context\ChannelContextInterface; |
17
|
|
|
use Sylius\Component\Core\Model\ChannelInterface; |
18
|
|
|
use Sylius\Component\Currency\Context\CurrencyContextInterface; |
19
|
|
|
use Sylius\Component\Currency\Context\CurrencyNotFoundException; |
20
|
|
|
use Sylius\Component\Currency\Model\Currency; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @author Kamil Kokot <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
final class ChannelAwareCurrencyContextSpec extends ObjectBehavior |
26
|
|
|
{ |
27
|
|
|
function let(CurrencyContextInterface $currencyContext, ChannelContextInterface $channelContext) |
28
|
|
|
{ |
29
|
|
|
$this->beConstructedWith($currencyContext, $channelContext); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
function it_is_a_currency_context() |
33
|
|
|
{ |
34
|
|
|
$this->shouldImplement(CurrencyContextInterface::class); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
function it_returns_the_currency_code_from_decorated_context_if_it_is_available_in_current_channel( |
38
|
|
|
CurrencyContextInterface $currencyContext, |
39
|
|
|
ChannelContextInterface $channelContext, |
40
|
|
|
ChannelInterface $channel |
41
|
|
|
) { |
42
|
|
|
$eur = new Currency(); |
43
|
|
|
$eur->setCode('EUR'); |
44
|
|
|
|
45
|
|
|
$usd = new Currency(); |
46
|
|
|
$usd->setCode('USD'); |
47
|
|
|
|
48
|
|
|
$channel->getCurrencies()->willReturn(new ArrayCollection([$eur, $usd])); |
49
|
|
|
$channelContext->getChannel()->willReturn($channel); |
50
|
|
|
|
51
|
|
|
$currencyContext->getCurrencyCode()->willReturn('USD'); |
52
|
|
|
|
53
|
|
|
$this->getCurrencyCode()->shouldReturn('USD'); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
function it_returns_the_channels_base_currency_if_the_one_from_context_is_not_available( |
57
|
|
|
CurrencyContextInterface $currencyContext, |
58
|
|
|
ChannelContextInterface $channelContext, |
59
|
|
|
ChannelInterface $channel |
60
|
|
|
) { |
61
|
|
|
$eur = new Currency(); |
62
|
|
|
$eur->setCode('EUR'); |
63
|
|
|
|
64
|
|
|
$channel->getBaseCurrency()->willReturn($eur); |
65
|
|
|
$channel->getCurrencies()->willReturn(new ArrayCollection([$eur])); |
66
|
|
|
$channelContext->getChannel()->willReturn($channel); |
67
|
|
|
|
68
|
|
|
$currencyContext->getCurrencyCode()->willReturn('USD'); |
69
|
|
|
|
70
|
|
|
$this->getCurrencyCode()->shouldReturn('EUR'); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
function it_returns_the_channels_base_currency_if_currency_was_not_found( |
74
|
|
|
CurrencyContextInterface $currencyContext, |
75
|
|
|
ChannelContextInterface $channelContext, |
76
|
|
|
ChannelInterface $channel |
77
|
|
|
) { |
78
|
|
|
$eur = new Currency(); |
79
|
|
|
$eur->setCode('EUR'); |
80
|
|
|
|
81
|
|
|
$channel->getBaseCurrency()->willReturn($eur); |
82
|
|
|
$channelContext->getChannel()->willReturn($channel); |
83
|
|
|
|
84
|
|
|
$currencyContext->getCurrencyCode()->willThrow(CurrencyNotFoundException::class); |
85
|
|
|
|
86
|
|
|
$this->getCurrencyCode()->shouldReturn('EUR'); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|