|
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 PhpSpec\ObjectBehavior; |
|
15
|
|
|
use Sylius\Component\Channel\Context\ChannelContextInterface; |
|
16
|
|
|
use Sylius\Component\Core\Currency\CurrencyStorageInterface; |
|
17
|
|
|
use Sylius\Component\Core\Model\ChannelInterface; |
|
18
|
|
|
use Sylius\Component\Currency\Context\CurrencyContextInterface; |
|
19
|
|
|
use Sylius\Component\Currency\Context\CurrencyNotFoundException; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @author Kamil Kokot <[email protected]> |
|
23
|
|
|
*/ |
|
24
|
|
|
final class StorageBasedCurrencyContextSpec extends ObjectBehavior |
|
25
|
|
|
{ |
|
26
|
|
|
function let(ChannelContextInterface $channelContext, CurrencyStorageInterface $currencyStorage) |
|
27
|
|
|
{ |
|
28
|
|
|
$this->beConstructedWith($channelContext, $currencyStorage); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
function it_is_a_currency_context() |
|
32
|
|
|
{ |
|
33
|
|
|
$this->shouldImplement(CurrencyContextInterface::class); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
function it_returns_an_available_active_currency( |
|
37
|
|
|
ChannelContextInterface $channelContext, |
|
38
|
|
|
CurrencyStorageInterface $currencyStorage, |
|
39
|
|
|
ChannelInterface $channel |
|
40
|
|
|
) { |
|
41
|
|
|
$channelContext->getChannel()->willReturn($channel); |
|
42
|
|
|
|
|
43
|
|
|
$currencyStorage->get($channel)->willReturn('BTC'); |
|
44
|
|
|
|
|
45
|
|
|
$this->getCurrencyCode()->shouldReturn('BTC'); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
function it_throws_an_exception_if_storage_does_not_have_currency_code( |
|
49
|
|
|
ChannelContextInterface $channelContext, |
|
50
|
|
|
CurrencyStorageInterface $currencyStorage, |
|
51
|
|
|
ChannelInterface $channel |
|
52
|
|
|
) { |
|
53
|
|
|
$channelContext->getChannel()->willReturn($channel); |
|
54
|
|
|
|
|
55
|
|
|
$currencyStorage->get($channel)->willReturn(null); |
|
56
|
|
|
|
|
57
|
|
|
$this->shouldThrow(CurrencyNotFoundException::class)->during('getCurrencyCode'); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|