_application = $application; } /** * Isolate global application objects */ protected function _isolateApp() { if ($this->_hasNonIsolatedTests) { $this->_application->reinitialize(); $this->_hasNonIsolatedTests = false; } } /** * Isolate application before running test case */ public function startTestSuite() { $this->_isolateApp(); } /** * Handler for 'endTest' event * * @param \PHPUnit_Framework_TestCase $test * @throws \Magento\Framework\Exception\LocalizedException */ public function endTest(\PHPUnit_Framework_TestCase $test) { $this->_hasNonIsolatedTests = true; /* Determine an isolation from doc comment */ $annotations = $test->getAnnotations(); $annotations = array_replace((array) $annotations['class'], (array) $annotations['method']); if (isset($annotations['magentoAppIsolation'])) { $isolation = $annotations['magentoAppIsolation']; if ($isolation !== ['enabled'] && $isolation !== ['disabled']) { throw new \Magento\Framework\Exception\LocalizedException( __('Invalid "@magentoAppIsolation" annotation, can be "enabled" or "disabled" only.') ); } $isIsolationEnabled = $isolation === ['enabled']; } else { /* Controller tests should be isolated by default */ $isIsolationEnabled = $test instanceof \Magento\TestFramework\TestCase\AbstractController; } if ($isIsolationEnabled) { $this->_isolateApp(); } } }