Completed
Push — 1.0-listener-flush ( 454bb4 )
by Kamil
26:12
created

DefaultUnitedStatesChannelFactorySpec   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 10

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 0
cbo 10
dl 0
loc 90
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
B let() 0 26 1
A it_implements_a_default_channel_factory_interface() 0 4 1
A it_creates_a_default_united_states_channel_with_country_zone_and_usd_as_base_currency() 0 55 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
declare(strict_types=1);
13
14
namespace spec\Sylius\Component\Core\Test\Services;
15
16
use PhpSpec\ObjectBehavior;
17
use Sylius\Component\Addressing\Factory\ZoneFactoryInterface;
18
use Sylius\Component\Addressing\Model\CountryInterface;
19
use Sylius\Component\Addressing\Model\ZoneInterface;
20
use Sylius\Component\Channel\Factory\ChannelFactoryInterface;
21
use Sylius\Component\Core\Model\ChannelInterface;
22
use Sylius\Component\Core\Test\Services\DefaultChannelFactoryInterface;
23
use Sylius\Component\Currency\Model\CurrencyInterface;
24
use Sylius\Component\Locale\Model\LocaleInterface;
25
use Sylius\Component\Resource\Factory\FactoryInterface;
26
use Sylius\Component\Resource\Repository\RepositoryInterface;
27
28
/**
29
 * @author Arkadiusz Krakowiak <[email protected]>
30
 */
31
final class DefaultUnitedStatesChannelFactorySpec extends ObjectBehavior
32
{
33
    function let(
34
        RepositoryInterface $channelRepository,
35
        RepositoryInterface $countryRepository,
36
        RepositoryInterface $currencyRepository,
37
        RepositoryInterface $localeRepository,
38
        RepositoryInterface $zoneRepository,
39
        ChannelFactoryInterface $channelFactory,
40
        FactoryInterface $countryFactory,
41
        FactoryInterface $currencyFactory,
42
        FactoryInterface $localeFactory,
43
        ZoneFactoryInterface $zoneFactory
44
    ): void {
45
        $this->beConstructedWith(
46
            $channelRepository,
47
            $countryRepository,
48
            $currencyRepository,
49
            $localeRepository,
50
            $zoneRepository,
51
            $channelFactory,
52
            $countryFactory,
53
            $currencyFactory,
54
            $localeFactory,
55
            $zoneFactory,
56
            'en_US'
57
        );
58
    }
59
60
    function it_implements_a_default_channel_factory_interface(): void
61
    {
62
        $this->shouldImplement(DefaultChannelFactoryInterface::class);
63
    }
64
65
    function it_creates_a_default_united_states_channel_with_country_zone_and_usd_as_base_currency(
66
        RepositoryInterface $channelRepository,
67
        RepositoryInterface $countryRepository,
68
        RepositoryInterface $currencyRepository,
69
        RepositoryInterface $localeRepository,
70
        RepositoryInterface $zoneRepository,
71
        ChannelFactoryInterface $channelFactory,
72
        FactoryInterface $countryFactory,
73
        FactoryInterface $currencyFactory,
74
        FactoryInterface $localeFactory,
75
        ZoneFactoryInterface $zoneFactory,
76
        ZoneInterface $zone,
77
        ChannelInterface $channel,
78
        CountryInterface $unitedStates,
79
        CurrencyInterface $currency,
80
        LocaleInterface $locale
81
    ): void {
82
        $channel->getName()->willReturn('United States');
83
        $channelFactory->createNamed('United States')->willReturn($channel);
84
85
        $localeFactory->createNew()->willReturn($locale);
86
        $locale->setCode('en_US')->shouldBeCalled();
87
88
        $zoneFactory->createWithMembers(['US'])->willReturn($zone);
89
90
        $channel->setCode('WEB-US')->shouldBeCalled();
91
        $channel->setTaxCalculationStrategy('order_items_based')->shouldBeCalled();
92
93
        $zone->setCode('US')->shouldBeCalled();
94
        $zone->setName('United States')->shouldBeCalled();
95
        $zone->setType(ZoneInterface::TYPE_COUNTRY)->shouldBeCalled();
96
97
        $countryFactory->createNew()->willReturn($unitedStates);
98
        $unitedStates->setCode('US')->shouldBeCalled();
99
100
        $currencyFactory->createNew()->willReturn($currency);
101
        $currency->setCode('USD')->shouldBeCalled();
102
103
        $channel->setBaseCurrency($currency)->shouldBeCalled();
104
        $channel->addCurrency($currency)->shouldBeCalled();
105
        $channel->setDefaultLocale($locale)->shouldBeCalled();
106
        $channel->addLocale($locale)->shouldBeCalled();
107
108
        $currencyRepository->findOneBy(['code' => 'USD'])->willReturn(null);
109
        $localeRepository->findOneBy(['code' => 'en_US'])->willReturn(null);
110
111
        $currencyRepository->add($currency)->shouldBeCalled();
112
        $localeRepository->add($locale)->shouldBeCalled();
113
114
        $countryRepository->add($unitedStates)->shouldBeCalled();
115
        $channelRepository->add($channel)->shouldBeCalled();
116
        $zoneRepository->add($zone)->shouldBeCalled();
117
118
        $this->create();
119
    }
120
}
121