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\Api\Admin; |
15
|
|
|
|
16
|
|
|
use ApiPlatform\Core\Api\IriConverterInterface; |
17
|
|
|
use Behat\Behat\Context\Context; |
18
|
|
|
use Sylius\Behat\Client\ApiClientInterface; |
19
|
|
|
use Sylius\Behat\Client\ResponseCheckerInterface; |
20
|
|
|
use Sylius\Component\Addressing\Model\CountryInterface; |
21
|
|
|
use Sylius\Component\Core\Formatter\StringInflector; |
22
|
|
|
use Sylius\Component\Core\Model\ChannelInterface; |
23
|
|
|
use Sylius\Component\Core\Model\TaxonInterface; |
24
|
|
|
use Sylius\Component\Currency\Model\CurrencyInterface; |
25
|
|
|
use Sylius\Component\Locale\Model\LocaleInterface; |
26
|
|
|
use Webmozart\Assert\Assert; |
27
|
|
|
|
28
|
|
|
final class ManagingChannelsContext implements Context |
29
|
|
|
{ |
30
|
|
|
/** @var ApiClientInterface */ |
31
|
|
|
private $client; |
32
|
|
|
|
33
|
|
|
/** @var ResponseCheckerInterface */ |
34
|
|
|
private $responseChecker; |
35
|
|
|
|
36
|
|
|
/** @var IriConverterInterface */ |
37
|
|
|
private $iriConverter; |
38
|
|
|
|
39
|
|
|
/** @var array */ |
40
|
|
|
private $shopBillingData = []; |
41
|
|
|
|
42
|
|
|
public function __construct( |
43
|
|
|
ApiClientInterface $client, |
44
|
|
|
ResponseCheckerInterface $responseChecker, |
45
|
|
|
IriConverterInterface $iriConverter |
46
|
|
|
) { |
47
|
|
|
$this->client = $client; |
48
|
|
|
$this->responseChecker = $responseChecker; |
49
|
|
|
$this->iriConverter = $iriConverter; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @When I want to create a new channel |
54
|
|
|
*/ |
55
|
|
|
public function iWantToCreateANewChannel(): void |
56
|
|
|
{ |
57
|
|
|
$this->client->buildCreateRequest(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @When I specify its :field as :value |
62
|
|
|
* @When I :field it :value |
63
|
|
|
* @When I set its :field as :value |
64
|
|
|
* @When I define its :field as :value |
65
|
|
|
*/ |
66
|
|
|
public function iSpecifyItsAs(string $field, string $value): void |
67
|
|
|
{ |
68
|
|
|
$this->client->addRequestData($field, $value); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @When I choose :currency as the base currency |
73
|
|
|
*/ |
74
|
|
|
public function iChooseAsTheBaseCurrency(CurrencyInterface $currency): void |
75
|
|
|
{ |
76
|
|
|
$this->client->addRequestData('baseCurrency', $this->iriConverter->getIriFromItem($currency)); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @When I choose :locale as a default locale |
81
|
|
|
*/ |
82
|
|
|
public function iChooseAsADefaultLocale(LocaleInterface $locale): void |
83
|
|
|
{ |
84
|
|
|
$this->client->addRequestData('defaultLocale', $this->iriConverter->getIriFromItem($locale)); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @When I describe it as :description |
89
|
|
|
*/ |
90
|
|
|
public function iDescribeItAs(string $description): void |
91
|
|
|
{ |
92
|
|
|
$this->client->addRequestData('description', $description); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @When I set its contact email as :contactEmail |
97
|
|
|
*/ |
98
|
|
|
public function iSetItsContactEmailAs(string $contactEmail): void |
99
|
|
|
{ |
100
|
|
|
$this->client->addRequestData('contactEmail', $contactEmail); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @When I choose :country and :otherCountry as operating countries |
105
|
|
|
*/ |
106
|
|
|
public function iChooseAndAsOperatingCountries(CountryInterface $country, CountryInterface $otherCountry): void |
107
|
|
|
{ |
108
|
|
|
$this->client->addRequestData('countries', [ |
109
|
|
|
$this->iriConverter->getIriFromItem($country), |
110
|
|
|
$this->iriConverter->getIriFromItem($otherCountry), |
111
|
|
|
]); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @When I allow to skip shipping step if only one shipping method is available |
116
|
|
|
*/ |
117
|
|
|
public function iAllowToSkipShippingStepIfOnlyOneShippingMethodIsAvailable(): void |
118
|
|
|
{ |
119
|
|
|
$this->client->addRequestData('skippingShippingStepAllowed', true); |
|
|
|
|
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @When I allow to skip payment step if only one payment method is available |
124
|
|
|
*/ |
125
|
|
|
public function iAllowToSkipPaymentStepIfOnlyOnePaymentMethodIsAvailable(): void |
126
|
|
|
{ |
127
|
|
|
$this->client->addRequestData('skippingPaymentStepAllowed', true); |
|
|
|
|
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @When I specify menu taxon as :taxon |
132
|
|
|
*/ |
133
|
|
|
public function iSpecifyMenuTaxonAs(TaxonInterface $taxon): void |
134
|
|
|
{ |
135
|
|
|
$this->client->addRequestData('menuTaxon', $this->iriConverter->getIriFromItem($taxon)); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @When I specify company as :company |
140
|
|
|
*/ |
141
|
|
|
public function iSpecifyCompanyAs(string $company): void |
142
|
|
|
{ |
143
|
|
|
$this->shopBillingData['company'] = $company; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @When I specify tax ID as :taxId |
148
|
|
|
*/ |
149
|
|
|
public function iSpecifyTaxIdAs(string $taxId): void |
150
|
|
|
{ |
151
|
|
|
$this->shopBillingData['taxId'] = $taxId; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @When I specify shop billing address as :street, :postcode :city, :country |
156
|
|
|
*/ |
157
|
|
|
public function specifyShopBillingAddressAs( |
158
|
|
|
string $street, |
159
|
|
|
string $postcode, |
160
|
|
|
string $city, |
161
|
|
|
CountryInterface $country |
162
|
|
|
): void { |
163
|
|
|
$this->shopBillingData['street'] = $street; |
164
|
|
|
$this->shopBillingData['city'] = $city; |
165
|
|
|
$this->shopBillingData['postcode'] = $postcode; |
166
|
|
|
$this->shopBillingData['countryCode'] = $country->getCode(); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* @When I select the :taxCalculationStrategy as tax calculation strategy |
171
|
|
|
*/ |
172
|
|
|
public function iSelectTaxCalculationStrategy(string $taxCalculationStrategy): void |
173
|
|
|
{ |
174
|
|
|
$this->client->addRequestData('taxCalculationStrategy', StringInflector::nameToLowercaseCode($taxCalculationStrategy)); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @When I add it |
179
|
|
|
*/ |
180
|
|
|
public function iAddIt(): void |
181
|
|
|
{ |
182
|
|
|
$this->client->addSubResourceData('shopBillingData', $this->shopBillingData); |
183
|
|
|
|
184
|
|
|
$this->client->create(); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* @When I want to browse channels |
189
|
|
|
*/ |
190
|
|
|
public function iWantToBrowseChannels(): void |
191
|
|
|
{ |
192
|
|
|
$this->client->index(); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* @Then I should be notified that it has been successfully created |
197
|
|
|
*/ |
198
|
|
|
public function iShouldBeNotifiedThatItHasBeenSuccessfullyCreated(): void |
199
|
|
|
{ |
200
|
|
|
Assert::true( |
201
|
|
|
$this->responseChecker->isCreationSuccessful($this->client->getLastResponse()), |
202
|
|
|
'Channel could not be created' |
203
|
|
|
); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* @Then the channel :name should appear in the registry |
208
|
|
|
* @Then the channel :name should be in the registry |
209
|
|
|
*/ |
210
|
|
|
public function theChannelShouldAppearInTheRegistry(string $name): void |
211
|
|
|
{ |
212
|
|
|
Assert::true( |
213
|
|
|
$this->responseChecker->hasItemWithValue($this->client->index(), 'name', $name), |
214
|
|
|
sprintf('Channel with name %s does not exist', $name) |
215
|
|
|
); |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* @Then the channel :channel should have :taxon as a menu taxon |
220
|
|
|
*/ |
221
|
|
|
public function theChannelShouldHaveAsAMenuTaxon(ChannelInterface $channel, TaxonInterface $taxon): void |
222
|
|
|
{ |
223
|
|
|
Assert::same( |
224
|
|
|
$this->responseChecker->getValue($this->client->show($channel->getCode()), 'menuTaxon'), |
225
|
|
|
$this->iriConverter->getIriFromItem($taxon), |
226
|
|
|
sprintf('Channel %s does not have %s menu taxon', $channel->getName(), $taxon->getName()) |
227
|
|
|
); |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* @Then I should see :count channels in the list |
232
|
|
|
*/ |
233
|
|
|
public function iShouldSeeChannelsInTheList(int $count): void |
234
|
|
|
{ |
235
|
|
|
Assert::same($this->responseChecker->countCollectionItems($this->client->getLastResponse()), $count); |
236
|
|
|
} |
237
|
|
|
} |
238
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: