Complex classes like MinkContext often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use MinkContext, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
22 | class MinkContext extends RawMinkContext implements TranslatableContext |
||
23 | { |
||
24 | |||
25 | /** |
||
26 | * Opens homepage or specified page |
||
27 | * Example: Given I am on "http://batman.com" |
||
28 | * Example: And I am on "/articles/isBatmanBruceWayne" |
||
29 | * Example: When I go to "/articles/isBatmanBruceWayne" |
||
30 | * Example: Given I am on homepage |
||
31 | * Example: And I am on homepage |
||
32 | * Example: When I go to homepage |
||
33 | * Example: When I go to the homepage |
||
34 | * |
||
35 | * @Given /^(?:|I )am on "(?P<page>[^"]+)"$/ |
||
36 | * @When /^(?:|I )go to "(?P<page>[^"]+)"$/ |
||
37 | * @Given /^(?:|I )am on (?:|the )homepage$/ |
||
38 | * @When /^(?:|I )go to (?:|the )homepage$/ |
||
39 | */ |
||
40 | public function visit($page = "/") |
||
44 | |||
45 | /** |
||
46 | * Reloads current page |
||
47 | * Example: When I reload the page |
||
48 | * Example: And I reload the page |
||
49 | * |
||
50 | * @When /^(?:|I )reload the page$/ |
||
51 | */ |
||
52 | public function reload() |
||
56 | |||
57 | /** |
||
58 | * Moves backward one page in history |
||
59 | * Example: When I move backward one page |
||
60 | * |
||
61 | * @When /^(?:|I )move backward one page$/ |
||
62 | */ |
||
63 | public function back() |
||
67 | |||
68 | /** |
||
69 | * Moves forward one page in history |
||
70 | * Example: And I move forward one page |
||
71 | * |
||
72 | * @When /^(?:|I )move forward one page$/ |
||
73 | */ |
||
74 | public function forward() |
||
78 | |||
79 | /** |
||
80 | * Presses button with specified id|name|title|alt|value |
||
81 | * Example: When I press "Log In" |
||
82 | * Example: And I press "Log In" |
||
83 | * |
||
84 | * @When /^(?:|I )press "(?P<button>(?:[^"]|\\")*)"$/ |
||
85 | */ |
||
86 | public function pressButton($button) |
||
91 | |||
92 | /** |
||
93 | * Clicks link with specified id|title|alt|text |
||
94 | * Example: When I follow "Log In" |
||
95 | * Example: And I follow "Log In" |
||
96 | * |
||
97 | * @When /^(?:|I )follow "(?P<link>(?:[^"]|\\")*)"$/ |
||
98 | */ |
||
99 | public function clickLink($link) |
||
104 | |||
105 | /** |
||
106 | * Fills in form field with specified id|name|label|value |
||
107 | * Example: When I fill in "username" with: "bwayne" |
||
108 | * Example: And I fill in "bwayne" for "username" |
||
109 | * |
||
110 | * @When /^(?:|I )fill in "(?P<field>(?:[^"]|\\")*)" with "(?P<value>(?:[^"]|\\")*)"$/ |
||
111 | * @When /^(?:|I )fill in "(?P<field>(?:[^"]|\\")*)" with:$/ |
||
112 | * @When /^(?:|I )fill in "(?P<value>(?:[^"]|\\")*)" for "(?P<field>(?:[^"]|\\")*)"$/ |
||
113 | */ |
||
114 | public function fillField($field, $value) |
||
120 | |||
121 | /** |
||
122 | * Fills in form fields with provided table |
||
123 | * Example: When I fill in the following" |
||
124 | * | username | bruceWayne | |
||
125 | * | password | iLoveBats123 | |
||
126 | * Example: And I fill in the following" |
||
127 | * | username | bruceWayne | |
||
128 | * | password | iLoveBats123 | |
||
129 | * |
||
130 | * @When /^(?:|I )fill in the following:$/ |
||
131 | */ |
||
132 | public function fillFields(TableNode $fields) |
||
138 | |||
139 | /** |
||
140 | * Selects option in select field with specified id|name|label|value |
||
141 | * Example: When I select "Bats" from "user_fears" |
||
142 | * Example: And I select "Bats" from "user_fears" |
||
143 | * |
||
144 | * @When /^(?:|I )select "(?P<option>(?:[^"]|\\")*)" from "(?P<select>(?:[^"]|\\")*)"$/ |
||
145 | */ |
||
146 | public function selectOption($select, $option) |
||
152 | |||
153 | /** |
||
154 | * Selects additional option in select field with specified id|name|label|value |
||
155 | * Example: When I additionally select "Deceased" from "parents_alive_status" |
||
156 | * Example: And I additionally select "Deceased" from "parents_alive_status" |
||
157 | * |
||
158 | * @When /^(?:|I )additionally select "(?P<option>(?:[^"]|\\")*)" from "(?P<select>(?:[^"]|\\")*)"$/ |
||
159 | */ |
||
160 | public function additionallySelectOption($select, $option) |
||
166 | |||
167 | /** |
||
168 | * Checks checkbox with specified id|name|label|value |
||
169 | * Example: When I check "Pearl Necklace" |
||
170 | * Example: And I check "Pearl Necklace" |
||
171 | * |
||
172 | * @When /^(?:|I )check "(?P<option>(?:[^"]|\\")*)"$/ |
||
173 | */ |
||
174 | public function checkOption($option) |
||
179 | |||
180 | /** |
||
181 | * Unchecks checkbox with specified id|name|label|value |
||
182 | * Example: When I uncheck "Broadway Plays" |
||
183 | * Example: And I uncheck "Broadway Plays" |
||
184 | * |
||
185 | * @When /^(?:|I )uncheck "(?P<option>(?:[^"]|\\")*)"$/ |
||
186 | */ |
||
187 | public function uncheckOption($option) |
||
192 | |||
193 | /** |
||
194 | * Attaches file to field with specified id|name|label|value |
||
195 | * Example: When I attach "bwayne_profile.png" to "profileImageUpload" |
||
196 | * Example: And I attach "bwayne_profile.png" to "profileImageUpload" |
||
197 | * |
||
198 | * @When /^(?:|I )attach the file "(?P<path>[^"]*)" to "(?P<field>(?:[^"]|\\")*)"$/ |
||
199 | */ |
||
200 | public function attachFileToField($field, $path) |
||
213 | |||
214 | /** |
||
215 | * Checks, that current page PATH is equal to specified |
||
216 | * Example: Then I should be on "/" |
||
217 | * Example: And I should be on "/bats" |
||
218 | * Example: And I should be on "http://google.com" |
||
219 | * |
||
220 | * @Then /^(?:|I )should be on "(?P<page>[^"]+)"$/ |
||
221 | */ |
||
222 | public function assertPageAddress($page) |
||
226 | |||
227 | /** |
||
228 | * Checks, that current page is the homepage |
||
229 | * Example: Then I should be on the homepage |
||
230 | * Example: And I should be on the homepage |
||
231 | * |
||
232 | * @Then /^(?:|I )should be on (?:|the )homepage$/ |
||
233 | */ |
||
234 | public function assertHomepage() |
||
238 | |||
239 | /** |
||
240 | * Checks, that current page PATH matches regular expression |
||
241 | * Example: Then the url should match "superman is dead" |
||
242 | * Example: Then the uri should match "log in" |
||
243 | * Example: And the url should match "log in" |
||
244 | * |
||
245 | * @Then /^the (?i)url(?-i) should match (?P<pattern>"(?:[^"]|\\")*")$/ |
||
246 | */ |
||
247 | public function assertUrlRegExp($pattern) |
||
251 | |||
252 | /** |
||
253 | * Checks, that current page response status is equal to specified |
||
254 | * Example: Then the response status code should be 200 |
||
255 | * Example: And the response status code should be 400 |
||
256 | * |
||
257 | * @Then /^the response status code should be (?P<code>\d+)$/ |
||
258 | */ |
||
259 | public function assertResponseStatus($code) |
||
263 | |||
264 | /** |
||
265 | * Checks, that current page response status is not equal to specified |
||
266 | * Example: Then the response status code should not be 501 |
||
267 | * Example: And the response status code should not be 404 |
||
268 | * |
||
269 | * @Then /^the response status code should not be (?P<code>\d+)$/ |
||
270 | */ |
||
271 | public function assertResponseStatusIsNot($code) |
||
275 | |||
276 | /** |
||
277 | * Checks, that page contains specified text |
||
278 | * Example: Then I should see "Who is the Batman?" |
||
279 | * Example: And I should see "Who is the Batman?" |
||
280 | * |
||
281 | * @Then /^(?:|I )should see "(?P<text>(?:[^"]|\\")*)"$/ |
||
282 | */ |
||
283 | public function assertPageContainsText($text) |
||
287 | |||
288 | /** |
||
289 | * Checks, that page doesn't contain specified text |
||
290 | * Example: Then I should not see "Batman is Bruce Wayne" |
||
291 | * Example: And I should not see "Batman is Bruce Wayne" |
||
292 | * |
||
293 | * @Then /^(?:|I )should not see "(?P<text>(?:[^"]|\\")*)"$/ |
||
294 | */ |
||
295 | public function assertPageNotContainsText($text) |
||
299 | |||
300 | /** |
||
301 | * Checks, that page contains text matching specified pattern |
||
302 | * Example: Then I should see text matching "Batman, the vigilante" |
||
303 | * Example: And I should not see "Batman, the vigilante" |
||
304 | * |
||
305 | * @Then /^(?:|I )should see text matching (?P<pattern>"(?:[^"]|\\")*")$/ |
||
306 | */ |
||
307 | public function assertPageMatchesText($pattern) |
||
311 | |||
312 | /** |
||
313 | * Checks, that page doesn't contain text matching specified pattern |
||
314 | * Example: Then I should see text matching "Bruce Wayne, the vigilante" |
||
315 | * Example: And I should not see "Bruce Wayne, the vigilante" |
||
316 | * |
||
317 | * @Then /^(?:|I )should not see text matching (?P<pattern>"(?:[^"]|\\")*")$/ |
||
318 | */ |
||
319 | public function assertPageNotMatchesText($pattern) |
||
323 | |||
324 | /** |
||
325 | * Checks, that HTML response contains specified string |
||
326 | * Example: Then the response should contain "Batman is the hero Gotham deserves." |
||
327 | * Example: And the response should contain "Batman is the hero Gotham deserves." |
||
328 | * |
||
329 | * @Then /^the response should contain "(?P<text>(?:[^"]|\\")*)"$/ |
||
330 | */ |
||
331 | public function assertResponseContains($text) |
||
335 | |||
336 | /** |
||
337 | * Checks, that HTML response doesn't contain specified string |
||
338 | * Example: Then the response should not contain "Bruce Wayne is a billionaire, play-boy, vigilante." |
||
339 | * Example: And the response should not contain "Bruce Wayne is a billionaire, play-boy, vigilante." |
||
340 | * |
||
341 | * @Then /^the response should not contain "(?P<text>(?:[^"]|\\")*)"$/ |
||
342 | */ |
||
343 | public function assertResponseNotContains($text) |
||
347 | |||
348 | /** |
||
349 | * Checks, that element with specified CSS contains specified text |
||
350 | * Example: Then I should see "Batman" in the "heroes_list" element |
||
351 | * Example: And I should see "Batman" in the "heroes_list" element |
||
352 | * |
||
353 | * @Then /^(?:|I )should see "(?P<text>(?:[^"]|\\")*)" in the "(?P<element>[^"]*)" element$/ |
||
354 | */ |
||
355 | public function assertElementContainsText($element, $text) |
||
359 | |||
360 | /** |
||
361 | * Checks, that element with specified CSS doesn't contain specified text |
||
362 | * Example: Then I should not see "Bruce Wayne" in the "heroes_alter_egos" element |
||
363 | * Example: And I should not see "Bruce Wayne" in the "heroes_alter_egos" element |
||
364 | * |
||
365 | * @Then /^(?:|I )should not see "(?P<text>(?:[^"]|\\")*)" in the "(?P<element>[^"]*)" element$/ |
||
366 | */ |
||
367 | public function assertElementNotContainsText($element, $text) |
||
371 | |||
372 | /** |
||
373 | * Checks, that element with specified CSS contains specified HTML |
||
374 | * Example: Then the "body" element should contain "style=\"color:black;\"" |
||
375 | * Example: And the "body" element should contain "style=\"color:black;\"" |
||
376 | * |
||
377 | * @Then /^the "(?P<element>[^"]*)" element should contain "(?P<value>(?:[^"]|\\")*)"$/ |
||
378 | */ |
||
379 | public function assertElementContains($element, $value) |
||
383 | |||
384 | /** |
||
385 | * Checks, that element with specified CSS doesn't contain specified HTML |
||
386 | * Example: Then the "body" element should not contain "style=\"color:black;\"" |
||
387 | * Example: And the "body" element should not contain "style=\"color:black;\"" |
||
388 | * |
||
389 | * @Then /^the "(?P<element>[^"]*)" element should not contain "(?P<value>(?:[^"]|\\")*)"$/ |
||
390 | */ |
||
391 | public function assertElementNotContains($element, $value) |
||
395 | |||
396 | /** |
||
397 | * Checks, that element with specified CSS exists on page |
||
398 | * Example: Then I should see a "body" element |
||
399 | * Example: And I should see a "body" element |
||
400 | * |
||
401 | * @Then /^(?:|I )should see an? "(?P<element>[^"]*)" element$/ |
||
402 | */ |
||
403 | public function assertElementOnPage($element) |
||
407 | |||
408 | /** |
||
409 | * Checks, that element with specified CSS doesn't exist on page |
||
410 | * Example: Then I should not see a "canvas" element |
||
411 | * Example: And I should not see a "canvas" element |
||
412 | * |
||
413 | * @Then /^(?:|I )should not see an? "(?P<element>[^"]*)" element$/ |
||
414 | */ |
||
415 | public function assertElementNotOnPage($element) |
||
419 | |||
420 | /** |
||
421 | * Checks, that form field with specified id|name|label|value has specified value |
||
422 | * Example: Then the "username" field should contain "bwayne" |
||
423 | * Example: And the "username" field should contain "bwayne" |
||
424 | * |
||
425 | * @Then /^the "(?P<field>(?:[^"]|\\")*)" field should contain "(?P<value>(?:[^"]|\\")*)"$/ |
||
426 | */ |
||
427 | public function assertFieldContains($field, $value) |
||
433 | |||
434 | /** |
||
435 | * Checks, that form field with specified id|name|label|value doesn't have specified value |
||
436 | * Example: Then the "username" field should not contain "batman" |
||
437 | * Example: And the "username" field should not contain "batman" |
||
438 | * |
||
439 | * @Then /^the "(?P<field>(?:[^"]|\\")*)" field should not contain "(?P<value>(?:[^"]|\\")*)"$/ |
||
440 | */ |
||
441 | public function assertFieldNotContains($field, $value) |
||
447 | |||
448 | /** |
||
449 | * Checks, that (?P<num>\d+) CSS elements exist on the page |
||
450 | * Example: Then I should see 5 "div" elements |
||
451 | * Example: And I should see 5 "div" elements |
||
452 | * |
||
453 | * @Then /^(?:|I )should see (?P<num>\d+) "(?P<element>[^"]*)" elements?$/ |
||
454 | */ |
||
455 | public function assertNumElements($num, $element) |
||
459 | |||
460 | /** |
||
461 | * Checks, that checkbox with specified id|name|label|value is checked |
||
462 | * Example: Then the "remember_me" checkbox should be checked |
||
463 | * Example: And the "remember_me" checkbox is checked |
||
464 | * |
||
465 | * @Then /^the "(?P<checkbox>(?:[^"]|\\")*)" checkbox should be checked$/ |
||
466 | * @Then /^the "(?P<checkbox>(?:[^"]|\\")*)" checkbox is checked$/ |
||
467 | * @Then /^the checkbox "(?P<checkbox>(?:[^"]|\\")*)" (?:is|should be) checked$/ |
||
468 | */ |
||
469 | public function assertCheckboxChecked($checkbox) |
||
473 | |||
474 | /** |
||
475 | * Checks, that checkbox with specified id|name|label|value is unchecked |
||
476 | * Example: Then the "newsletter" checkbox should be unchecked |
||
477 | * Example: Then the "newsletter" checkbox should not be checked |
||
478 | * Example: And the "newsletter" checkbox is unchecked |
||
479 | * |
||
480 | * @Then /^the "(?P<checkbox>(?:[^"]|\\")*)" checkbox should (?:be unchecked|not be checked)$/ |
||
481 | * @Then /^the "(?P<checkbox>(?:[^"]|\\")*)" checkbox is (?:unchecked|not checked)$/ |
||
482 | * @Then /^the checkbox "(?P<checkbox>(?:[^"]|\\")*)" should (?:be unchecked|not be checked)$/ |
||
483 | * @Then /^the checkbox "(?P<checkbox>(?:[^"]|\\")*)" is (?:unchecked|not checked)$/ |
||
484 | */ |
||
485 | public function assertCheckboxNotChecked($checkbox) |
||
489 | |||
490 | /** |
||
491 | * Prints current URL to console. |
||
492 | * Example: Then print current URL |
||
493 | * Example: And print current URL |
||
494 | * |
||
495 | * @Then /^print current URL$/ |
||
496 | */ |
||
497 | public function printCurrentUrl() |
||
501 | |||
502 | /** |
||
503 | * Prints last response to console |
||
504 | * Example: Then print current response |
||
505 | * Example: And print current response |
||
506 | * |
||
507 | * @Then /^print last response$/ |
||
508 | */ |
||
509 | public function printLastResponse() |
||
516 | |||
517 | /** |
||
518 | * Opens last response content in browser |
||
519 | * Example: Then show last response |
||
520 | * Example: And show last response |
||
521 | * |
||
522 | * @Then /^show last response$/ |
||
523 | */ |
||
524 | public function showLastResponse() |
||
534 | |||
535 | /** |
||
536 | * Returns list of definition translation resources paths |
||
537 | * |
||
538 | * @return array |
||
539 | */ |
||
540 | public static function getTranslationResources() |
||
544 | |||
545 | /** |
||
546 | * Returns list of definition translation resources paths for this dictionary |
||
547 | * |
||
548 | * @return array |
||
549 | */ |
||
550 | public static function getMinkTranslationResources() |
||
554 | |||
555 | /** |
||
556 | * Returns fixed step argument (with \\" replaced back to ") |
||
557 | * |
||
558 | * @param string $argument |
||
559 | * |
||
560 | * @return string |
||
561 | */ |
||
562 | protected function fixStepArgument($argument) |
||
566 | } |
||
567 |