db = Bootstrap::getInstance()->getBootstrap()->getApplication()->getDbInstance(); $this->objectManager = Bootstrap::getObjectManager(); $this->db->restoreFromDbDump(); $this->cacheTypeList = $this->objectManager->get(TypeListInterface::class); $this->cacheTypeList->cleanType('config'); $this->objectManager->get(Config::class)->clean(); } /** * @param string $mode * @param TestCase $test * @throws \Exception */ private function setDimensionMode(string $mode, TestCase $test) { $this->objectManager = Bootstrap::getObjectManager(); $this->modeSwitcher = $this->objectManager->get(ModeSwitcher::class); $this->configReader = $this->objectManager->get(ScopeConfigInterface::class); $this->cacheTypeList = $this->objectManager->get(TypeListInterface::class); $this->configReader->clean(); $previousMode = $this->configReader->getValue(ModeSwitcherConfiguration::XML_PATH_PRICE_DIMENSIONS_MODE) ?: DimensionModeConfiguration::DIMENSION_NONE; if ($previousMode !== $mode) { //Create new tables and move data $this->modeSwitcher->switchMode($mode, $previousMode); $this->objectManager->get(Config::class)->clean(); } else { $this->fail('Dimensions mode for indexer has not been changed', $test); } } /** * Handler for 'startTest' event * * @param TestCase $test * @return void * @throws \Exception */ public function startTest(TestCase $test) { $source = $test->getAnnotations(); if (isset($source['method']['magentoIndexerDimensionMode'])) { $annotations = $source['method']['magentoIndexerDimensionMode']; } elseif (isset($source['class']['magentoIndexerDimensionMode'])) { $annotations = $source['class']['magentoIndexerDimensionMode']; } else { return; } $dbIsolation = $source['method']['magentoDbIsolation'] ?? $source['class']['magentoDbIsolation'] ?? ['disabled']; if ($dbIsolation[0] != 'disabled') { $this->fail("Invalid @magentoDbIsolation declaration: $dbIsolation[0]", $test); } list($indexerType, $indexerMode) = explode(' ', $annotations[0]); if ($indexerType == Processor::INDEXER_ID) { $this->isDimensionMode = true; $this->setDimensionMode($indexerMode, $test); } } /** * Handler for 'endTest' event * * @return void */ public function endTest() { if ($this->isDimensionMode) { $this->restoreDb(); $this->isDimensionMode = false; } } /** * Fails the test with specified error message * * @param string $message * @param TestCase $test * @throws \Exception */ private function fail($message, TestCase $test) { $test->fail("{$message} in the test '{$test->toString()}'"); } }