Completed
Push — core-test-reorganisation ( 880d88 )
by Kamil
44:19 queued 07:25
created

it_is_initializable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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\Behat\Service;
13
14
use PhpSpec\ObjectBehavior;
15
use Sylius\Component\Addressing\Factory\ZoneFactoryInterface;
16
use Sylius\Component\Addressing\Model\CountryInterface;
17
use Sylius\Component\Addressing\Model\Scope;
18
use Sylius\Component\Addressing\Model\ZoneInterface;
19
use Sylius\Component\Channel\Factory\ChannelFactoryInterface;
20
use Sylius\Component\Core\Model\ChannelInterface;
21
use Sylius\Behat\Service\DefaultChannelFactoryInterface;
22
use Sylius\Behat\Service\DefaultUnitedStatesChannelFactory;
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
    ) {
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_is_initializable()
61
    {
62
        $this->shouldHaveType(DefaultUnitedStatesChannelFactory::class);
63
    }
64
65
    function it_implements_a_default_channel_factory_interface()
66
    {
67
        $this->shouldImplement(DefaultChannelFactoryInterface::class);
68
    }
69
70
    function it_creates_a_default_united_states_channel_with_country_zone_and_usd_as_base_currency(
71
        RepositoryInterface $channelRepository,
72
        RepositoryInterface $countryRepository,
73
        RepositoryInterface $currencyRepository,
74
        RepositoryInterface $localeRepository,
75
        RepositoryInterface $zoneRepository,
76
        ChannelFactoryInterface $channelFactory,
77
        FactoryInterface $countryFactory,
78
        FactoryInterface $currencyFactory,
79
        FactoryInterface $localeFactory,
80
        ZoneFactoryInterface $zoneFactory,
81
        ZoneInterface $zone,
82
        ChannelInterface $channel,
83
        CountryInterface $unitedStates,
84
        CurrencyInterface $currency,
85
        LocaleInterface $locale
86
    ) {
87
        $channel->getName()->willReturn('United States');
88
        $channelFactory->createNamed('United States')->willReturn($channel);
89
90
        $localeFactory->createNew()->willReturn($locale);
91
        $locale->setCode('en_US')->shouldBeCalled();
92
93
        $zoneFactory->createWithMembers(['US'])->willReturn($zone);
94
95
        $channel->setCode('WEB-US')->shouldBeCalled();
96
        $channel->setTaxCalculationStrategy('order_items_based')->shouldBeCalled();
97
98
        $zone->setCode('US')->shouldBeCalled();
99
        $zone->setName('United States')->shouldBeCalled();
100
        $zone->setType(ZoneInterface::TYPE_COUNTRY)->shouldBeCalled();
101
102
        $countryFactory->createNew()->willReturn($unitedStates);
103
        $unitedStates->setCode('US')->shouldBeCalled();
104
105
        $currencyFactory->createNew()->willReturn($currency);
106
        $currency->setCode('USD')->shouldBeCalled();
107
108
        $channel->setBaseCurrency($currency)->shouldBeCalled();
109
        $channel->addCurrency($currency)->shouldBeCalled();
110
        $channel->setDefaultLocale($locale)->shouldBeCalled();
111
        $channel->addLocale($locale)->shouldBeCalled();
112
113
        $currencyRepository->findOneBy(['code' => 'USD'])->willReturn(null);
114
        $localeRepository->findOneBy(['code' => 'en_US'])->willReturn(null);
115
116
        $currencyRepository->add($currency)->shouldBeCalled();
117
        $localeRepository->add($locale)->shouldBeCalled();
118
119
        $countryRepository->add($unitedStates)->shouldBeCalled();
120
        $channelRepository->add($channel)->shouldBeCalled();
121
        $zoneRepository->add($zone)->shouldBeCalled();
122
123
        $this->create();
124
    }
125
}
126