Completed
Push — unused-definitions ( d9908f )
by Kamil
18:33
created

ChannelContext::storeOperatesOnASingleChannel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 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
namespace Sylius\Behat\Context\Setup;
13
14
use Behat\Behat\Context\Context;
15
use Doctrine\Common\Persistence\ObjectManager;
16
use Sylius\Component\Addressing\Model\ZoneInterface;
17
use Sylius\Component\Channel\Factory\ChannelFactoryInterface;
18
use Sylius\Component\Channel\Repository\ChannelRepositoryInterface;
19
use Sylius\Component\Core\Currency\CurrencyStorageInterface;
20
use Sylius\Component\Core\Model\ChannelInterface;
21
use Sylius\Component\Core\Test\Services\DefaultChannelFactoryInterface;
22
use Sylius\Behat\Service\SharedStorageInterface;
23
use Sylius\Component\Currency\Model\CurrencyInterface;
24
25
/**
26
 * @author Arkadiusz Krakowiak <[email protected]>
27
 * @author Mateusz Zalewski <[email protected]>
28
 */
29
final class ChannelContext implements Context
30
{
31
    /**
32
     * @var SharedStorageInterface
33
     */
34
    private $sharedStorage;
35
36
    /**
37
     * @var DefaultChannelFactoryInterface
38
     */
39
    private $unitedStatesChannelFactory;
40
41
    /**
42
     * @var DefaultChannelFactoryInterface
43
     */
44
    private $defaultChannelFactory;
45
46
    /**
47
     * @var ChannelFactoryInterface
48
     */
49
    private $channelFactory;
50
51
    /**
52
     * @var ChannelRepositoryInterface
53
     */
54
    private $channelRepository;
55
56
    /**
57
     * @var ObjectManager
58
     */
59
    private $channelManager;
60
61
    /**
62
     * @var CurrencyStorageInterface
63
     */
64
    private $currencyStorage;
65
66
    /**
67
     * @param SharedStorageInterface $sharedStorage
68
     * @param DefaultChannelFactoryInterface $unitedStatesChannelFactory
69
     * @param DefaultChannelFactoryInterface $defaultChannelFactory
70
     * @param ChannelFactoryInterface $channelFactory
71
     * @param ChannelRepositoryInterface $channelRepository
72
     * @param ObjectManager $channelManager
73
     * @param CurrencyStorageInterface $currencyStorage
74
     */
75
    public function __construct(
76
        SharedStorageInterface $sharedStorage,
77
        DefaultChannelFactoryInterface $unitedStatesChannelFactory,
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $unitedStatesChannelFactory exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
78
        DefaultChannelFactoryInterface $defaultChannelFactory,
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $defaultChannelFactory exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
79
        ChannelFactoryInterface $channelFactory,
80
        ChannelRepositoryInterface $channelRepository,
81
        ObjectManager $channelManager,
82
        CurrencyStorageInterface $currencyStorage
83
    ) {
84
        $this->sharedStorage = $sharedStorage;
85
        $this->unitedStatesChannelFactory = $unitedStatesChannelFactory;
86
        $this->defaultChannelFactory = $defaultChannelFactory;
87
        $this->channelFactory = $channelFactory;
88
        $this->channelRepository = $channelRepository;
89
        $this->channelManager = $channelManager;
90
        $this->currencyStorage = $currencyStorage;
91
    }
92
93
    /**
94
     * @Given the store operates on a single channel in "United States"
95
     */
96
    public function storeOperatesOnASingleChannelInUnitedStates()
97
    {
98
        $defaultData = $this->unitedStatesChannelFactory->create();
99
100
        $this->sharedStorage->setClipboard($defaultData);
101
        $this->sharedStorage->set('channel', $defaultData['channel']);
102
    }
103
104
    /**
105
     * @Given the store operates on a single channel in the "United States" named :channelIdentifier
106
     */
107
    public function storeOperatesOnASingleChannelInTheUnitedStatesNamed($channelIdentifier)
108
    {
109
        $defaultData = $this->unitedStatesChannelFactory->create($channelIdentifier, $channelIdentifier);
110
111
        $this->sharedStorage->setClipboard($defaultData);
112
        $this->sharedStorage->set('channel', $defaultData['channel']);
113
    }
114
115
    /**
116
     * @Given the store operates on a single channel
117
     * @Given the store operates on a single channel in :currencyCode currency
118
     */
119
    public function storeOperatesOnASingleChannel($currencyCode = null)
120
    {
121
        $defaultData = $this->defaultChannelFactory->create(null, null, $currencyCode);
122
123
        $this->sharedStorage->setClipboard($defaultData);
124
        $this->sharedStorage->set('channel', $defaultData['channel']);
125
    }
126
127
    /**
128
     * @Given /^the store(?:| also) operates on (?:a|another) channel named "([^"]+)"$/
129
     * @Given /^the store(?:| also) operates on (?:a|another) channel named "([^"]+)" in "([^"]+)" currency$/
130
     * @Given the store operates on a channel identified by :code code
131
     */
132
    public function theStoreOperatesOnAChannelNamed($channelIdentifier, $currencyCode = null)
133
    {
134
        $defaultData = $this->defaultChannelFactory->create($channelIdentifier, $channelIdentifier, $currencyCode);
135
136
        $this->sharedStorage->setClipboard($defaultData);
137
        $this->sharedStorage->set('channel', $defaultData['channel']);
138
        $this->currencyStorage->set($defaultData['channel'], $defaultData['currency']->getCode());
139
    }
140
141
    /**
142
     * @Given the channel :channel is enabled
143
     */
144
    public function theChannelIsEnabled(ChannelInterface $channel)
145
    {
146
        $this->changeChannelState($channel, true);
147
    }
148
149
    /**
150
     * @Given the channel :channel is disabled
151
     * @Given the channel :channel has been disabled
152
     */
153
    public function theChannelIsDisabled(ChannelInterface $channel)
154
    {
155
        $this->changeChannelState($channel, false);
156
    }
157
158
    /**
159
     * @Given channel :channel has been deleted
160
     */
161
    public function iChannelHasBeenDeleted(ChannelInterface $channel)
162
    {
163
        $this->channelRepository->remove($channel);
164
    }
165
166
    /**
167
     * @Given /^(its) default tax zone is (zone "([^"]+)")$/
168
     */
169
    public function itsDefaultTaxRateIs(ChannelInterface $channel, ZoneInterface $defaultTaxZone)
170
    {
171
        $channel->setDefaultTaxZone($defaultTaxZone);
172
        $this->channelManager->flush();
173
    }
174
175
    /**
176
     * @Given /^(this channel) has contact email set as "([^"]+)"$/
177
     * @Given /^(this channel) has no contact email set$/
178
     */
179
    public function thisChannelHasContactEmailSetAs(ChannelInterface $channel, $contactEmail = null)
180
    {
181
        $channel->setContactEmail($contactEmail);
182
        $this->channelManager->flush();
183
    }
184
185
    /**
186
     * @param ChannelInterface $channel
187
     * @param bool $state
188
     */
189
    private function changeChannelState(ChannelInterface $channel, $state)
190
    {
191
        $channel->setEnabled($state);
192
        $this->channelManager->flush();
193
        $this->sharedStorage->set('channel', $channel);
194
    }
195
}
196