|
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
|
|
|
final class DefaultUnitedStatesChannelFactorySpec extends ObjectBehavior |
|
29
|
|
|
{ |
|
30
|
|
|
function let( |
|
31
|
|
|
RepositoryInterface $channelRepository, |
|
32
|
|
|
RepositoryInterface $countryRepository, |
|
33
|
|
|
RepositoryInterface $currencyRepository, |
|
34
|
|
|
RepositoryInterface $localeRepository, |
|
35
|
|
|
RepositoryInterface $zoneRepository, |
|
36
|
|
|
ChannelFactoryInterface $channelFactory, |
|
37
|
|
|
FactoryInterface $countryFactory, |
|
38
|
|
|
FactoryInterface $currencyFactory, |
|
39
|
|
|
FactoryInterface $localeFactory, |
|
40
|
|
|
ZoneFactoryInterface $zoneFactory |
|
41
|
|
|
): void { |
|
42
|
|
|
$this->beConstructedWith( |
|
43
|
|
|
$channelRepository, |
|
44
|
|
|
$countryRepository, |
|
45
|
|
|
$currencyRepository, |
|
46
|
|
|
$localeRepository, |
|
47
|
|
|
$zoneRepository, |
|
48
|
|
|
$channelFactory, |
|
49
|
|
|
$countryFactory, |
|
50
|
|
|
$currencyFactory, |
|
51
|
|
|
$localeFactory, |
|
52
|
|
|
$zoneFactory, |
|
53
|
|
|
'en_US' |
|
54
|
|
|
); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
function it_implements_a_default_channel_factory_interface(): void |
|
58
|
|
|
{ |
|
59
|
|
|
$this->shouldImplement(DefaultChannelFactoryInterface::class); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
function it_creates_a_default_united_states_channel_with_country_zone_and_usd_as_base_currency( |
|
63
|
|
|
RepositoryInterface $channelRepository, |
|
64
|
|
|
RepositoryInterface $countryRepository, |
|
65
|
|
|
RepositoryInterface $currencyRepository, |
|
66
|
|
|
RepositoryInterface $localeRepository, |
|
67
|
|
|
RepositoryInterface $zoneRepository, |
|
68
|
|
|
ChannelFactoryInterface $channelFactory, |
|
69
|
|
|
FactoryInterface $countryFactory, |
|
70
|
|
|
FactoryInterface $currencyFactory, |
|
71
|
|
|
FactoryInterface $localeFactory, |
|
72
|
|
|
ZoneFactoryInterface $zoneFactory, |
|
73
|
|
|
ZoneInterface $zone, |
|
74
|
|
|
ChannelInterface $channel, |
|
75
|
|
|
CountryInterface $unitedStates, |
|
76
|
|
|
CurrencyInterface $currency, |
|
77
|
|
|
LocaleInterface $locale |
|
78
|
|
|
): void { |
|
79
|
|
|
$channel->getName()->willReturn('United States'); |
|
80
|
|
|
$channelFactory->createNamed('United States')->willReturn($channel); |
|
81
|
|
|
|
|
82
|
|
|
$localeFactory->createNew()->willReturn($locale); |
|
83
|
|
|
$locale->setCode('en_US')->shouldBeCalled(); |
|
84
|
|
|
|
|
85
|
|
|
$zoneFactory->createWithMembers(['US'])->willReturn($zone); |
|
86
|
|
|
|
|
87
|
|
|
$channel->setCode('WEB-US')->shouldBeCalled(); |
|
88
|
|
|
$channel->setTaxCalculationStrategy('order_items_based')->shouldBeCalled(); |
|
89
|
|
|
|
|
90
|
|
|
$zone->setCode('US')->shouldBeCalled(); |
|
91
|
|
|
$zone->setName('United States')->shouldBeCalled(); |
|
92
|
|
|
$zone->setType(ZoneInterface::TYPE_COUNTRY)->shouldBeCalled(); |
|
93
|
|
|
|
|
94
|
|
|
$countryFactory->createNew()->willReturn($unitedStates); |
|
95
|
|
|
$unitedStates->setCode('US')->shouldBeCalled(); |
|
96
|
|
|
|
|
97
|
|
|
$currencyFactory->createNew()->willReturn($currency); |
|
98
|
|
|
$currency->setCode('USD')->shouldBeCalled(); |
|
99
|
|
|
|
|
100
|
|
|
$channel->setBaseCurrency($currency)->shouldBeCalled(); |
|
101
|
|
|
$channel->addCurrency($currency)->shouldBeCalled(); |
|
102
|
|
|
$channel->setDefaultLocale($locale)->shouldBeCalled(); |
|
103
|
|
|
$channel->addLocale($locale)->shouldBeCalled(); |
|
104
|
|
|
|
|
105
|
|
|
$currencyRepository->findOneBy(['code' => 'USD'])->willReturn(null); |
|
106
|
|
|
$localeRepository->findOneBy(['code' => 'en_US'])->willReturn(null); |
|
107
|
|
|
|
|
108
|
|
|
$currencyRepository->add($currency)->shouldBeCalled(); |
|
109
|
|
|
$localeRepository->add($locale)->shouldBeCalled(); |
|
110
|
|
|
|
|
111
|
|
|
$countryRepository->add($unitedStates)->shouldBeCalled(); |
|
112
|
|
|
$channelRepository->add($channel)->shouldBeCalled(); |
|
113
|
|
|
$zoneRepository->add($zone)->shouldBeCalled(); |
|
114
|
|
|
|
|
115
|
|
|
$this->create(); |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|