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 |
||
| 32 | abstract class AbstractTestCase extends \PHPUnit_Framework_TestCase |
||
| 33 | { |
||
| 34 | |||
| 35 | protected static $baseNamespaces = []; |
||
| 36 | |||
| 37 | protected $baseThemeClass = 'Magium\Themes\ThemeConfigurationInterface'; |
||
| 38 | |||
| 39 | protected $postCallbacks = []; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @var MasterListener |
||
| 43 | */ |
||
| 44 | |||
| 45 | protected static $masterListener; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @var \Magium\WebDriver\WebDriver |
||
| 49 | */ |
||
| 50 | protected $webdriver; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @var Di |
||
| 54 | */ |
||
| 55 | |||
| 56 | protected $di; |
||
| 57 | |||
| 58 | protected $textElementNodeSearch = [ |
||
| 59 | 'button', 'span', 'a', 'li', 'label', 'option', 'h1', 'h2', 'h3', 'td' |
||
| 60 | ]; |
||
| 61 | |||
| 62 | protected $testCaseConfiguration = 'Magium\TestCaseConfiguration'; |
||
| 63 | |||
| 64 | protected $testCaseConfigurationObject; |
||
| 65 | |||
| 66 | const BY_XPATH = 'byXpath'; |
||
| 67 | const BY_ID = 'byId'; |
||
| 68 | const BY_CSS_SELECTOR = 'byCssSelector'; |
||
| 69 | const BY_TEXT = 'byText'; |
||
| 70 | |||
| 71 | protected static $registrationCallbacks; |
||
| 72 | |||
| 73 | protected function setUp() |
||
| 83 | |||
| 84 | /** |
||
| 85 | * @return Di |
||
| 86 | */ |
||
| 87 | public function getDi() |
||
| 91 | |||
| 92 | /** |
||
| 93 | * @param Di $di |
||
| 94 | */ |
||
| 95 | public function setDi($di) |
||
| 99 | |||
| 100 | /** |
||
| 101 | * @return WebDriver |
||
| 102 | */ |
||
| 103 | public function getWebdriver() |
||
| 107 | |||
| 108 | /** |
||
| 109 | * @param WebDriver $webdriver |
||
| 110 | */ |
||
| 111 | public function setWebdriver(WebDriver $webdriver) |
||
| 115 | |||
| 116 | |||
| 117 | public function __construct($name = null, array $data = [], $dataName = null, TestCaseConfiguration $configuration = null) |
||
| 124 | |||
| 125 | public function setTestResultObject(PHPUnit_Framework_TestResult $result) |
||
| 133 | |||
| 134 | /** |
||
| 135 | * @return MasterListener |
||
| 136 | */ |
||
| 137 | |||
| 138 | public static function getMasterListener() |
||
| 145 | |||
| 146 | protected function tearDown() |
||
| 159 | |||
| 160 | |||
| 161 | public function filterWebDriverAction($by) |
||
| 174 | |||
| 175 | public function assertElementClickable($selector, $by = WebDriver::BY_ID) |
||
| 179 | |||
| 180 | |||
| 181 | public function assertElementNotClickable($selector, $by = WebDriver::BY_ID) |
||
| 186 | |||
| 187 | public function setTestCaseConfigurationClass($class) |
||
| 191 | |||
| 192 | public static function addBaseNamespace($namespace) |
||
| 198 | |||
| 199 | public static function resolveClass( $class, $prefix = null) |
||
| 220 | |||
| 221 | public function setTypePreference($type, $preference) |
||
| 229 | |||
| 230 | protected function normalizeClassRequest($class) |
||
| 234 | |||
| 235 | public function addPostTestCallback($callback) |
||
| 242 | |||
| 243 | /** |
||
| 244 | |||
| 245 | * @param string $theme |
||
| 246 | * @return \Magium\Themes\ThemeConfigurationInterface |
||
| 247 | */ |
||
| 248 | |||
| 249 | public function getTheme($theme = null) |
||
| 257 | |||
| 258 | /** |
||
| 259 | * |
||
| 260 | * @param string $action |
||
| 261 | * @return mixed |
||
| 262 | */ |
||
| 263 | |||
| 264 | public function getAction($action) |
||
| 270 | |||
| 271 | |||
| 272 | /** |
||
| 273 | * @param string $name |
||
| 274 | * @return \Magium\Magento\Identities\AbstractEntity |
||
| 275 | */ |
||
| 276 | |||
| 277 | public function getIdentity($name = 'Customer') |
||
| 283 | |||
| 284 | /** |
||
| 285 | * |
||
| 286 | * @param string $navigator |
||
| 287 | * @return \Magium\Magento\Navigators\BaseMenuNavigator |
||
| 288 | */ |
||
| 289 | |||
| 290 | public function getNavigator($navigator = 'BaseMenu') |
||
| 296 | |||
| 297 | public function getAssertion($assertion) |
||
| 303 | |||
| 304 | /** |
||
| 305 | * |
||
| 306 | * @param string $extractor |
||
| 307 | * @return \Magium\Extractors\AbstractExtractor |
||
| 308 | */ |
||
| 309 | |||
| 310 | public function getExtractor($extractor) |
||
| 316 | |||
| 317 | /** |
||
| 318 | * Sleep the specified amount of time. |
||
| 319 | * |
||
| 320 | * Options: 1s (1 second), 1ms (1 millisecond), 1us (1 microsecond), 1ns (1 nanosecond) |
||
| 321 | * |
||
| 322 | * @param $time |
||
| 323 | */ |
||
| 324 | |||
| 325 | public function sleep($time) |
||
| 339 | |||
| 340 | |||
| 341 | public function commandOpen($url) |
||
| 345 | |||
| 346 | |||
| 347 | /** |
||
| 348 | * @return \Magium\Util\Log\Logger |
||
| 349 | */ |
||
| 350 | |||
| 351 | public function getLogger() |
||
| 355 | |||
| 356 | public function get($class) |
||
| 365 | |||
| 366 | |||
| 367 | public function assertElementExists($selector, $by = 'byId') |
||
| 371 | |||
| 372 | public function assertTitleEquals($title) |
||
| 377 | |||
| 378 | |||
| 379 | public function assertTitleContains($title) |
||
| 384 | |||
| 385 | |||
| 386 | public function assertNotTitleEquals($title) |
||
| 391 | |||
| 392 | |||
| 393 | public function assertNotTitleContains($title) |
||
| 398 | |||
| 399 | public function assertURLEquals($url) |
||
| 404 | |||
| 405 | public function assertURLContains($url) |
||
| 410 | |||
| 411 | |||
| 412 | public function assertURLNotEquals($url) |
||
| 417 | |||
| 418 | public function assertURLNotContains($url) |
||
| 423 | |||
| 424 | protected function elementAssertion($selector, $by, $name) |
||
| 431 | |||
| 432 | public function assertElementDisplayed($selector, $by = 'byId') |
||
| 436 | |||
| 437 | public function assertElementNotDisplayed($selector, $by = 'byId') |
||
| 449 | |||
| 450 | public function assertElementNotExists($selector, $by = 'byId') |
||
| 454 | |||
| 455 | /** |
||
| 456 | * @return LoggingAssertionExecutor |
||
| 457 | */ |
||
| 458 | |||
| 459 | public function getAssertionLogger() |
||
| 463 | |||
| 464 | public function switchThemeConfiguration($fullyQualifiedClassName) |
||
| 487 | |||
| 488 | public static function assertWebDriverElement($element) |
||
| 492 | |||
| 493 | public function assertElementHasText($node, $text) |
||
| 501 | |||
| 502 | public function assertPageHasText($text) |
||
| 512 | |||
| 513 | public function assertPageNotHasText($text) |
||
| 522 | |||
| 523 | /** |
||
| 524 | * @param $xpath |
||
| 525 | * @return \Facebook\WebDriver\Remote\RemoteWebElement |
||
| 526 | */ |
||
| 527 | |||
| 528 | public function byXpath($xpath) |
||
| 532 | |||
| 533 | /** |
||
| 534 | * @param $id |
||
| 535 | * @return \Facebook\WebDriver\Remote\RemoteWebElement |
||
| 536 | */ |
||
| 537 | |||
| 538 | public function byId($id) |
||
| 542 | |||
| 543 | /** |
||
| 544 | * @param $selector |
||
| 545 | * @return \Facebook\WebDriver\Remote\RemoteWebElement |
||
| 546 | */ |
||
| 547 | |||
| 548 | public function byCssSelector($selector) |
||
| 552 | |||
| 553 | protected function getElementByTextXpath($xpathTemplate, $text, $specificNodeType = null, $parentElementSelector = null) |
||
| 572 | |||
| 573 | /** |
||
| 574 | * @param string $text |
||
| 575 | * @param string $specificNodeType |
||
| 576 | * @param string $parentElementSelector |
||
| 577 | * @return \Facebook\WebDriver\Remote\RemoteWebElement |
||
| 578 | */ |
||
| 579 | public function byText($text, $specificNodeType = null, $parentElementSelector = null) |
||
| 584 | |||
| 585 | |||
| 586 | /** |
||
| 587 | * @param string $text |
||
| 588 | * @param string $specificNodeType |
||
| 589 | * @param string $parentElementSelector |
||
| 590 | * @return \Facebook\WebDriver\Remote\RemoteWebElement |
||
| 591 | */ |
||
| 592 | public function byContainsText($text, $specificNodeType = null, $parentElementSelector = null) |
||
| 597 | |||
| 598 | /** |
||
| 599 | * @return \Magium\Util\Translator\Translator |
||
| 600 | */ |
||
| 601 | |||
| 602 | public function getTranslator() |
||
| 606 | |||
| 607 | public function addTranslationCsvFile($file, $locale) |
||
| 611 | } |
||
| 612 |