| Conditions | 7 |
| Paths | 9 |
| Total Lines | 57 |
| Code Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 42 | public function initialize(AbstractTestCase $testCase, $force = false) |
||
| 43 | { |
||
| 44 | if ($this->initialized === $testCase && !$force) { |
||
| 45 | return; |
||
| 46 | } |
||
| 47 | $this->configureDi($testCase); |
||
| 48 | $testCase->getDi()->instanceManager()->addSharedInstance(AbstractTestCase::getMasterListener(), 'Magium\Util\Phpunit\MasterListener'); |
||
| 49 | |||
| 50 | $rc = new \ReflectionClass($testCase); |
||
| 51 | while ($rc->getParentClass()) { |
||
| 52 | $class = $rc->getParentClass()->getName(); |
||
| 53 | $testCase->getDi()->instanceManager()->addSharedInstance($testCase, $class); |
||
| 54 | $rc = new \ReflectionClass($class); |
||
| 55 | } |
||
| 56 | $webDriver = $testCase->getDi()->get('Magium\WebDriver\WebDriver'); |
||
| 57 | if ($webDriver instanceof WebDriver) { |
||
| 58 | $testCase->setWebdriver($webDriver); |
||
| 59 | $testCase->setTypePreference( |
||
| 60 | 'Facebook\WebDriver\WebDriver', |
||
| 61 | 'Magium\WebDriver\WebDriver' |
||
| 62 | ); |
||
| 63 | $testCase->setTypePreference( |
||
| 64 | 'Facebook\WebDriver\RemoteWebDriver', |
||
| 65 | 'Magium\WebDriver\WebDriver' |
||
| 66 | ); |
||
| 67 | } else { |
||
| 68 | throw new InvalidConfigurationException('DIC has misconfigured WebDriver object'); |
||
| 69 | } |
||
| 70 | |||
| 71 | $remote = $testCase->getDi()->get('Magium\WebDriver\LoggingRemoteExecuteMethod'); |
||
| 72 | if ($remote instanceof LoggingRemoteExecuteMethod) { |
||
| 73 | $testCase->getWebdriver()->setRemoteExecuteMethod($remote); |
||
| 74 | } else { |
||
| 75 | throw new InvalidConfigurationException('DIC has invalid logger configured'); |
||
| 76 | } |
||
| 77 | |||
| 78 | // This is going to be refactored in a completely backwards compatible way. Currently, because the DiC is |
||
| 79 | // rebuilt for each request it doesn't maintain state between tests. This is a good thing... except when |
||
| 80 | // something that understands it (the MasterListener) does restain state. |
||
| 81 | |||
| 82 | $clairvoyant = $this->initClairvoyant($testCase); |
||
| 83 | |||
| 84 | /* @var $clairvoyant \Magium\Util\Api\Clairvoyant\Clairvoyant */ |
||
| 85 | $request = $testCase->get('Magium\Util\Api\Request'); |
||
| 86 | if ($request instanceof Request) { |
||
| 87 | $clairvoyant->setApiRequest($request); |
||
| 88 | } |
||
| 89 | $clairvoyant->reset(); |
||
| 90 | $clairvoyant->setSessionId($testCase->getWebdriver()->getSessionID()); |
||
| 91 | $clairvoyant->setCapability($this->testCaseConfigurationObject->getCapabilities()); |
||
| 92 | $testCase->getLogger()->addWriter($clairvoyant); |
||
| 93 | $testCase->getLogger()->addCharacteristic(Logger::CHARACTERISTIC_BROWSER, $testCase->getWebdriver()->getBrowser()); |
||
| 94 | $testCase->getLogger()->addCharacteristic(Logger::CHARACTERISTIC_OPERATING_SYSTEM, $testCase->getWebdriver()->getPlatform()); |
||
| 95 | |||
| 96 | RegistrationListener::executeCallbacks($testCase); |
||
| 97 | $this->initialized = $testCase; |
||
| 98 | } |
||
| 99 | |||
| 216 | } |