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 $browser; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @var string |
||
| 54 | */ |
||
| 55 | protected $browserBin; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @var string |
||
| 59 | */ |
||
| 60 | protected $uri; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @var PHPWebDriver_WebDriver |
||
| 64 | */ |
||
| 65 | protected $webDriver; |
||
| 66 | |||
| 67 | /** |
||
| 68 | * @var \PHPWebDriver_WebDriverSession|WebDriver\SessionInterface |
||
| 69 | */ |
||
| 70 | protected $session; |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Resolves URI to open session |
||
| 74 | */ |
||
| 75 | protected function setUp() |
||
| 85 | |||
| 86 | /** |
||
| 87 | * @return void |
||
| 88 | */ |
||
| 89 | protected function tearDown() |
||
| 93 | |||
| 94 | /** |
||
| 95 | * @param Exception $exc |
||
| 96 | * @throws Exception |
||
| 97 | */ |
||
| 98 | protected function onNotSuccessfulTest(Exception $exc) |
||
| 104 | |||
| 105 | /** |
||
| 106 | * @return string |
||
| 107 | */ |
||
| 108 | protected function getBrowser() |
||
| 112 | |||
| 113 | /** |
||
| 114 | * @return string |
||
| 115 | */ |
||
| 116 | protected function getBrowserBin() |
||
| 120 | |||
| 121 | /** |
||
| 122 | * @param string $bin |
||
| 123 | * @return string |
||
| 124 | */ |
||
| 125 | protected function setBrowserBin($bin) |
||
| 130 | |||
| 131 | /** |
||
| 132 | * @return \PHPWebDriver_WebDriverSession|WebDriver\SessionInterface |
||
| 133 | */ |
||
| 134 | public function getSession() |
||
| 138 | |||
| 139 | /** |
||
| 140 | * @return string |
||
| 141 | */ |
||
| 142 | protected function getSessionId() |
||
| 146 | |||
| 147 | /** |
||
| 148 | * @return string |
||
| 149 | */ |
||
| 150 | protected function getServerUrl() |
||
| 155 | |||
| 156 | /** |
||
| 157 | * Get raw source from URL |
||
| 158 | * |
||
| 159 | * @param string $url |
||
| 160 | * @param null $sessId |
||
| 161 | * @return string |
||
| 162 | */ |
||
| 163 | protected function source($url, $sessId = null) |
||
| 169 | |||
| 170 | /** |
||
| 171 | * Resolve Selenium WebDriver host |
||
| 172 | * |
||
| 173 | * @return string |
||
| 174 | */ |
||
| 175 | protected function resolveHost() |
||
| 181 | |||
| 182 | /** |
||
| 183 | * Resolve Selenium WebDriver port |
||
| 184 | * |
||
| 185 | * @return string |
||
| 186 | */ |
||
| 187 | protected function resolvePort() |
||
| 193 | |||
| 194 | /** |
||
| 195 | * Resolve test session browser |
||
| 196 | * |
||
| 197 | * @return string |
||
| 198 | */ |
||
| 199 | protected function resolveBrowser() |
||
| 216 | |||
| 217 | /** |
||
| 218 | * Resolve test session capabilities |
||
| 219 | * |
||
| 220 | * @return array |
||
| 221 | */ |
||
| 222 | protected function resolveCapabilities() |
||
| 239 | |||
| 240 | /** |
||
| 241 | * Resolve test target URI |
||
| 242 | * |
||
| 243 | * @return string |
||
| 244 | */ |
||
| 245 | protected function resolveUri() |
||
| 253 | |||
| 254 | /** |
||
| 255 | * @param float $sec |
||
| 256 | * @return $this |
||
| 257 | */ |
||
| 258 | protected function sleep($sec = 2.0) |
||
| 263 | |||
| 264 | /** |
||
| 265 | * Opens URI and asserts not error |
||
| 266 | * |
||
| 267 | * @param string $path |
||
| 268 | * @param string $caption |
||
| 269 | * @return $this |
||
| 270 | */ |
||
| 271 | protected function openOk($path = '', $caption = 'Home') |
||
| 279 | |||
| 280 | /** |
||
| 281 | * Assert that page is without errors |
||
| 282 | * |
||
| 283 | * @return $this |
||
| 284 | */ |
||
| 285 | protected function assertNotError() |
||
| 298 | |||
| 299 | /** |
||
| 300 | * @return bool |
||
| 301 | */ |
||
| 302 | public function is404() |
||
| 312 | |||
| 313 | /** |
||
| 314 | * Clicks on a link |
||
| 315 | * |
||
| 316 | * @param string $linkText |
||
| 317 | * @param callable $callback |
||
| 318 | * @return $this |
||
| 319 | */ |
||
| 320 | protected function clickLink($linkText, callable $callback = null) |
||
| 328 | |||
| 329 | /** |
||
| 330 | * Clicks on ajax-link |
||
| 331 | * |
||
| 332 | * @param string $linkText |
||
| 333 | * @param callable $callback |
||
| 334 | * @return $this |
||
| 335 | */ |
||
| 336 | protected function clickAjaxLink($linkText, callable $callback = null) |
||
| 344 | |||
| 345 | /** |
||
| 346 | * @param string $class |
||
| 347 | * @return $this |
||
| 348 | */ |
||
| 349 | protected function clickByClass($class) |
||
| 354 | |||
| 355 | /** |
||
| 356 | * @param string $name |
||
| 357 | * @param string $value |
||
| 358 | * @return $this |
||
| 359 | * @deprecated use getSelect() |
||
| 360 | */ |
||
| 361 | protected function clickSelect($name, $value) |
||
| 367 | |||
| 368 | /** |
||
| 369 | * @param string $name |
||
| 370 | * @return WebDriver\Select |
||
| 371 | */ |
||
| 372 | protected function getSelect($name) |
||
| 376 | |||
| 377 | /** |
||
| 378 | * Enters the input value |
||
| 379 | * |
||
| 380 | * @param string|PHPWebDriver_WebDriverElement $name |
||
| 381 | * @param string $value |
||
| 382 | * @param callable|false|null $callback |
||
| 383 | * @return $this |
||
| 384 | */ |
||
| 385 | protected function enterInput($name, $value, $callback = null) |
||
| 410 | |||
| 411 | /** |
||
| 412 | * Submit the input value |
||
| 413 | * |
||
| 414 | * @param string|PHPWebDriver_WebDriverElement $name |
||
| 415 | * @param string $value |
||
| 416 | * @return $this |
||
| 417 | */ |
||
| 418 | protected function submitInput($name, $value) |
||
| 425 | |||
| 426 | /** |
||
| 427 | * Assert that input value is same than expected |
||
| 428 | * |
||
| 429 | * @param string|PHPWebDriver_WebDriverElement $name |
||
| 430 | * @param string $expectedValue |
||
| 431 | * @param callable $callback |
||
| 432 | * @return $this |
||
| 433 | */ |
||
| 434 | public function assertInput($name, $expectedValue, callable $callback = null) |
||
| 441 | |||
| 442 | /** |
||
| 443 | * Focus a browser window |
||
| 444 | * |
||
| 445 | * @param int $index |
||
| 446 | * @return $this |
||
| 447 | */ |
||
| 448 | protected function focusWindow($index) |
||
| 455 | |||
| 456 | /** |
||
| 457 | * Close a browser window |
||
| 458 | * |
||
| 459 | * @return $this |
||
| 460 | */ |
||
| 461 | protected function closeWindow() |
||
| 467 | |||
| 468 | /** |
||
| 469 | * Wait for something, then do something else |
||
| 470 | * |
||
| 471 | * @param callable $action |
||
| 472 | * @param callable $callback |
||
| 473 | * @return $this |
||
| 474 | */ |
||
| 475 | protected function waitFor(callable $action, callable $callback = null) |
||
| 481 | |||
| 482 | /** |
||
| 483 | * Ajax wait |
||
| 484 | * |
||
| 485 | * Depends on jQuery. |
||
| 486 | * |
||
| 487 | * @param float $delay Seconds |
||
| 488 | * @return $this |
||
| 489 | */ |
||
| 490 | protected function waitForAjax($delay = .1) |
||
| 501 | } |
||
| 502 |
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.