Completed
Push — pull-request/8646 ( c68392 )
by Kamil
29:42
created

ChannelContext   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 192
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 6

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 15
c 2
b 0
f 0
lcom 2
cbo 6
dl 0
loc 192
rs 10

15 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 1
A channelHasAccountVerificationDisabled() 0 6 1
A storeOperatesOnASingleChannelInUnitedStates() 0 7 1
A storeOperatesOnASingleChannelInTheUnitedStatesNamed() 0 7 1
A storeOperatesOnASingleChannel() 0 7 1
A theStoreOperatesOnAChannelNamed() 0 8 1
A theChannelIsEnabled() 0 4 1
A theChannelIsDisabled() 0 4 1
A iChannelHasBeenDeleted() 0 4 1
A itsDefaultTaxRateIs() 0 5 1
A thisChannelHasContactEmailSetAs() 0 5 1
A onThisChannelShippingStepIsSkippedIfOnlyASingleShippingMethodIsAvailable() 0 6 1
A onThisChannelPaymentStepIsSkippedIfOnlyASinglePaymentMethodIsAvailable() 0 7 1
A onThisChannelAccountVerificationIsNotRequired() 0 6 1
A changeChannelState() 0 6 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
declare(strict_types=1);
13
14
namespace Sylius\Behat\Context\Setup;
15
16
use Behat\Behat\Context\Context;
17
use Doctrine\Common\Persistence\ObjectManager;
18
use Sylius\Behat\Service\SharedStorageInterface;
19
use Sylius\Component\Addressing\Model\ZoneInterface;
20
use Sylius\Component\Channel\Repository\ChannelRepositoryInterface;
21
use Sylius\Component\Core\Formatter\StringInflector;
22
use Sylius\Component\Core\Model\ChannelInterface;
23
use Sylius\Component\Core\Test\Services\DefaultChannelFactoryInterface;
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 ChannelRepositoryInterface
48
     */
49
    private $channelRepository;
50
51
    /**
52
     * @var ObjectManager
53
     */
54
    private $channelManager;
55
56
    /**
57
     * @param SharedStorageInterface $sharedStorage
58
     * @param DefaultChannelFactoryInterface $unitedStatesChannelFactory
59
     * @param DefaultChannelFactoryInterface $defaultChannelFactory
60
     * @param ChannelRepositoryInterface $channelRepository
61
     * @param ObjectManager $channelManager
62
     */
63
    public function __construct(
64
        SharedStorageInterface $sharedStorage,
65
        DefaultChannelFactoryInterface $unitedStatesChannelFactory,
66
        DefaultChannelFactoryInterface $defaultChannelFactory,
67
        ChannelRepositoryInterface $channelRepository,
68
        ObjectManager $channelManager
69
    ) {
70
        $this->sharedStorage = $sharedStorage;
71
        $this->unitedStatesChannelFactory = $unitedStatesChannelFactory;
72
        $this->defaultChannelFactory = $defaultChannelFactory;
73
        $this->channelRepository = $channelRepository;
74
        $this->channelManager = $channelManager;
75
    }
76
77
    /**
78
     * @Given :channel channel has account verification disabled
79
     */
80
    public function channelHasAccountVerificationDisabled(ChannelInterface $channel): void
81
    {
82
        $channel->setAccountVerificationRequired(false);
83
84
        $this->channelManager->flush();
85
    }
86
87
    /**
88
     * @Given the store operates on a single channel in "United States"
89
     */
90
    public function storeOperatesOnASingleChannelInUnitedStates()
91
    {
92
        $defaultData = $this->unitedStatesChannelFactory->create();
93
94
        $this->sharedStorage->setClipboard($defaultData);
95
        $this->sharedStorage->set('channel', $defaultData['channel']);
96
    }
97
98
    /**
99
     * @Given the store operates on a single channel in the "United States" named :channelIdentifier
100
     */
101
    public function storeOperatesOnASingleChannelInTheUnitedStatesNamed($channelIdentifier)
102
    {
103
        $defaultData = $this->unitedStatesChannelFactory->create($channelIdentifier, $channelIdentifier);
104
105
        $this->sharedStorage->setClipboard($defaultData);
106
        $this->sharedStorage->set('channel', $defaultData['channel']);
107
    }
108
109
    /**
110
     * @Given the store operates on a single channel
111
     * @Given the store operates on a single channel in :currencyCode currency
112
     */
113
    public function storeOperatesOnASingleChannel($currencyCode = null)
114
    {
115
        $defaultData = $this->defaultChannelFactory->create(null, null, $currencyCode);
116
117
        $this->sharedStorage->setClipboard($defaultData);
118
        $this->sharedStorage->set('channel', $defaultData['channel']);
119
    }
120
121
    /**
122
     * @Given /^the store(?:| also) operates on (?:a|another) channel named "([^"]+)"$/
123
     * @Given /^the store(?:| also) operates on (?:a|another) channel named "([^"]+)" in "([^"]+)" currency$/
124
     * @Given the store operates on a channel identified by :code code
125
     */
126
    public function theStoreOperatesOnAChannelNamed($channelName, $currencyCode = null)
127
    {
128
        $channelCode = StringInflector::nameToLowercaseCode($channelName);
129
        $defaultData = $this->defaultChannelFactory->create($channelCode, $channelName, $currencyCode);
130
131
        $this->sharedStorage->setClipboard($defaultData);
132
        $this->sharedStorage->set('channel', $defaultData['channel']);
133
    }
134
135
    /**
136
     * @Given the channel :channel is enabled
137
     */
138
    public function theChannelIsEnabled(ChannelInterface $channel)
139
    {
140
        $this->changeChannelState($channel, true);
141
    }
142
143
    /**
144
     * @Given the channel :channel is disabled
145
     * @Given the channel :channel has been disabled
146
     */
147
    public function theChannelIsDisabled(ChannelInterface $channel)
148
    {
149
        $this->changeChannelState($channel, false);
150
    }
151
152
    /**
153
     * @Given channel :channel has been deleted
154
     */
155
    public function iChannelHasBeenDeleted(ChannelInterface $channel)
156
    {
157
        $this->channelRepository->remove($channel);
158
    }
159
160
    /**
161
     * @Given /^(its) default tax zone is (zone "([^"]+)")$/
162
     */
163
    public function itsDefaultTaxRateIs(ChannelInterface $channel, ZoneInterface $defaultTaxZone)
164
    {
165
        $channel->setDefaultTaxZone($defaultTaxZone);
166
        $this->channelManager->flush();
167
    }
168
169
    /**
170
     * @Given /^(this channel) has contact email set as "([^"]+)"$/
171
     * @Given /^(this channel) has no contact email set$/
172
     */
173
    public function thisChannelHasContactEmailSetAs(ChannelInterface $channel, $contactEmail = null)
174
    {
175
        $channel->setContactEmail($contactEmail);
176
        $this->channelManager->flush();
177
    }
178
179
    /**
180
     * @Given /^on (this channel) shipping step is skipped if only a single shipping method is available$/
181
     */
182
    public function onThisChannelShippingStepIsSkippedIfOnlyASingleShippingMethodIsAvailable(ChannelInterface $channel)
183
    {
184
        $channel->setSkippingShippingStepAllowed(true);
185
186
        $this->channelManager->flush();
187
    }
188
189
    /**
190
     * @Given /^on (this channel) payment step is skipped if only a single payment method is available$/
191
     */
192
    public function onThisChannelPaymentStepIsSkippedIfOnlyASinglePaymentMethodIsAvailable(
193
        ChannelInterface $channel
194
    ) {
195
        $channel->setSkippingPaymentStepAllowed(true);
196
197
        $this->channelManager->flush();
198
    }
199
200
    /**
201
     * @Given /^on (this channel) account verification is not required$/
202
     */
203
    public function onThisChannelAccountVerificationIsNotRequired(ChannelInterface $channel)
204
    {
205
        $channel->setAccountVerificationRequired(false);
206
207
        $this->channelManager->flush();
208
    }
209
210
    /**
211
     * @param ChannelInterface $channel
212
     * @param bool $state
213
     */
214
    private function changeChannelState(ChannelInterface $channel, $state)
215
    {
216
        $channel->setEnabled($state);
217
        $this->channelManager->flush();
218
        $this->sharedStorage->set('channel', $channel);
219
    }
220
}
221