1 | <?php |
||
30 | final class AccountContext implements Context |
||
31 | { |
||
32 | /** |
||
33 | * @var DashboardPageInterface |
||
34 | */ |
||
35 | private $dashboardPage; |
||
36 | |||
37 | /** |
||
38 | * @var ProfileUpdatePageInterface |
||
39 | */ |
||
40 | private $profileUpdatePage; |
||
41 | |||
42 | /** |
||
43 | * @var ChangePasswordPageInterface |
||
44 | */ |
||
45 | private $changePasswordPage; |
||
46 | |||
47 | /** |
||
48 | * @var IndexPageInterface |
||
49 | */ |
||
50 | private $orderIndexPage; |
||
51 | |||
52 | /** |
||
53 | * @var ShowPageInterface |
||
54 | */ |
||
55 | private $orderShowPage; |
||
56 | |||
57 | /** |
||
58 | * @var NotificationCheckerInterface |
||
59 | */ |
||
60 | private $notificationChecker; |
||
61 | |||
62 | /** |
||
63 | * @param DashboardPageInterface $dashboardPage |
||
64 | * @param ProfileUpdatePageInterface $profileUpdatePage |
||
65 | * @param ChangePasswordPageInterface $changePasswordPage |
||
66 | * @param IndexPageInterface $orderIndexPage |
||
67 | * @param ShowPageInterface $orderShowPage |
||
68 | * @param NotificationCheckerInterface $notificationChecker |
||
69 | */ |
||
70 | public function __construct( |
||
71 | DashboardPageInterface $dashboardPage, |
||
72 | ProfileUpdatePageInterface $profileUpdatePage, |
||
73 | ChangePasswordPageInterface $changePasswordPage, |
||
74 | IndexPageInterface $orderIndexPage, |
||
75 | ShowPageInterface $orderShowPage, |
||
76 | NotificationCheckerInterface $notificationChecker |
||
77 | ) { |
||
78 | $this->dashboardPage = $dashboardPage; |
||
79 | $this->profileUpdatePage = $profileUpdatePage; |
||
80 | $this->changePasswordPage = $changePasswordPage; |
||
81 | $this->orderIndexPage = $orderIndexPage; |
||
82 | $this->orderShowPage = $orderShowPage; |
||
83 | $this->notificationChecker = $notificationChecker; |
||
84 | } |
||
85 | |||
86 | /** |
||
87 | * @Given I want to modify my profile |
||
88 | */ |
||
89 | public function iWantToModifyMyProfile() |
||
93 | |||
94 | /** |
||
95 | * @When I specify the first name as :firstName |
||
96 | * @When I remove the first name |
||
97 | */ |
||
98 | public function iSpecifyTheFirstName($firstName = null) |
||
102 | |||
103 | /** |
||
104 | * @When I specify the last name as :lastName |
||
105 | * @When I remove the last name |
||
106 | */ |
||
107 | public function iSpecifyTheLastName($lastName = null) |
||
111 | |||
112 | /** |
||
113 | * @When I specify the email as :email |
||
114 | * @When I remove the email |
||
115 | */ |
||
116 | public function iSpecifyTheEmail($email = null) |
||
120 | |||
121 | /** |
||
122 | * @When I save my changes |
||
123 | * @When I try to save my changes |
||
124 | */ |
||
125 | public function iSaveMyChanges() |
||
129 | |||
130 | /** |
||
131 | * @Then I should be notified that it has been successfully edited |
||
132 | */ |
||
133 | public function iShouldBeNotifiedThatItHasBeenSuccessfullyEdited() |
||
137 | |||
138 | /** |
||
139 | * @Then my name should be :name |
||
140 | * @Then my name should still be :name |
||
141 | */ |
||
142 | public function myNameShouldBe($name) |
||
151 | |||
152 | /** |
||
153 | * @Then my email should be :email |
||
154 | * @Then my email should still be :email |
||
155 | */ |
||
156 | public function myEmailShouldBe($email) |
||
165 | |||
166 | /** |
||
167 | * @Then /^I should be notified that the ([^"]+) is required$/ |
||
168 | */ |
||
169 | public function iShouldBeNotifiedThatElementIsRequired($element) |
||
173 | |||
174 | /** |
||
175 | * @Then /^I should be notified that the ([^"]+) is invalid$/ |
||
176 | */ |
||
177 | public function iShouldBeNotifiedThatElementIsInvalid($element) |
||
181 | |||
182 | /** |
||
183 | * @Then I should be notified that the email is already used |
||
184 | */ |
||
185 | public function iShouldBeNotifiedThatTheEmailIsAlreadyUsed() |
||
189 | |||
190 | /** |
||
191 | * @Given /^I want to change my password$/ |
||
192 | */ |
||
193 | public function iWantToChangeMyPassword() |
||
197 | |||
198 | /** |
||
199 | * @Given I change password from :oldPassword to :newPassword |
||
200 | */ |
||
201 | public function iChangePasswordTo($oldPassword, $newPassword) |
||
207 | |||
208 | /** |
||
209 | * @Then I should be notified that my password has been successfully changed |
||
210 | */ |
||
211 | public function iShouldBeNotifiedThatMyPasswordHasBeenSuccessfullyChanged() |
||
215 | |||
216 | /** |
||
217 | * @Given I specify the current password as :password |
||
218 | */ |
||
219 | public function iSpecifyTheCurrentPasswordAs($password) |
||
223 | |||
224 | /** |
||
225 | * @Given I specify the new password as :password |
||
226 | */ |
||
227 | public function iSpecifyTheNewPasswordAs($password) |
||
231 | |||
232 | /** |
||
233 | * @Given I confirm this password as :password |
||
234 | */ |
||
235 | public function iSpecifyTheConfirmationPasswordAs($password) |
||
239 | |||
240 | /** |
||
241 | * @Then I should be notified that provided password is different than the current one |
||
242 | */ |
||
243 | public function iShouldBeNotifiedThatProvidedPasswordIsDifferentThanTheCurrentOne() |
||
247 | |||
248 | /** |
||
249 | * @Then I should be notified that the entered passwords do not match |
||
250 | */ |
||
251 | public function iShouldBeNotifiedThatTheEnteredPasswordsDoNotMatch() |
||
255 | |||
256 | /** |
||
257 | * @Then I should be notified that the password should be at least 4 characters long |
||
258 | */ |
||
259 | public function iShouldBeNotifiedThatThePasswordShouldBeAtLeastCharactersLong() |
||
263 | |||
264 | /** |
||
265 | * @When I browse my orders |
||
266 | */ |
||
267 | public function iBrowseMyOrders() |
||
271 | |||
272 | /** |
||
273 | * @Then I should see a single order in the list |
||
274 | */ |
||
275 | public function iShouldSeeASingleOrderInTheList() |
||
276 | { |
||
277 | Assert::same( |
||
278 | 1, |
||
279 | $this->orderIndexPage->countOrders(), |
||
280 | '%s rows with orders should appear on page, %s rows have been found.' |
||
281 | ); |
||
282 | } |
||
283 | |||
284 | /** |
||
285 | * @Then this order should have :order number |
||
286 | */ |
||
287 | public function thisOrderShouldHaveNumber(OrderInterface $order) |
||
294 | |||
295 | /** |
||
296 | * @When I view the summary of the order :order |
||
297 | */ |
||
298 | public function iViewTheSummaryOfTheOrder(OrderInterface $order) |
||
299 | { |
||
300 | $this->orderShowPage->open(['number' => $order->getNumber()]); |
||
301 | } |
||
302 | |||
303 | /** |
||
304 | * @Then it should has number :orderNumber |
||
305 | */ |
||
306 | public function itShouldHasNumber($orderNumber) |
||
307 | { |
||
308 | Assert::same( |
||
309 | $this->orderShowPage->getNumber(), |
||
310 | $orderNumber, |
||
311 | 'The number of an order is %s, but should be %s.' |
||
312 | ); |
||
313 | } |
||
314 | |||
315 | /** |
||
316 | * @Then I should see :customerName, :street, :postcode, :city, :countryName as shipping address |
||
317 | */ |
||
318 | public function iShouldSeeAsShippingAddress($customerName, $street, $postcode, $city, $countryName) |
||
325 | |||
326 | /** |
||
327 | * @Then I should see :customerName, :street, :postcode, :city, :countryName as billing address |
||
328 | */ |
||
329 | public function itShouldBeShippedTo($customerName, $street, $postcode, $city, $countryName) |
||
336 | |||
337 | /** |
||
338 | * @Then I should see :total as order's total |
||
339 | */ |
||
340 | public function iShouldSeeAsOrderSTotal($total) |
||
348 | |||
349 | /** |
||
350 | * @Then I should see :itemsTotal as order's subtotal |
||
351 | */ |
||
352 | public function iShouldSeeAsOrderSSubtotal($subtotal) |
||
360 | |||
361 | /** |
||
362 | * @Then I should see that I have to pay :paymentAmount for this order |
||
363 | * @Then I should see :paymentTotal as payment total |
||
364 | */ |
||
365 | public function iShouldSeeIHaveToPayForThisOrder($paymentAmount) |
||
366 | { |
||
367 | Assert::same( |
||
368 | $this->orderShowPage->getPaymentPrice(), |
||
369 | $paymentAmount, |
||
370 | 'Payment total is %s, but should be %s.' |
||
371 | ); |
||
372 | } |
||
373 | |||
374 | /** |
||
375 | * @Then I should see :numberOfItems items in the list |
||
376 | */ |
||
377 | public function iShouldSeeItemsInTheList($numberOfItems) |
||
385 | |||
386 | /** |
||
387 | * @Then the product named :productName should be in the items list |
||
388 | */ |
||
389 | public function theProductShouldBeInTheItemsList($productName) |
||
396 | |||
397 | /** |
||
398 | * @Then I should see :itemPrice as item price |
||
399 | */ |
||
400 | public function iShouldSeeAsItemPrice($itemPrice) |
||
408 | |||
409 | /** |
||
410 | * @param PageInterface $page |
||
411 | * @param string $element |
||
412 | * @param string $expectedMessage |
||
413 | */ |
||
414 | private function assertFieldValidationMessage(PageInterface $page, $element, $expectedMessage) |
||
421 | |||
422 | /** |
||
423 | * @When I subscribe to the newsletter |
||
424 | */ |
||
425 | public function iSubscribeToTheNewsletter() |
||
429 | |||
430 | /** |
||
431 | * @Then subscription to the newsletter should be enabled |
||
432 | */ |
||
433 | public function subscriptionToTheNewsletterShouldBeEnabled() |
||
440 | } |
||
441 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: