|
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\Channel\Factory\ChannelFactoryInterface; |
|
16
|
|
|
use Sylius\Component\Core\Model\ChannelInterface; |
|
17
|
|
|
use Sylius\Behat\Service\DefaultChannelFactory; |
|
18
|
|
|
use Sylius\Behat\Service\DefaultChannelFactoryInterface; |
|
19
|
|
|
use Sylius\Component\Currency\Model\CurrencyInterface; |
|
20
|
|
|
use Sylius\Component\Locale\Model\LocaleInterface; |
|
21
|
|
|
use Sylius\Component\Resource\Factory\FactoryInterface; |
|
22
|
|
|
use Sylius\Component\Resource\Repository\RepositoryInterface; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @author Mateusz Zalewski <[email protected]> |
|
26
|
|
|
*/ |
|
27
|
|
|
final class DefaultChannelFactorySpec extends ObjectBehavior |
|
28
|
|
|
{ |
|
29
|
|
|
function let( |
|
30
|
|
|
ChannelFactoryInterface $channelFactory, |
|
31
|
|
|
FactoryInterface $currencyFactory, |
|
32
|
|
|
FactoryInterface $localeFactory, |
|
33
|
|
|
RepositoryInterface $channelRepository, |
|
34
|
|
|
RepositoryInterface $currencyRepository, |
|
35
|
|
|
RepositoryInterface $localeRepository |
|
36
|
|
|
) { |
|
37
|
|
|
$this->beConstructedWith( |
|
38
|
|
|
$channelFactory, |
|
39
|
|
|
$currencyFactory, |
|
40
|
|
|
$localeFactory, |
|
41
|
|
|
$channelRepository, |
|
42
|
|
|
$currencyRepository, |
|
43
|
|
|
$localeRepository, |
|
44
|
|
|
'en_US' |
|
45
|
|
|
); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
function it_is_initializable() |
|
49
|
|
|
{ |
|
50
|
|
|
$this->shouldHaveType(DefaultChannelFactory::class); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
function it_implements_a_default_channel_factory_interface() |
|
54
|
|
|
{ |
|
55
|
|
|
$this->shouldImplement(DefaultChannelFactoryInterface::class); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
function it_creates_a_default_channel_and_persist_it( |
|
59
|
|
|
ChannelFactoryInterface $channelFactory, |
|
60
|
|
|
FactoryInterface $currencyFactory, |
|
61
|
|
|
FactoryInterface $localeFactory, |
|
62
|
|
|
RepositoryInterface $channelRepository, |
|
63
|
|
|
RepositoryInterface $currencyRepository, |
|
64
|
|
|
RepositoryInterface $localeRepository, |
|
65
|
|
|
ChannelInterface $channel, |
|
66
|
|
|
CurrencyInterface $currency, |
|
67
|
|
|
LocaleInterface $locale |
|
68
|
|
|
) { |
|
69
|
|
|
$localeFactory->createNew()->willReturn($locale); |
|
70
|
|
|
$locale->setCode('en_US')->shouldBeCalled(); |
|
71
|
|
|
|
|
72
|
|
|
$currencyFactory->createNew()->willReturn($currency); |
|
73
|
|
|
$currency->setCode('USD')->shouldBeCalled(); |
|
74
|
|
|
|
|
75
|
|
|
$channelFactory->createNamed('Default')->willReturn($channel); |
|
76
|
|
|
|
|
77
|
|
|
$channel->setCode('DEFAULT')->shouldBeCalled(); |
|
78
|
|
|
$channel->setTaxCalculationStrategy('order_items_based')->shouldBeCalled(); |
|
79
|
|
|
|
|
80
|
|
|
$channel->addCurrency($currency)->shouldBeCalled(); |
|
81
|
|
|
$channel->setBaseCurrency($currency)->shouldBeCalled(); |
|
82
|
|
|
$channel->addLocale($locale)->shouldBeCalled(); |
|
83
|
|
|
$channel->setDefaultLocale($locale)->shouldBeCalled(); |
|
84
|
|
|
|
|
85
|
|
|
$currencyRepository->findOneBy(['code' => 'USD'])->willReturn(null); |
|
86
|
|
|
$localeRepository->findOneBy(['code' => 'en_US'])->willReturn(null); |
|
87
|
|
|
|
|
88
|
|
|
$currencyRepository->add($currency)->shouldBeCalled(); |
|
89
|
|
|
$localeRepository->add($locale)->shouldBeCalled(); |
|
90
|
|
|
$channelRepository->add($channel)->shouldBeCalled(); |
|
91
|
|
|
|
|
92
|
|
|
$this->create()->shouldReturn(['channel' => $channel, 'currency' => $currency, 'locale' => $locale]); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|