Complex classes like AbstractTestCase 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 AbstractTestCase, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
21 | abstract class AbstractTestCase extends \PHPUnit_Framework_TestCase |
||
22 | { |
||
23 | use ElementTrait; |
||
24 | use ElementsTrait; |
||
25 | use NotifyTrait; |
||
26 | use ScreenshotTrait; |
||
27 | |||
28 | /** |
||
29 | * Selenium Web Driver host URI |
||
30 | * |
||
31 | * @var string |
||
32 | */ |
||
33 | protected static $webDriverHost = 'http://localhost:%s/wd/hub'; |
||
34 | |||
35 | /** |
||
36 | * Selenium Web Driver port |
||
37 | * |
||
38 | * @var string |
||
39 | */ |
||
40 | protected static $webDriverPort = '4444'; |
||
41 | |||
42 | /** |
||
43 | * @var string |
||
44 | */ |
||
45 | protected static $webDriverBrowser = 'firefox'; |
||
46 | |||
47 | /** |
||
48 | * @var string |
||
49 | */ |
||
50 | protected static $webDriverScreen = '1920x1080'; |
||
51 | |||
52 | /** |
||
53 | * @var string |
||
54 | */ |
||
55 | protected $browser; |
||
56 | |||
57 | /** |
||
58 | * @var string |
||
59 | */ |
||
60 | protected $browserBin; |
||
61 | |||
62 | /** |
||
63 | * @var string |
||
64 | */ |
||
65 | protected $uri; |
||
66 | |||
67 | /** |
||
68 | * @var PHPWebDriver_WebDriver |
||
69 | */ |
||
70 | protected $webDriver; |
||
71 | |||
72 | /** |
||
73 | * @var \PHPWebDriver_WebDriverSession|WebDriver\SessionInterface |
||
74 | */ |
||
75 | protected $session; |
||
76 | |||
77 | /** |
||
78 | * Resolves URI to open session |
||
79 | */ |
||
80 | protected function setUp() |
||
88 | |||
89 | /** |
||
90 | * @return void |
||
91 | */ |
||
92 | protected function tearDown() |
||
96 | |||
97 | /** |
||
98 | * @param Exception $exc |
||
99 | * @throws Exception |
||
100 | */ |
||
101 | protected function onNotSuccessfulTest(Exception $exc) |
||
107 | |||
108 | /** |
||
109 | * @return string |
||
110 | */ |
||
111 | protected function getBrowser() |
||
115 | |||
116 | /** |
||
117 | * @return string |
||
118 | */ |
||
119 | protected function getBrowserBin() |
||
123 | |||
124 | /** |
||
125 | * @param string $bin |
||
126 | * @return string |
||
127 | */ |
||
128 | protected function setBrowserBin($bin) |
||
133 | |||
134 | /** |
||
135 | * @return \PHPWebDriver_WebDriverSession|WebDriver\SessionInterface |
||
136 | */ |
||
137 | public function getSession() |
||
141 | |||
142 | /** |
||
143 | * @return string |
||
144 | */ |
||
145 | protected function getSessionId() |
||
149 | |||
150 | /** |
||
151 | * @return string |
||
152 | */ |
||
153 | protected function getServerUrl() |
||
158 | |||
159 | /** |
||
160 | * Get raw source from URL |
||
161 | * |
||
162 | * @param string $url |
||
163 | * @param null $sessId |
||
164 | * @return string |
||
165 | */ |
||
166 | protected function source($url, $sessId = null) |
||
172 | |||
173 | /** |
||
174 | * Resolve Selenium WebDriver host |
||
175 | * |
||
176 | * @return string |
||
177 | */ |
||
178 | protected function resolveHost() |
||
184 | |||
185 | /** |
||
186 | * Resolve Selenium WebDriver port |
||
187 | * |
||
188 | * @return string |
||
189 | */ |
||
190 | protected function resolvePort() |
||
196 | |||
197 | /** |
||
198 | * Resolve test session browser |
||
199 | * |
||
200 | * @return string |
||
201 | */ |
||
202 | protected function resolveBrowser() |
||
219 | |||
220 | /** |
||
221 | * Resolve test session capabilities |
||
222 | * |
||
223 | * @return array |
||
224 | */ |
||
225 | protected function resolveCapabilities() |
||
242 | |||
243 | /** |
||
244 | * Resolve test target URI |
||
245 | * |
||
246 | * @return string |
||
247 | */ |
||
248 | protected function resolveUri() |
||
256 | |||
257 | /** |
||
258 | * @return array |
||
259 | */ |
||
260 | protected function resolveWindowSize() |
||
267 | |||
268 | /** |
||
269 | * @param float $sec |
||
270 | * @return $this |
||
271 | */ |
||
272 | protected function sleep($sec = 2.0) |
||
277 | |||
278 | /** |
||
279 | * Opens URI and asserts not error |
||
280 | * |
||
281 | * @param string $path |
||
282 | * @param string|null $caption |
||
283 | * @return $this |
||
284 | */ |
||
285 | protected function open($path = '', $caption = null) |
||
292 | |||
293 | /** |
||
294 | * @param string $path |
||
295 | * @param string $caption |
||
296 | * @return $this |
||
297 | * @todo remove |
||
298 | * @deprecated use open() |
||
299 | */ |
||
300 | protected function openOk($path = '', $caption = 'Home') |
||
304 | |||
305 | /** |
||
306 | * Assert that page is without errors |
||
307 | * |
||
308 | * @return $this |
||
309 | */ |
||
310 | protected function assertNotError() |
||
323 | |||
324 | /** |
||
325 | * @return bool |
||
326 | */ |
||
327 | public function is404() |
||
337 | |||
338 | /** |
||
339 | * Clicks on a link |
||
340 | * |
||
341 | * @param string $linkText |
||
342 | * @param callable $callback |
||
343 | * @return $this |
||
344 | */ |
||
345 | protected function clickLink($linkText, callable $callback = null) |
||
352 | |||
353 | /** |
||
354 | * Clicks on ajax-link |
||
355 | * |
||
356 | * @param string $linkText |
||
357 | * @param callable $callback |
||
358 | * @return $this |
||
359 | */ |
||
360 | protected function clickAjaxLink($linkText, callable $callback = null) |
||
366 | |||
367 | /** |
||
368 | * @param string $class |
||
369 | * @return $this |
||
370 | */ |
||
371 | protected function clickByClass($class) |
||
376 | |||
377 | /** |
||
378 | * @param string $name |
||
379 | * @param string $value |
||
380 | * @return $this |
||
381 | * @deprecated use getSelect() |
||
382 | */ |
||
383 | protected function clickSelect($name, $value) |
||
389 | |||
390 | /** |
||
391 | * @param string $name |
||
392 | * @return WebDriver\Select |
||
393 | */ |
||
394 | protected function getSelect($name) |
||
398 | |||
399 | /** |
||
400 | * Enters the input value |
||
401 | * |
||
402 | * @param string|WebDriverElement $name |
||
403 | * @param string $value |
||
404 | * @param callable|false|null $callback |
||
405 | * @return $this |
||
406 | */ |
||
407 | protected function enterInput($name, $value, $callback = null) |
||
431 | |||
432 | /** |
||
433 | * Submit the input value |
||
434 | * |
||
435 | * @param string|WebDriverElement $name |
||
436 | * @param string $value |
||
437 | * @return $this |
||
438 | */ |
||
439 | protected function submitInput($name, $value) |
||
447 | |||
448 | /** |
||
449 | * Assert that input value is same than expected |
||
450 | * |
||
451 | * @param string|WebDriverElement|WebDriver\ElementInterface $name |
||
452 | * @param string $expectedValue |
||
453 | * @param callable $callback |
||
454 | * @return $this |
||
455 | */ |
||
456 | public function assertInput($name, $expectedValue, callable $callback = null) |
||
463 | |||
464 | /** |
||
465 | * Focus a browser window |
||
466 | * |
||
467 | * @param int $index |
||
468 | * @return $this |
||
469 | */ |
||
470 | protected function focusWindow($index) |
||
477 | |||
478 | /** |
||
479 | * Close a browser window |
||
480 | * |
||
481 | * @return $this |
||
482 | */ |
||
483 | protected function closeWindow() |
||
489 | |||
490 | /** |
||
491 | * Wait for something, then do something else |
||
492 | * |
||
493 | * @param callable|object $action |
||
494 | * @param callable|object $callback |
||
495 | * @return $this |
||
496 | */ |
||
497 | protected function waitFor(callable $action, callable $callback = null) |
||
503 | |||
504 | /** |
||
505 | * Ajax wait |
||
506 | * |
||
507 | * Depends on jQuery. |
||
508 | * |
||
509 | * @param float $delay Seconds |
||
510 | * @return $this |
||
511 | */ |
||
512 | protected function waitForAjax($delay = .1) |
||
523 | } |
||
524 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.