| Conditions | 7 |
| Paths | 9 |
| Total Lines | 57 |
| Code Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 55 | public function initialize(AbstractTestCase $testCase, $force = false) |
||
| 56 | { |
||
| 57 | if ($this->initialized === $testCase && !$force) { |
||
| 58 | return; |
||
| 59 | } |
||
| 60 | $this->configureDi($testCase); |
||
| 61 | $testCase->getDi()->instanceManager()->addSharedInstance(AbstractTestCase::getMasterListener(), 'Magium\Util\Phpunit\MasterListener'); |
||
| 62 | |||
| 63 | $rc = new \ReflectionClass($testCase); |
||
| 64 | while ($rc->getParentClass()) { |
||
| 65 | $class = $rc->getParentClass()->getName(); |
||
| 66 | $testCase->getDi()->instanceManager()->addSharedInstance($testCase, $class); |
||
| 67 | $rc = new \ReflectionClass($class); |
||
| 68 | } |
||
| 69 | $webDriver = $testCase->getDi()->get('Magium\WebDriver\WebDriver'); |
||
| 70 | if ($webDriver instanceof WebDriver) { |
||
| 71 | $testCase->setWebdriver($webDriver); |
||
| 72 | $testCase->setTypePreference( |
||
| 73 | 'Facebook\WebDriver\WebDriver', |
||
| 74 | 'Magium\WebDriver\WebDriver' |
||
| 75 | ); |
||
| 76 | $testCase->setTypePreference( |
||
| 77 | 'Facebook\WebDriver\RemoteWebDriver', |
||
| 78 | 'Magium\WebDriver\WebDriver' |
||
| 79 | ); |
||
| 80 | } else { |
||
| 81 | throw new InvalidConfigurationException('DIC has misconfigured WebDriver object'); |
||
| 82 | } |
||
| 83 | |||
| 84 | $remote = $testCase->getDi()->get('Magium\WebDriver\LoggingRemoteExecuteMethod'); |
||
| 85 | if ($remote instanceof LoggingRemoteExecuteMethod) { |
||
| 86 | $testCase->getWebdriver()->setRemoteExecuteMethod($remote); |
||
| 87 | } else { |
||
| 88 | throw new InvalidConfigurationException('DIC has invalid logger configured'); |
||
| 89 | } |
||
| 90 | |||
| 91 | // This is going to be refactored in a completely backwards compatible way. Currently, because the DiC is |
||
| 92 | // rebuilt for each request it doesn't maintain state between tests. This is a good thing... except when |
||
| 93 | // something that understands it (the MasterListener) does restain state. |
||
| 94 | |||
| 95 | $clairvoyant = $this->initClairvoyant($testCase); |
||
| 96 | |||
| 97 | /* @var $clairvoyant \Magium\Util\Api\Clairvoyant\Clairvoyant */ |
||
| 98 | $request = $testCase->get('Magium\Util\Api\Request'); |
||
| 99 | if ($request instanceof Request) { |
||
| 100 | $clairvoyant->setApiRequest($request); |
||
| 101 | } |
||
| 102 | $clairvoyant->reset(); |
||
| 103 | $clairvoyant->setSessionId($testCase->getWebdriver()->getSessionID()); |
||
| 104 | $clairvoyant->setCapability($this->testCaseConfigurationObject->getCapabilities()); |
||
| 105 | $testCase->getLogger()->addWriter($clairvoyant); |
||
| 106 | $testCase->getLogger()->addCharacteristic(Logger::CHARACTERISTIC_BROWSER, $testCase->getWebdriver()->getBrowser()); |
||
| 107 | $testCase->getLogger()->addCharacteristic(Logger::CHARACTERISTIC_OPERATING_SYSTEM, $testCase->getWebdriver()->getPlatform()); |
||
| 108 | |||
| 109 | RegistrationListener::executeCallbacks($testCase); |
||
| 110 | $this->initialized = $testCase; |
||
| 111 | } |
||
| 112 | |||
| 227 | } |