Completed
Push — layout-caching ( bff40d...dc5564 )
by Kamil
67:32 queued 46:25
created

CurrencyStorageSpec   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 5
dl 0
loc 82
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 4 1
A it_is_a_currency_storage() 0 4 1
A it_gets_a_currency_for_a_given_channel() 0 10 1
A it_sets_a_currency_for_a_given_channel_if_it_is_one_of_the_available_ones_but_not_the_base_one() 0 18 1
A it_removes_a_currency_for_a_given_channel_if_it_is_the_base_one() 0 19 1
A it_removes_a_currency_for_a_given_channel_if_it_is_not_available() 0 19 1
1
<?php
2
3
namespace spec\Sylius\Component\Core\Currency;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use PhpSpec\ObjectBehavior;
7
use Sylius\Component\Core\Currency\CurrencyStorageInterface;
8
use Sylius\Component\Core\Model\ChannelInterface;
9
use Sylius\Component\Currency\Model\Currency;
10
use Sylius\Component\Resource\Storage\StorageInterface;
11
12
/**
13
 * @author Kamil Kokot <[email protected]>
14
 */
15
final class CurrencyStorageSpec extends ObjectBehavior
16
{
17
    function let(StorageInterface $storage)
18
    {
19
        $this->beConstructedWith($storage);
20
    }
21
22
    function it_is_a_currency_storage()
23
    {
24
        $this->shouldImplement(CurrencyStorageInterface::class);
25
    }
26
27
    function it_gets_a_currency_for_a_given_channel(
28
        StorageInterface $storage,
29
        ChannelInterface $channel
30
    ) {
31
        $channel->getCode()->willReturn('web');
32
33
        $storage->get('_currency_web')->willReturn('BTC');
34
35
        $this->get($channel)->shouldReturn('BTC');
36
    }
37
38
    function it_sets_a_currency_for_a_given_channel_if_it_is_one_of_the_available_ones_but_not_the_base_one(
39
        StorageInterface $storage,
40
        ChannelInterface $channel
41
    ) {
42
        $usd = new Currency();
43
        $usd->setCode('USD');
44
45
        $eur = new Currency();
46
        $eur->setCode('EUR');
47
48
        $channel->getBaseCurrency()->willReturn($usd);
49
        $channel->getCurrencies()->willReturn(new ArrayCollection([$usd, $eur]));
50
        $channel->getCode()->willReturn('web');
51
52
        $storage->set('_currency_web', 'EUR')->shouldBeCalled();
53
54
        $this->set($channel, 'EUR');
55
    }
56
57
    function it_removes_a_currency_for_a_given_channel_if_it_is_the_base_one(
58
        StorageInterface $storage,
59
        ChannelInterface $channel
60
    ) {
61
        $usd = new Currency();
62
        $usd->setCode('USD');
63
64
        $eur = new Currency();
65
        $eur->setCode('EUR');
66
67
        $channel->getBaseCurrency()->willReturn($usd);
68
        $channel->getCurrencies()->willReturn(new ArrayCollection([$usd, $eur]));
69
        $channel->getCode()->willReturn('web');
70
71
        $storage->set('_currency_web', 'USD')->shouldNotBeCalled();
72
        $storage->remove('_currency_web')->shouldBeCalled();
73
74
        $this->set($channel, 'USD');
75
    }
76
77
    function it_removes_a_currency_for_a_given_channel_if_it_is_not_available(
78
        StorageInterface $storage,
79
        ChannelInterface $channel
80
    ) {
81
        $usd = new Currency();
82
        $usd->setCode('USD');
83
84
        $eur = new Currency();
85
        $eur->setCode('EUR');
86
87
        $channel->getBaseCurrency()->willReturn($usd);
88
        $channel->getCurrencies()->willReturn(new ArrayCollection([$usd, $eur]));
89
        $channel->getCode()->willReturn('web');
90
91
        $storage->set('_currency_web', 'GBP')->shouldNotBeCalled();
92
        $storage->remove('_currency_web')->shouldBeCalled();
93
94
        $this->set($channel, 'GBP');
95
    }
96
}
97