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\Ui\Shop; |
15
|
|
|
|
16
|
|
|
use Behat\Behat\Context\Context; |
17
|
|
|
use Sylius\Behat\Context\Ui\Shop\Checkout\CheckoutAddressingContext; |
18
|
|
|
use Sylius\Behat\Context\Ui\Shop\Checkout\CheckoutPaymentContext; |
19
|
|
|
use Sylius\Behat\Context\Ui\Shop\Checkout\CheckoutShippingContext; |
20
|
|
|
use Sylius\Behat\Page\Shop\Account\LoginPageInterface; |
21
|
|
|
use Sylius\Behat\Page\Shop\Account\RegisterPageInterface; |
22
|
|
|
use Sylius\Behat\Page\Shop\Checkout\AddressPageInterface; |
23
|
|
|
use Sylius\Behat\Page\Shop\Checkout\CompletePageInterface; |
24
|
|
|
use Sylius\Behat\Page\Shop\Checkout\SelectPaymentPageInterface; |
25
|
|
|
use Sylius\Behat\Page\Shop\Checkout\SelectShippingPageInterface; |
26
|
|
|
use Sylius\Behat\Page\UnexpectedPageException; |
27
|
|
|
use Sylius\Behat\Service\Resolver\CurrentPageResolverInterface; |
28
|
|
|
use Sylius\Component\Addressing\Model\CountryInterface; |
29
|
|
|
use Webmozart\Assert\Assert; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @author Arkadiusz Krakowiak <[email protected]> |
33
|
|
|
*/ |
34
|
|
|
final class CheckoutContext implements Context |
35
|
|
|
{ |
36
|
|
|
/** |
37
|
|
|
* @var AddressPageInterface |
38
|
|
|
*/ |
39
|
|
|
private $addressPage; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var SelectPaymentPageInterface |
43
|
|
|
*/ |
44
|
|
|
private $selectPaymentPage; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var SelectShippingPageInterface |
48
|
|
|
*/ |
49
|
|
|
private $selectShippingPage; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @var CompletePageInterface |
53
|
|
|
*/ |
54
|
|
|
private $completePage; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @var RegisterPageInterface |
58
|
|
|
*/ |
59
|
|
|
private $registerPage; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @var CurrentPageResolverInterface |
63
|
|
|
*/ |
64
|
|
|
private $currentPageResolver; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @var CheckoutAddressingContext |
68
|
|
|
*/ |
69
|
|
|
private $addressingContext; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @var CheckoutShippingContext |
73
|
|
|
*/ |
74
|
|
|
private $shippingContext; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @var CheckoutPaymentContext |
78
|
|
|
*/ |
79
|
|
|
private $paymentContext; |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param AddressPageInterface $addressPage |
83
|
|
|
* @param SelectPaymentPageInterface $selectPaymentPage |
84
|
|
|
* @param SelectShippingPageInterface $selectShippingPage |
85
|
|
|
* @param CompletePageInterface $completePage |
86
|
|
|
* @param RegisterPageInterface $registerPage |
87
|
|
|
* @param CurrentPageResolverInterface $currentPageResolver |
88
|
|
|
* @param CheckoutAddressingContext $addressingContext |
89
|
|
|
* @param CheckoutShippingContext $shippingContext |
90
|
|
|
* @param CheckoutPaymentContext $paymentContext |
91
|
|
|
*/ |
92
|
|
|
public function __construct( |
93
|
|
|
AddressPageInterface $addressPage, |
94
|
|
|
SelectPaymentPageInterface $selectPaymentPage, |
95
|
|
|
SelectShippingPageInterface $selectShippingPage, |
96
|
|
|
CompletePageInterface $completePage, |
97
|
|
|
RegisterPageInterface $registerPage, |
98
|
|
|
CurrentPageResolverInterface $currentPageResolver, |
99
|
|
|
CheckoutAddressingContext $addressingContext, |
100
|
|
|
CheckoutShippingContext $shippingContext, |
101
|
|
|
CheckoutPaymentContext $paymentContext |
102
|
|
|
) { |
103
|
|
|
$this->addressPage = $addressPage; |
104
|
|
|
$this->selectPaymentPage = $selectPaymentPage; |
105
|
|
|
$this->selectShippingPage = $selectShippingPage; |
106
|
|
|
$this->completePage = $completePage; |
107
|
|
|
$this->registerPage = $registerPage; |
108
|
|
|
$this->currentPageResolver = $currentPageResolver; |
109
|
|
|
$this->addressingContext = $addressingContext; |
110
|
|
|
$this->shippingContext = $shippingContext; |
111
|
|
|
$this->paymentContext = $paymentContext; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @Given I was at the checkout summary step |
116
|
|
|
*/ |
117
|
|
|
public function iWasAtTheCheckoutSummaryStep() |
118
|
|
|
{ |
119
|
|
|
$this->addressingContext->iSpecifiedTheShippingAddress(); |
120
|
|
|
$this->iProceedOrderWithShippingMethodAndPayment('Free', 'Offline'); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @Given I chose :shippingMethodName shipping method |
125
|
|
|
* @When I proceed selecting :shippingMethodName shipping method |
126
|
|
|
*/ |
127
|
|
|
public function iProceedSelectingShippingMethod($shippingMethodName) |
128
|
|
|
{ |
129
|
|
|
$this->iProceedSelectingShippingCountryAndShippingMethod(null, $shippingMethodName); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @Given I have proceeded selecting :paymentMethodName payment method |
134
|
|
|
* @When I proceed selecting :paymentMethodName payment method |
135
|
|
|
*/ |
136
|
|
|
public function iProceedSelectingPaymentMethod($paymentMethodName) |
137
|
|
|
{ |
138
|
|
|
$this->iProceedSelectingShippingCountryAndShippingMethod(); |
139
|
|
|
$this->paymentContext->iChoosePaymentMethod($paymentMethodName); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @Given I have proceeded order with :shippingMethodName shipping method and :paymentMethodName payment |
144
|
|
|
* @When I proceed with :shippingMethodName shipping method and :paymentMethodName payment |
145
|
|
|
*/ |
146
|
|
|
public function iProceedOrderWithShippingMethodAndPayment($shippingMethodName, $paymentMethodName) |
147
|
|
|
{ |
148
|
|
|
$this->shippingContext->iHaveProceededSelectingShippingMethod($shippingMethodName); |
149
|
|
|
$this->paymentContext->iChoosePaymentMethod($paymentMethodName); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @When I proceed through checkout process |
154
|
|
|
* @When I proceed through checkout process in the :localeCode locale |
155
|
|
|
*/ |
156
|
|
|
public function iProceedThroughCheckoutProcess($localeCode = 'en_US') |
157
|
|
|
{ |
158
|
|
|
$this->addressingContext->iProceedSelectingShippingCountry(null, $localeCode); |
159
|
|
|
$this->shippingContext->iCompleteTheShippingStep(); |
160
|
|
|
$this->paymentContext->iCompleteThePaymentStep(); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* @When /^I proceed selecting ("[^"]+" as shipping country) with "([^"]+)" method$/ |
165
|
|
|
*/ |
166
|
|
|
public function iProceedSelectingShippingCountryAndShippingMethod(CountryInterface $shippingCountry = null, $shippingMethodName = null) |
167
|
|
|
{ |
168
|
|
|
$this->addressingContext->iProceedSelectingShippingCountry($shippingCountry); |
169
|
|
|
$this->shippingContext->iHaveProceededSelectingShippingMethod($shippingMethodName ?: 'Free'); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @When /^I change shipping method to "([^"]*)"$/ |
174
|
|
|
*/ |
175
|
|
|
public function iChangeShippingMethod($shippingMethodName) |
176
|
|
|
{ |
177
|
|
|
$this->paymentContext->iDecideToChangeMyShippingMethod(); |
178
|
|
|
$this->shippingContext->iHaveProceededSelectingShippingMethod($shippingMethodName); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* @When I go to the addressing step |
183
|
|
|
*/ |
184
|
|
|
public function iGoToTheAddressingStep() |
185
|
|
|
{ |
186
|
|
|
if ($this->selectShippingPage->isOpen()) { |
187
|
|
|
$this->selectShippingPage->changeAddressByStepLabel(); |
188
|
|
|
|
189
|
|
|
return; |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
if ($this->selectPaymentPage->isOpen()) { |
193
|
|
|
$this->selectPaymentPage->changeAddressByStepLabel(); |
194
|
|
|
|
195
|
|
|
return; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
if ($this->completePage->isOpen()) { |
199
|
|
|
$this->completePage->changeAddress(); |
200
|
|
|
|
201
|
|
|
return; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
throw new UnexpectedPageException('It is impossible to go to addressing step from current page.'); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* @When I go to the shipping step |
209
|
|
|
*/ |
210
|
|
|
public function iGoToTheShippingStep() |
211
|
|
|
{ |
212
|
|
|
if ($this->selectPaymentPage->isOpen()) { |
213
|
|
|
$this->selectPaymentPage->changeShippingMethodByStepLabel(); |
214
|
|
|
|
215
|
|
|
return; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
if ($this->completePage->isOpen()) { |
219
|
|
|
$this->completePage->changeShippingMethod(); |
220
|
|
|
|
221
|
|
|
return; |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
throw new UnexpectedPageException('It is impossible to go to shipping step from current page.'); |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* @Then the subtotal of :item item should be :price |
229
|
|
|
*/ |
230
|
|
|
public function theSubtotalOfItemShouldBe($item, $price) |
231
|
|
|
{ |
232
|
|
|
/** @var AddressPageInterface|SelectPaymentPageInterface|SelectShippingPageInterface|CompletePageInterface $currentPage */ |
233
|
|
|
$currentPage = $this->currentPageResolver->getCurrentPageWithForm([ |
234
|
|
|
$this->addressPage, |
235
|
|
|
$this->selectPaymentPage, |
236
|
|
|
$this->selectShippingPage, |
237
|
|
|
$this->completePage, |
238
|
|
|
]); |
239
|
|
|
|
240
|
|
|
Assert::eq($currentPage->getItemSubtotal($item), $price); |
|
|
|
|
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
/** |
244
|
|
|
* @When I register with previously used :email email and :password password |
245
|
|
|
*/ |
246
|
|
|
public function iRegisterWithPreviouslyUsedEmailAndPassword(string $email, string $password): void |
247
|
|
|
{ |
248
|
|
|
$this->registerPage->open(); |
249
|
|
|
$this->registerPage->specifyEmail($email); |
250
|
|
|
$this->registerPage->specifyPassword($password); |
251
|
|
|
$this->registerPage->verifyPassword($password); |
252
|
|
|
$this->registerPage->specifyFirstName('Carrot'); |
253
|
|
|
$this->registerPage->specifyLastName('Ironfoundersson'); |
254
|
|
|
$this->registerPage->register(); |
255
|
|
|
} |
256
|
|
|
} |
257
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: