public function testEndTestIsolationController() { /** @var $controllerTestCase Magento_Test_TestCase_ControllerAbstract */ $controllerTestCase = $this->getMockForAbstractClass('Magento_Test_TestCase_ControllerAbstract'); $this->_listener->startTest($controllerTestCase); $this->_annotation->expects($this->once())->method('_isolateApp'); $this->_annotation->endTest(); }
/** * 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); } } }
/** * 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; } } }
/** * 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 setUp() { $this->_listener = new Magento_Test_Listener(); $this->_listener->startTest($this); $this->_annotation = $this->getMock('Magento_Test_Listener_Annotation_FixtureTestSingleConnection', array('_startTransaction', '_rollbackTransaction', '_applyOneFixture'), array($this->_listener)); }
protected function tearDown() { $this->_listener->endTest($this->_listener->getCurrentTest(), 0); }
$globalEtcFiles = "../../../app/etc/*.xml"; } $globalEtcFiles .= ';etc/integration-tests-config.xml'; if (defined('TESTS_MODULE_CONFIG_FILES') && TESTS_MODULE_CONFIG_FILES) { $moduleEtcFiles = TESTS_MODULE_CONFIG_FILES; } else { $moduleEtcFiles = "../../../app/etc/modules/*.xml"; } $developerMode = false; if (defined('TESTS_MAGENTO_DEVELOPER_MODE') && TESTS_MAGENTO_DEVELOPER_MODE == 'enabled') { $developerMode = true; } Magento_Test_Bootstrap::setInstance(new Magento_Test_Bootstrap(realpath("{$baseDir}/../../../"), $localXmlFile, $globalEtcFiles, $moduleEtcFiles, "{$baseDir}/tmp", $cleanupAction, $developerMode)); /* Enable profiler if necessary */ if (defined('TESTS_PROFILER_FILE') && TESTS_PROFILER_FILE) { Magento_Profiler::registerOutput(new Magento_Profiler_Output_Csvfile($baseDir . DIRECTORY_SEPARATOR . TESTS_PROFILER_FILE)); } /* Enable profiler with bamboo friendly output format */ if (defined('TESTS_BAMBOO_PROFILER_FILE') && defined('TESTS_BAMBOO_PROFILER_METRICS_FILE')) { Magento_Profiler::registerOutput(new Magento_Test_Profiler_OutputBamboo($baseDir . DIRECTORY_SEPARATOR . TESTS_BAMBOO_PROFILER_FILE, require $baseDir . DIRECTORY_SEPARATOR . TESTS_BAMBOO_PROFILER_METRICS_FILE)); } /* Activate custom annotations in doc comments */ /* * Note: order of registering (and applying) annotations is important. * To allow config fixtures to deal with fixture stores, data fixtures should be processed before config fixtures. */ Magento_Test_Listener::registerObserver('Magento_Test_Listener_Annotation_Isolation'); Magento_Test_Listener::registerObserver('Magento_Test_Listener_Annotation_Fixture'); Magento_Test_Listener::registerObserver('Magento_Test_Listener_Annotation_Config'); /* Unset declared global variables to release PHPUnit from maintaining their values between tests */ unset($baseDir, $localXmlFile, $globalEtcFiles, $moduleEtcFiles);
public function testEndTest() { $this->_listener->endTest($this, 0); Magento_Test_ListenerTestObserver::assertCalledMethods(array(array('Magento_Test_ListenerTestObserverTwo', 'endTest'), array('Magento_Test_ListenerTestObserverOne', 'endTest'))); }