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 Sylius\Behat\Context\Setup; |
13
|
|
|
|
14
|
|
|
use Behat\Behat\Context\Context; |
15
|
|
|
use Sylius\Component\Channel\Factory\ChannelFactoryInterface; |
16
|
|
|
use Sylius\Component\Channel\Repository\ChannelRepositoryInterface; |
17
|
|
|
use Sylius\Component\Core\Test\Services\DefaultChannelFactoryInterface; |
18
|
|
|
use Sylius\Component\Core\Test\Services\SharedStorageInterface; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @author Arkadiusz Krakowiak <[email protected]> |
22
|
|
|
* @author Mateusz Zalewski <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
final class ChannelContext implements Context |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var SharedStorageInterface |
28
|
|
|
*/ |
29
|
|
|
private $sharedStorage; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var DefaultChannelFactoryInterface |
33
|
|
|
*/ |
34
|
|
|
private $franceChannelFactory; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var DefaultChannelFactoryInterface |
38
|
|
|
*/ |
39
|
|
|
private $defaultChannelFactory; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var ChannelFactoryInterface |
43
|
|
|
*/ |
44
|
|
|
private $channelFactory; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var ChannelRepositoryInterface |
48
|
|
|
*/ |
49
|
|
|
private $channelRepository; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param SharedStorageInterface $sharedStorage |
53
|
|
|
* @param DefaultChannelFactoryInterface $franceChannelFactory |
54
|
|
|
* @param DefaultChannelFactoryInterface $defaultChannelFactory |
55
|
|
|
* @param ChannelFactoryInterface $channelFactory |
56
|
|
|
* @param ChannelRepositoryInterface $channelRepository |
57
|
|
|
*/ |
58
|
|
|
public function __construct( |
59
|
|
|
SharedStorageInterface $sharedStorage, |
60
|
|
|
DefaultChannelFactoryInterface $franceChannelFactory, |
61
|
|
|
DefaultChannelFactoryInterface $defaultChannelFactory, |
62
|
|
|
ChannelFactoryInterface $channelFactory, |
63
|
|
|
ChannelRepositoryInterface $channelRepository |
64
|
|
|
) { |
65
|
|
|
$this->sharedStorage = $sharedStorage; |
66
|
|
|
$this->franceChannelFactory = $franceChannelFactory; |
67
|
|
|
$this->defaultChannelFactory = $defaultChannelFactory; |
68
|
|
|
$this->channelFactory = $channelFactory; |
69
|
|
|
$this->channelRepository = $channelRepository; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @Transform /^channel "([^"]+)"$/ |
74
|
|
|
* @Transform /^"([^"]+)" channel/ |
75
|
|
|
* @Transform :channel |
76
|
|
|
*/ |
77
|
|
|
public function getChannelByName($channelName) |
78
|
|
|
{ |
79
|
|
|
$channel = $this->channelRepository->findOneBy(['name' => $channelName]); |
80
|
|
|
if (null === $channel) { |
81
|
|
|
throw new \InvalidArgumentException('Channel with name "'.$channelName.'" does not exist'); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
return $channel; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @Transform /(?:this|that|the) channel/ |
89
|
|
|
*/ |
90
|
|
|
public function getLatestChannel() |
91
|
|
|
{ |
92
|
|
|
return $this->sharedStorage->getCurrentResource('channel'); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @Given the store is operating on a single "France" channel |
97
|
|
|
*/ |
98
|
|
|
public function thatStoreIsOperatingOnASingleFranceChannel() |
99
|
|
|
{ |
100
|
|
|
$defaultData = $this->franceChannelFactory->create(); |
101
|
|
|
$this->sharedStorage->setClipboard($defaultData); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @Given the store operates on a single channel |
106
|
|
|
* @Given the store is operating on a single channel |
107
|
|
|
*/ |
108
|
|
|
public function thatStoreIsOperatingOnASingleChannel() |
109
|
|
|
{ |
110
|
|
|
$defaultData = $this->defaultChannelFactory->create(); |
111
|
|
|
$this->sharedStorage->setClipboard($defaultData); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @Given /^the store operates on (?:a|another) channel named "([^"]+)"$/ |
116
|
|
|
*/ |
117
|
|
|
public function theStoreOperatesOnAChannelNamed($channelName) |
118
|
|
|
{ |
119
|
|
|
$channel = $this->channelFactory->createNamed($channelName); |
120
|
|
|
$channel->setCode($channelName); |
121
|
|
|
|
122
|
|
|
$this->channelRepository->add($channel); |
123
|
|
|
$this->sharedStorage->setCurrentResource('channel', $channel); |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|