/** * Execute fixture scripts if any * * @param array $fixtures */ protected function _applyFixtures(array $fixtures) { if (empty($fixtures)) { return; } /* Start transaction before applying first fixture to be able to revert them all further */ if (empty($this->_appliedFixtures)) { if (!$this->_isSingleConnection()) { throw new Exception('Transaction fixtures with 2 connections are not implemented yet.'); } $this->_startTransaction(); } /* Execute fixture scripts */ foreach ($fixtures as $fixture) { if (strpos($fixture, '\\') !== false) { throw new Exception('The "\\" symbol is not allowed for fixture definition.'); } $fixtureMethod = array(get_class($this->_listener->getCurrentTest()), $fixture); $fixtureScript = realpath(__DIR__ . '/../../../../../testsuite') . DIRECTORY_SEPARATOR . $fixture; /* Skip already applied fixtures */ if (in_array($fixtureMethod, $this->_appliedFixtures, true) || in_array($fixtureScript, $this->_appliedFixtures, true)) { continue; } if (is_callable($fixtureMethod)) { $this->_applyOneFixture($fixtureMethod); $this->_appliedFixtures[] = $fixtureMethod; } else { $this->_applyOneFixture($fixtureScript); $this->_appliedFixtures[] = $fixtureScript; } } }
/** * Assign required config values and save original ones */ protected function _assignConfigData() { if (!$this->_listener || !$this->_listener->getCurrentTest()) { return; } $annotations = $this->_listener->getCurrentTest()->getAnnotations(); if (!isset($annotations['method']['magentoConfigFixture'])) { return; } foreach ($annotations['method']['magentoConfigFixture'] as $configPathAndValue) { if (preg_match('/^.+?(?=_store\\s)/', $configPathAndValue, $matches)) { /* Store-scoped config value */ $storeCode = $matches[0] != 'current' ? $matches[0] : ''; list(, $configPath, $requiredValue) = preg_split('/\\s+/', $configPathAndValue, 3); $originalValue = $this->_getConfigValue($configPath, $storeCode); $this->_storeConfigValues[$storeCode][$configPath] = $originalValue; $this->_setConfigValue($configPath, $requiredValue, $storeCode); } else { /* Global config value */ list($configPath, $requiredValue) = preg_split('/\\s+/', $configPathAndValue, 2); $originalValue = $this->_getConfigValue($configPath); $this->_globalConfigValues[$configPath] = $originalValue; $this->_setConfigValue($configPath, $requiredValue); } } }
public function testGetCurrentTest() { $this->assertNull($this->_listener->getCurrentTest()); $this->_listener->startTest($this); $this->assertSame($this, $this->_listener->getCurrentTest()); $this->_listener->endTest($this, 0); $this->assertNull($this->_listener->getCurrentTest()); }
/** * Handler for 'endTest' event */ public function endTest() { $test = $this->_listener->getCurrentTest(); $this->_hasNonIsolatedTests = true; /* Determine an isolation from doc comment */ $annotations = $test->getAnnotations(); if (isset($annotations['method']['magentoAppIsolation'])) { $isolation = $annotations['method']['magentoAppIsolation']; if ($isolation !== array('enabled') && $isolation !== array('disabled')) { throw new Exception('Invalid "@magentoAppIsolation" annotation, can be "enabled" or "disabled" only.'); } $isIsolationEnabled = $isolation === array('enabled'); } else { /* Controller tests should be isolated by default */ $isIsolationEnabled = $test instanceof Magento_Test_TestCase_ControllerAbstract; } if ($isIsolationEnabled) { $this->_isolateApp(); } }
protected function tearDown() { $this->_listener->endTest($this->_listener->getCurrentTest(), 0); }