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($this->addressBookIndexPage->hasAddressOf($fullName)); |
||
237 | } |
||
238 | |||
239 | /** |
||
240 | * @Then I should still be on the address addition page |
||
241 | */ |
||
242 | public function iShouldStillBeOnAddressAdditionPage() |
||
246 | |||
247 | /** |
||
248 | * @Then I should still be on the :fullName address edit page |
||
249 | */ |
||
250 | public function iShouldStillBeOnTheAddressEditPage($fullName) |
||
256 | |||
257 | /** |
||
258 | * @Then I should still have :value as my specified province |
||
259 | */ |
||
260 | public function iShouldStillHaveAsMySpecifiedProvince($value) |
||
264 | |||
265 | /** |
||
266 | * @Then I should still have :value as my chosen province |
||
267 | */ |
||
268 | public function iShouldStillHaveAsMyChosenProvince($value) |
||
272 | |||
273 | /** |
||
274 | * @Then I should be notified that the province needs to be specified |
||
275 | */ |
||
276 | public function iShouldBeNotifiedThatTheProvinceNeedsToBeSpecified() |
||
280 | |||
281 | /** |
||
282 | * @Then /^I should be notified about (\d+) errors$/ |
||
283 | */ |
||
284 | public function iShouldBeNotifiedAboutErrors($expectedCount) |
||
288 | |||
289 | /** |
||
290 | * @Then there should be no addresses |
||
291 | */ |
||
292 | public function thereShouldBeNoAddresses() |
||
296 | |||
297 | /** |
||
298 | * @Then I should not see the address assigned to :fullName |
||
299 | */ |
||
300 | public function iShouldNotSeeAddressOf($fullName) |
||
304 | |||
305 | /** |
||
306 | * @Then /^I should(?:| still) have a single address in my address book$/ |
||
307 | * @Then /^I should(?:| still) have (\d+) addresses in my address book$/ |
||
308 | */ |
||
309 | public function iShouldHaveAddresses($count = 1) |
||
315 | |||
316 | /** |
||
317 | * @Then I should be notified that the address has been successfully added |
||
318 | */ |
||
319 | public function iShouldBeNotifiedThatAddressHasBeenSuccessfullyAdded() |
||
323 | |||
324 | /** |
||
325 | * @Then I should be notified that the address has been successfully deleted |
||
326 | */ |
||
327 | public function iShouldBeNotifiedAboutSuccessfulDelete() |
||
331 | |||
332 | /** |
||
333 | * @Then I should be unable to edit their address |
||
334 | */ |
||
335 | public function iShouldBeUnableToEditTheirAddress() |
||
341 | |||
342 | /** |
||
343 | * @Then I should be notified that the address has been successfully updated |
||
344 | */ |
||
345 | public function iShouldBeNotifiedAboutSuccessfulUpdate() |
||
349 | |||
350 | /** |
||
351 | * @Then I should be notified that the address has been set as default |
||
352 | */ |
||
353 | public function iShouldBeNotifiedThatAddressHasBeenSetAsDefault() |
||
357 | |||
358 | /** |
||
359 | * @Then I should not have a default address |
||
360 | */ |
||
361 | public function iShouldHaveNoDefaultAddress() |
||
365 | |||
366 | /** |
||
367 | * @Then /^(address "[^"]+", "[^"]+", "[^"]+", "[^"]+", "[^"]+"(?:|, "[^"]+")) should(?:| still) be marked as my default address$/ |
||
368 | */ |
||
369 | public function addressShouldBeMarkedAsMyDefaultAddress(AddressInterface $address) |
||
376 | |||
377 | /** |
||
378 | * @param string $fullName |
||
379 | * |
||
380 | * @return AddressInterface |
||
381 | */ |
||
382 | private function getAddressOf($fullName) |
||
392 | |||
393 | /** |
||
394 | * @return SymfonyPageInterface |
||
395 | */ |
||
396 | private function getCurrentPage() |
||
405 | } |
||
406 |
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.