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 | |||
| 24 | protected static $baseNamespaces = []; |
||
| 25 | |||
| 26 | protected $baseThemeClass = 'Magium\Themes\ThemeConfigurationInterface'; |
||
| 27 | |||
| 28 | protected $postCallbacks = []; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var MasterListener |
||
| 32 | */ |
||
| 33 | |||
| 34 | protected static $masterListener; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var \Magium\WebDriver\WebDriver |
||
| 38 | */ |
||
| 39 | protected $webdriver; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @var Di |
||
| 43 | */ |
||
| 44 | |||
| 45 | protected $di; |
||
| 46 | |||
| 47 | protected $textElementNodeSearch = [ |
||
| 48 | 'button', 'span', 'a', 'li', 'label', 'option', 'h1', 'h2', 'h3', 'td' |
||
| 49 | ]; |
||
| 50 | |||
| 51 | protected $initializer; |
||
| 52 | |||
| 53 | const BY_XPATH = 'byXpath'; |
||
| 54 | const BY_ID = 'byId'; |
||
| 55 | const BY_CSS_SELECTOR = 'byCssSelector'; |
||
| 56 | const BY_TEXT = 'byText'; |
||
| 57 | |||
| 58 | protected static $registrationCallbacks; |
||
| 59 | |||
| 60 | protected function setUp() |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @return Di |
||
| 73 | */ |
||
| 74 | public function getDi() |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @param Di $di |
||
| 81 | */ |
||
| 82 | public function setDi($di) |
||
| 86 | |||
| 87 | /** |
||
| 88 | * @return WebDriver |
||
| 89 | */ |
||
| 90 | public function getWebdriver() |
||
| 94 | |||
| 95 | /** |
||
| 96 | * @param WebDriver $webdriver |
||
| 97 | */ |
||
| 98 | public function setWebdriver(WebDriver $webdriver) |
||
| 102 | |||
| 103 | public function getInitializer() |
||
| 107 | |||
| 108 | |||
| 109 | public function __construct($name = null, array $data = [], $dataName = null, Initializer $initializer = null) |
||
| 119 | |||
| 120 | public function setTestResultObject(PHPUnit_Framework_TestResult $result) |
||
| 128 | |||
| 129 | /** |
||
| 130 | * @return MasterListener |
||
| 131 | */ |
||
| 132 | |||
| 133 | public static function getMasterListener() |
||
| 140 | |||
| 141 | protected function tearDown() |
||
| 154 | |||
| 155 | |||
| 156 | public function filterWebDriverAction($by) |
||
| 169 | |||
| 170 | public function assertElementClickable($selector, $by = WebDriver::BY_ID) |
||
| 174 | |||
| 175 | |||
| 176 | public function assertElementNotClickable($selector, $by = WebDriver::BY_ID) |
||
| 181 | |||
| 182 | public static function addBaseNamespace($namespace) |
||
| 188 | |||
| 189 | public static function resolveClass( $class, $prefix = null) |
||
| 210 | |||
| 211 | public function setTypePreference($type, $preference) |
||
| 219 | |||
| 220 | protected function normalizeClassRequest($class) |
||
| 224 | |||
| 225 | public function addPostTestCallback($callback) |
||
| 232 | |||
| 233 | /** |
||
| 234 | |||
| 235 | * @param string $theme |
||
| 236 | * @return \Magium\Themes\ThemeConfigurationInterface |
||
| 237 | */ |
||
| 238 | |||
| 239 | public function getTheme($theme = null) |
||
| 247 | |||
| 248 | /** |
||
| 249 | * |
||
| 250 | * @param string $action |
||
| 251 | * @return mixed |
||
| 252 | */ |
||
| 253 | |||
| 254 | public function getAction($action) |
||
| 260 | |||
| 261 | |||
| 262 | /** |
||
| 263 | * @param string $name |
||
| 264 | * @return \Magium\Magento\Identities\AbstractEntity |
||
| 265 | */ |
||
| 266 | |||
| 267 | public function getIdentity($name = 'Customer') |
||
| 273 | |||
| 274 | /** |
||
| 275 | * |
||
| 276 | * @param string $navigator |
||
| 277 | * @return \Magium\Magento\Navigators\BaseMenuNavigator |
||
| 278 | */ |
||
| 279 | |||
| 280 | public function getNavigator($navigator = 'BaseMenu') |
||
| 286 | |||
| 287 | public function getAssertion($assertion) |
||
| 293 | |||
| 294 | /** |
||
| 295 | * |
||
| 296 | * @param string $extractor |
||
| 297 | * @return \Magium\Extractors\AbstractExtractor |
||
| 298 | */ |
||
| 299 | |||
| 300 | public function getExtractor($extractor) |
||
| 306 | |||
| 307 | /** |
||
| 308 | * Sleep the specified amount of time. |
||
| 309 | * |
||
| 310 | * Options: 1s (1 second), 1ms (1 millisecond), 1us (1 microsecond), 1ns (1 nanosecond) |
||
| 311 | * |
||
| 312 | * @param $time |
||
| 313 | */ |
||
| 314 | |||
| 315 | public function sleep($time) |
||
| 329 | |||
| 330 | |||
| 331 | public function commandOpen($url) |
||
| 335 | |||
| 336 | |||
| 337 | /** |
||
| 338 | * @return \Magium\Util\Log\Logger |
||
| 339 | */ |
||
| 340 | |||
| 341 | public function getLogger() |
||
| 345 | |||
| 346 | public function get($class) |
||
| 355 | |||
| 356 | |||
| 357 | public function assertElementExists($selector, $by = 'byId') |
||
| 361 | |||
| 362 | public function assertTitleEquals($title) |
||
| 367 | |||
| 368 | |||
| 369 | public function assertTitleContains($title) |
||
| 374 | |||
| 375 | |||
| 376 | public function assertNotTitleEquals($title) |
||
| 381 | |||
| 382 | |||
| 383 | public function assertNotTitleContains($title) |
||
| 388 | |||
| 389 | public function assertURLEquals($url) |
||
| 394 | |||
| 395 | public function assertURLContains($url) |
||
| 400 | |||
| 401 | |||
| 402 | public function assertURLNotEquals($url) |
||
| 407 | |||
| 408 | public function assertURLNotContains($url) |
||
| 413 | |||
| 414 | protected function elementAssertion($selector, $by, $name) |
||
| 421 | |||
| 422 | public function assertElementDisplayed($selector, $by = 'byId') |
||
| 426 | |||
| 427 | public function assertElementNotDisplayed($selector, $by = 'byId') |
||
| 439 | |||
| 440 | public function assertElementNotExists($selector, $by = 'byId') |
||
| 444 | |||
| 445 | /** |
||
| 446 | * @return LoggingAssertionExecutor |
||
| 447 | */ |
||
| 448 | |||
| 449 | public function getAssertionLogger() |
||
| 453 | |||
| 454 | public function switchThemeConfiguration($fullyQualifiedClassName) |
||
| 477 | |||
| 478 | public static function assertWebDriverElement($element) |
||
| 482 | |||
| 483 | public function assertElementHasText($node, $text) |
||
| 491 | |||
| 492 | public function assertPageHasText($text) |
||
| 502 | |||
| 503 | public function assertPageNotHasText($text) |
||
| 512 | |||
| 513 | /** |
||
| 514 | * @param $xpath |
||
| 515 | * @return \Facebook\WebDriver\Remote\RemoteWebElement |
||
| 516 | */ |
||
| 517 | |||
| 518 | public function byXpath($xpath) |
||
| 522 | |||
| 523 | /** |
||
| 524 | * @param $id |
||
| 525 | * @return \Facebook\WebDriver\Remote\RemoteWebElement |
||
| 526 | */ |
||
| 527 | |||
| 528 | public function byId($id) |
||
| 532 | |||
| 533 | /** |
||
| 534 | * @param $selector |
||
| 535 | * @return \Facebook\WebDriver\Remote\RemoteWebElement |
||
| 536 | */ |
||
| 537 | |||
| 538 | public function byCssSelector($selector) |
||
| 542 | |||
| 543 | protected function getElementByTextXpath($xpathTemplate, $text, $specificNodeType = null, $parentElementSelector = null) |
||
| 562 | |||
| 563 | /** |
||
| 564 | * @param string $text |
||
| 565 | * @param string $specificNodeType |
||
| 566 | * @param string $parentElementSelector |
||
| 567 | * @return \Facebook\WebDriver\Remote\RemoteWebElement |
||
| 568 | */ |
||
| 569 | public function byText($text, $specificNodeType = null, $parentElementSelector = null) |
||
| 574 | |||
| 575 | |||
| 576 | /** |
||
| 577 | * @param string $text |
||
| 578 | * @param string $specificNodeType |
||
| 579 | * @param string $parentElementSelector |
||
| 580 | * @return \Facebook\WebDriver\Remote\RemoteWebElement |
||
| 581 | */ |
||
| 582 | public function byContainsText($text, $specificNodeType = null, $parentElementSelector = null) |
||
| 587 | |||
| 588 | /** |
||
| 589 | * @return \Magium\Util\Translator\Translator |
||
| 590 | */ |
||
| 591 | |||
| 592 | public function getTranslator() |
||
| 596 | |||
| 597 | public function addTranslationCsvFile($file, $locale) |
||
| 601 | } |
||
| 602 |