Completed
Push — master ( 860366...55daec )
by Kamil
19:37
created

DefaultFranceChannelFactorySpec   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 4
Bugs 1 Features 1
Metric Value
wmc 4
c 4
b 1
f 1
lcom 0
cbo 6
dl 0
loc 89
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
B let() 0 25 1
A it_is_initializable() 0 4 1
A it_implements_default_channel_factory_interface() 0 4 1
A it_creates_default_france_channel_with_country_zone_and_eur_as_default_currency() 0 50 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\Test\Services;
13
14
use PhpSpec\ObjectBehavior;
15
use Sylius\Component\Addressing\Model\CountryInterface;
16
use Sylius\Component\Addressing\Model\ZoneInterface;
17
use Sylius\Component\Addressing\Model\ZoneMemberInterface;
18
use Sylius\Component\Channel\Factory\ChannelFactoryInterface;
19
use Sylius\Component\Core\Model\ChannelInterface;
20
use Sylius\Component\Core\Test\Services\DefaultChannelFactoryInterface;
21
use Sylius\Component\Currency\Model\CurrencyInterface;
22
use Sylius\Component\Resource\Factory\FactoryInterface;
23
use Sylius\Component\Resource\Repository\RepositoryInterface;
24
25
/**
26
 * @author Arkadiusz Krakowiak <[email protected]>
27
 */
28
class DefaultFranceChannelFactorySpec extends ObjectBehavior
29
{
30
    function let(
31
        RepositoryInterface $channelRepository,
32
        RepositoryInterface $countryRepository,
33
        RepositoryInterface $currencyRepository,
34
        RepositoryInterface $zoneMemberRepository,
35
        RepositoryInterface $zoneRepository,
36
        ChannelFactoryInterface $channelFactory,
37
        FactoryInterface $countryFactory,
38
        FactoryInterface $currencyFactory,
39
        FactoryInterface $zoneFactory,
40
        FactoryInterface $zoneMemberFactory
41
    ) {
42
        $this->beConstructedWith(
43
            $channelRepository,
44
            $countryRepository,
45
            $currencyRepository,
46
            $zoneMemberRepository,
47
            $zoneRepository,
48
            $channelFactory,
49
            $countryFactory,
50
            $currencyFactory,
51
            $zoneFactory,
52
            $zoneMemberFactory
53
        );
54
    }
55
56
    function it_is_initializable()
57
    {
58
        $this->shouldHaveType('Sylius\Component\Core\Test\Services\DefaultFranceChannelFactory');
59
    }
60
61
    function it_implements_default_channel_factory_interface()
62
    {
63
        $this->shouldImplement(DefaultChannelFactoryInterface::class);
64
    }
65
66
    function it_creates_default_france_channel_with_country_zone_and_eur_as_default_currency(
67
        $channelRepository,
68
        $countryRepository,
69
        $currencyRepository,
70
        $zoneMemberRepository,
71
        $zoneRepository,
72
        $channelFactory,
73
        $countryFactory,
74
        $currencyFactory,
75
        $zoneMemberFactory,
76
        $zoneFactory,
77
        ZoneMemberInterface $zoneMember,
78
        ZoneInterface $zone,
79
        ChannelInterface $channel,
80
        CountryInterface $france,
81
        CurrencyInterface $euro
82
    ) {
83
        $channel->getName()->willReturn('France');
84
        $channelFactory->createNamed('France')->willReturn($channel);
85
86
        $zoneMemberFactory->createNew()->willReturn($zoneMember);
87
        $zoneFactory->createNew()->willReturn($zone);
88
89
        $channel->setCode('WEB-FR')->shouldBeCalled();
90
91
        $zoneMember->setCode('FR')->shouldBeCalled();
92
        $zone->setCode('FR')->shouldBeCalled();
93
        $zone->setName('France')->shouldBeCalled();
94
        $zone->setType(ZoneInterface::TYPE_COUNTRY)->shouldBeCalled();
95
        $zone->addMember($zoneMember)->shouldBeCalled();
96
97
        $countryFactory->createNew()->willReturn($france);
98
        $france->setCode('FR')->shouldBeCalled();
99
100
        $currencyFactory->createNew()->willReturn($euro);
101
        $euro->setCode('EUR')->shouldBeCalled();
102
        $euro->setExchangeRate(1.00)->shouldBeCalled();
103
        $euro->setBase(true)->shouldBeCalled();
104
105
        $channel->setDefaultCurrency($euro)->shouldBeCalled();
106
107
        $currencyRepository->add($euro)->shouldBeCalled();
108
        $countryRepository->add($france)->shouldBeCalled();
109
110
        $channelRepository->add($channel)->shouldBeCalled();
111
        $zoneRepository->add($zone)->shouldBeCalled();
112
        $zoneMemberRepository->add($zoneMember)->shouldBeCalled();
113
114
        $this->create();
115
    }
116
}
117