1 | <?php |
||
31 | final class AddressBookContext implements Context |
||
32 | { |
||
33 | /** |
||
34 | * @var SharedStorageInterface |
||
35 | */ |
||
36 | private $sharedStorage; |
||
37 | |||
38 | /** |
||
39 | * @var RepositoryInterface |
||
40 | */ |
||
41 | private $addressRepository; |
||
42 | |||
43 | /** |
||
44 | * @var IndexPageInterface |
||
45 | */ |
||
46 | private $addressBookIndexPage; |
||
47 | |||
48 | /** |
||
49 | * @var CreatePageInterface |
||
50 | */ |
||
51 | private $addressBookCreatePage; |
||
52 | |||
53 | /** |
||
54 | * @var UpdatePageInterface |
||
55 | */ |
||
56 | private $addressBookUpdatePage; |
||
57 | |||
58 | /** |
||
59 | * @var CurrentPageResolverInterface |
||
60 | */ |
||
61 | private $currentPageResolver; |
||
62 | |||
63 | /** |
||
64 | * @var NotificationCheckerInterface |
||
65 | */ |
||
66 | private $notificationChecker; |
||
67 | |||
68 | /** |
||
69 | * @param SharedStorageInterface $sharedStorage |
||
70 | * @param RepositoryInterface $addressRepository |
||
71 | * @param IndexPageInterface $addressBookIndexPage |
||
72 | * @param CreatePageInterface $addressBookCreatePage |
||
73 | * @param UpdatePageInterface $addressBookUpdatePage |
||
74 | * @param CurrentPageResolverInterface $currentPageResolver |
||
75 | * @param NotificationCheckerInterface $notificationChecker |
||
76 | */ |
||
77 | public function __construct( |
||
78 | SharedStorageInterface $sharedStorage, |
||
79 | RepositoryInterface $addressRepository, |
||
80 | IndexPageInterface $addressBookIndexPage, |
||
81 | CreatePageInterface $addressBookCreatePage, |
||
|
|||
82 | UpdatePageInterface $addressBookUpdatePage, |
||
83 | CurrentPageResolverInterface $currentPageResolver, |
||
84 | NotificationCheckerInterface $notificationChecker |
||
85 | ) { |
||
86 | $this->sharedStorage = $sharedStorage; |
||
87 | $this->addressRepository = $addressRepository; |
||
88 | $this->addressBookIndexPage = $addressBookIndexPage; |
||
89 | $this->addressBookCreatePage = $addressBookCreatePage; |
||
90 | $this->addressBookUpdatePage = $addressBookUpdatePage; |
||
91 | $this->currentPageResolver = $currentPageResolver; |
||
92 | $this->notificationChecker = $notificationChecker; |
||
93 | } |
||
94 | |||
95 | /** |
||
96 | * @Given I am editing the address of :fullName |
||
97 | */ |
||
98 | public function iEditAddressOf($fullName) |
||
99 | { |
||
100 | $this->sharedStorage->set('full_name', $fullName); |
||
101 | |||
102 | $this->addressBookIndexPage->open(); |
||
103 | $this->addressBookIndexPage->editAddress($fullName); |
||
104 | } |
||
105 | |||
106 | /** |
||
107 | * @When I set the address of :fullName as default |
||
108 | */ |
||
109 | public function iSetTheAddressOfAsDefault($fullName) |
||
110 | { |
||
111 | $this->sharedStorage->set('full_name', $fullName); |
||
112 | |||
113 | $this->addressBookIndexPage->setAsDefault($fullName); |
||
114 | } |
||
115 | |||
116 | /** |
||
117 | * @When I want to add a new address to my address book |
||
118 | */ |
||
119 | public function iWantToAddANewAddressToMyAddressBook() |
||
120 | { |
||
121 | $this->addressBookCreatePage->open(); |
||
122 | } |
||
123 | |||
124 | /** |
||
125 | * @Given I am browsing my address book |
||
126 | * @When I browse my address book |
||
127 | */ |
||
128 | public function iBrowseMyAddresses() |
||
129 | { |
||
130 | $this->addressBookIndexPage->open(); |
||
131 | } |
||
132 | |||
133 | /** |
||
134 | * @When I specify :provinceName as my province |
||
135 | */ |
||
136 | public function iSpecifyAsMyProvince($provinceName) |
||
137 | { |
||
138 | $this->addressBookUpdatePage->specifyProvince($provinceName); |
||
139 | } |
||
140 | |||
141 | /** |
||
142 | * @When I choose :provinceName as my province |
||
143 | */ |
||
144 | public function iChooseAsMyProvince($provinceName) |
||
145 | { |
||
146 | $this->addressBookUpdatePage->selectProvince($provinceName); |
||
147 | } |
||
148 | |||
149 | /** |
||
150 | * @When I choose :countryName as my country |
||
151 | */ |
||
152 | public function iChooseAsMyCountry($countryName) |
||
153 | { |
||
154 | /** @var CreatePageInterface|UpdatePageInterface $currentPage */ |
||
155 | $currentPage = $this->getCurrentPage(); |
||
156 | $currentPage->selectCountry($countryName); |
||
157 | } |
||
158 | |||
159 | /** |
||
160 | * @When /^I change the ([^"]+) to "([^"]+)"$/ |
||
161 | * @When /^I remove the ([^"]+)$/ |
||
162 | */ |
||
163 | public function iChangeMyTo($field, $value = null) |
||
167 | |||
168 | /** |
||
169 | * @When /^I specify the (address as "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)")$/ |
||
170 | */ |
||
171 | public function iSpecifyTheAddressAs(AddressInterface $address) |
||
175 | |||
176 | /** |
||
177 | * @When I leave every field empty |
||
178 | */ |
||
179 | public function iLeaveEveryFieldEmpty() |
||
183 | |||
184 | /** |
||
185 | * @When I add it |
||
186 | */ |
||
187 | public function iAddIt() |
||
191 | |||
192 | /** |
||
193 | * @When I save my changed address |
||
194 | */ |
||
195 | public function iSaveChangedAddress() |
||
199 | |||
200 | /** |
||
201 | * @When I delete the :fullName address |
||
202 | */ |
||
203 | public function iDeleteTheAddress($fullname) |
||
207 | |||
208 | /** |
||
209 | * @When /^I try to edit the address of "([^"]+)"$/ |
||
210 | */ |
||
211 | public function iTryToEditTheAddressOf($fullName) |
||
219 | |||
220 | /** |
||
221 | * @Then /^it should contain "([^"]+)"$/ |
||
222 | */ |
||
223 | public function itShouldContain($value) |
||
229 | |||
230 | /** |
||
231 | * @Then this address should be assigned to :fullName |
||
232 | * @Then /^the address assigned to "([^"]+)" should (appear|be) in my book$/ |
||
233 | */ |
||
234 | public function thisAddressShouldHavePersonFirstNameAndLastName($fullName) |
||
235 | { |
||
236 | Assert::true( |
||
237 | $this->addressBookIndexPage->hasAddressOf($fullName), |
||
241 | |||
242 | /** |
||
243 | * @Then I should still be on the address addition page |
||
244 | */ |
||
245 | public function iShouldStillBeOnAddressAdditionPage() |
||
252 | |||
253 | /** |
||
254 | * @Then I should still be on the :fullName address edit page |
||
255 | */ |
||
256 | public function iShouldStillBeOnTheAddressEditPage($fullName) |
||
262 | |||
263 | /** |
||
264 | * @Then I should still have :value as my specified province |
||
265 | */ |
||
266 | public function iShouldStillHaveAsMySpecifiedProvince($value) |
||
276 | |||
277 | /** |
||
278 | * @Then I should still have :value as my chosen province |
||
279 | */ |
||
280 | public function iShouldStillHaveAsMyChosenProvince($value) |
||
290 | |||
291 | /** |
||
292 | * @Then I should be notified that the province needs to be specified |
||
293 | */ |
||
294 | public function iShouldBeNotifiedThatTheProvinceNeedsToBeSpecified() |
||
301 | |||
302 | /** |
||
303 | * @Then /^I should be notified about (\d+) errors$/ |
||
304 | */ |
||
305 | public function iShouldBeNotifiedAboutErrors($expectedCount) |
||
315 | |||
316 | /** |
||
317 | * @Then there should be no addresses |
||
318 | */ |
||
319 | public function thereShouldBeNoAddresses() |
||
326 | |||
327 | /** |
||
328 | * @Then I should not see the address assigned to :fullName |
||
329 | */ |
||
330 | public function iShouldNotSeeAddressOf($fullName) |
||
337 | |||
338 | /** |
||
339 | * @Then /^I should(?:| still) have a single address in my address book$/ |
||
340 | * @Then /^I should(?:| still) have (\d+) addresses in my address book$/ |
||
341 | */ |
||
342 | public function iShouldHaveAddresses($count = 1) |
||
348 | |||
349 | /** |
||
350 | * @Then I should be notified that the address has been successfully added |
||
351 | */ |
||
352 | public function iShouldBeNotifiedThatAddressHasBeenSuccessfullyAdded() |
||
356 | |||
357 | /** |
||
358 | * @Then I should be notified that the address has been successfully deleted |
||
359 | */ |
||
360 | public function iShouldBeNotifiedAboutSuccessfulDelete() |
||
364 | |||
365 | /** |
||
366 | * @Then I should be unable to edit their address |
||
367 | */ |
||
368 | public function iShouldBeUnableToEditTheirAddress() |
||
381 | |||
382 | /** |
||
383 | * @Then I should be notified that the address has been successfully updated |
||
384 | */ |
||
385 | public function iShouldBeNotifiedAboutSuccessfulUpdate() |
||
389 | |||
390 | /** |
||
391 | * @Then I should be notified that the address has been set as default |
||
392 | */ |
||
393 | public function iShouldBeNotifiedThatAddressHasBeenSetAsDefault() |
||
397 | |||
398 | /** |
||
399 | * @Then I should not have a default address |
||
400 | */ |
||
401 | public function iShouldHaveNoDefaultAddress() |
||
408 | |||
409 | /** |
||
410 | * @Then /^(address "[^"]+", "[^"]+", "[^"]+", "[^"]+", "[^"]+"(?:|, "[^"]+")) should be marked as my default address$/ |
||
411 | */ |
||
412 | public function addressShouldBeMarkedAsMyDefaultAddress(AddressInterface $address) |
||
423 | |||
424 | /** |
||
425 | * @param string $fullName |
||
426 | * |
||
427 | * @return AddressInterface |
||
428 | */ |
||
429 | private function getAddressOf($fullName) |
||
439 | |||
440 | /** |
||
441 | * @return SymfonyPageInterface |
||
442 | */ |
||
443 | private function getCurrentPage() |
||
452 | |||
453 | /** |
||
454 | * @param int $expectedCount |
||
455 | * |
||
456 | * @throws \InvalidArgumentException |
||
457 | */ |
||
458 | private function assertAddressesCountOnPage($expectedCount) |
||
472 | } |
||
473 |
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.