Completed
Push — master ( ab7347...117100 )
by Paweł
17:01 queued 07:09
created

onThisChannelShippingStepIsSkippedIfOnlyASingleShippingMethodIsAvailable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
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\Behat\Service\SharedStorageInterface;
17
use Sylius\Component\Addressing\Model\ZoneInterface;
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
23
/**
24
 * @author Arkadiusz Krakowiak <[email protected]>
25
 * @author Mateusz Zalewski <[email protected]>
26
 */
27
final class ChannelContext implements Context
28
{
29
    /**
30
     * @var SharedStorageInterface
31
     */
32
    private $sharedStorage;
33
34
    /**
35
     * @var DefaultChannelFactoryInterface
36
     */
37
    private $unitedStatesChannelFactory;
38
39
    /**
40
     * @var DefaultChannelFactoryInterface
41
     */
42
    private $defaultChannelFactory;
43
44
    /**
45
     * @var ChannelRepositoryInterface
46
     */
47
    private $channelRepository;
48
49
    /**
50
     * @var ObjectManager
51
     */
52
    private $channelManager;
53
54
    /**
55
     * @param SharedStorageInterface $sharedStorage
56
     * @param DefaultChannelFactoryInterface $unitedStatesChannelFactory
57
     * @param DefaultChannelFactoryInterface $defaultChannelFactory
58
     * @param ChannelRepositoryInterface $channelRepository
59
     * @param ObjectManager $channelManager
60
     */
61
    public function __construct(
62
        SharedStorageInterface $sharedStorage,
63
        DefaultChannelFactoryInterface $unitedStatesChannelFactory,
64
        DefaultChannelFactoryInterface $defaultChannelFactory,
65
        ChannelRepositoryInterface $channelRepository,
66
        ObjectManager $channelManager
67
    ) {
68
        $this->sharedStorage = $sharedStorage;
69
        $this->unitedStatesChannelFactory = $unitedStatesChannelFactory;
70
        $this->defaultChannelFactory = $defaultChannelFactory;
71
        $this->channelRepository = $channelRepository;
72
        $this->channelManager = $channelManager;
73
    }
74
75
    /**
76
     * @Given the store operates on a single channel in "United States"
77
     */
78
    public function storeOperatesOnASingleChannelInUnitedStates()
79
    {
80
        $defaultData = $this->unitedStatesChannelFactory->create();
81
82
        $this->sharedStorage->setClipboard($defaultData);
83
        $this->sharedStorage->set('channel', $defaultData['channel']);
84
    }
85
86
    /**
87
     * @Given the store operates on a single channel in the "United States" named :channelIdentifier
88
     */
89
    public function storeOperatesOnASingleChannelInTheUnitedStatesNamed($channelIdentifier)
90
    {
91
        $defaultData = $this->unitedStatesChannelFactory->create($channelIdentifier, $channelIdentifier);
92
93
        $this->sharedStorage->setClipboard($defaultData);
94
        $this->sharedStorage->set('channel', $defaultData['channel']);
95
    }
96
97
    /**
98
     * @Given the store operates on a single channel
99
     * @Given the store operates on a single channel in :currencyCode currency
100
     */
101
    public function storeOperatesOnASingleChannel($currencyCode = null)
102
    {
103
        $defaultData = $this->defaultChannelFactory->create(null, null, $currencyCode);
104
105
        $this->sharedStorage->setClipboard($defaultData);
106
        $this->sharedStorage->set('channel', $defaultData['channel']);
107
    }
108
109
    /**
110
     * @Given /^the store(?:| also) operates on (?:a|another) channel named "([^"]+)"$/
111
     * @Given /^the store(?:| also) operates on (?:a|another) channel named "([^"]+)" in "([^"]+)" currency$/
112
     * @Given the store operates on a channel identified by :code code
113
     */
114
    public function theStoreOperatesOnAChannelNamed($channelIdentifier, $currencyCode = null)
115
    {
116
        $defaultData = $this->defaultChannelFactory->create($channelIdentifier, $channelIdentifier, $currencyCode);
117
118
        $this->sharedStorage->setClipboard($defaultData);
119
        $this->sharedStorage->set('channel', $defaultData['channel']);
120
    }
121
122
    /**
123
     * @Given the channel :channel is enabled
124
     */
125
    public function theChannelIsEnabled(ChannelInterface $channel)
126
    {
127
        $this->changeChannelState($channel, true);
128
    }
129
130
    /**
131
     * @Given the channel :channel is disabled
132
     * @Given the channel :channel has been disabled
133
     */
134
    public function theChannelIsDisabled(ChannelInterface $channel)
135
    {
136
        $this->changeChannelState($channel, false);
137
    }
138
139
    /**
140
     * @Given channel :channel has been deleted
141
     */
142
    public function iChannelHasBeenDeleted(ChannelInterface $channel)
143
    {
144
        $this->channelRepository->remove($channel);
145
    }
146
147
    /**
148
     * @Given /^(its) default tax zone is (zone "([^"]+)")$/
149
     */
150
    public function itsDefaultTaxRateIs(ChannelInterface $channel, ZoneInterface $defaultTaxZone)
151
    {
152
        $channel->setDefaultTaxZone($defaultTaxZone);
153
        $this->channelManager->flush();
154
    }
155
156
    /**
157
     * @Given /^(this channel) has contact email set as "([^"]+)"$/
158
     * @Given /^(this channel) has no contact email set$/
159
     */
160
    public function thisChannelHasContactEmailSetAs(ChannelInterface $channel, $contactEmail = null)
161
    {
162
        $channel->setContactEmail($contactEmail);
163
        $this->channelManager->flush();
164
    }
165
166
    /**
167
     * @param ChannelInterface $channel
168
     * @param bool $state
169
     */
170
    private function changeChannelState(ChannelInterface $channel, $state)
171
    {
172
        $channel->setEnabled($state);
173
        $this->channelManager->flush();
174
        $this->sharedStorage->set('channel', $channel);
175
    }
176
177
    /**
178
     * @Given /^on (this channel) shipping step is skipped if only a single shipping method is available$/
179
     */
180
    public function onThisChannelShippingStepIsSkippedIfOnlyASingleShippingMethodIsAvailable(ChannelInterface $channel)
181
    {
182
        $channel->setSkippingShippingStepAllowed(true);
183
184
        $this->channelManager->flush();
185
    }
186
}
187