-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/2.2-develop' into MAGETWO-75086
- Loading branch information
Showing
22 changed files
with
1,647 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
146 changes: 146 additions & 0 deletions
146
dev/tests/integration/framework/Magento/TestFramework/Annotation/IndexerDimensionMode.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\TestFramework\Annotation; | ||
|
||
use Magento\Catalog\Model\Indexer\Product\Price\ModeSwitcher; | ||
use Magento\Catalog\Model\Indexer\Product\Price\Processor; | ||
use Magento\Framework\App\Cache\TypeListInterface; | ||
use Magento\Framework\App\Config\ConfigResource\ConfigInterface; | ||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\Framework\ObjectManagerInterface; | ||
use Magento\TestFramework\App\Config; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
use Magento\Catalog\Model\Indexer\Product\Price\DimensionModeConfiguration; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* Implementation of the @magentoIndexerDimensionMode DocBlock annotation | ||
*/ | ||
class IndexerDimensionMode | ||
{ | ||
/** @var TypeListInterface */ | ||
private $cacheTypeList; | ||
|
||
/** @var ScopeConfigInterface */ | ||
private $configReader; | ||
|
||
/** @var ModeSwitcher */ | ||
private $modeSwitcher; | ||
|
||
/** @var ConfigInterface */ | ||
private $configWriter; | ||
|
||
/** @var ObjectManagerInterface */ | ||
private $objectManager; | ||
|
||
/** @var \Magento\TestFramework\Db\Mysql */ | ||
private $db; | ||
|
||
/** @var bool */ | ||
private $isDimensionMode = false; | ||
|
||
private function restoreDb() | ||
{ | ||
$this->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 | ||
*/ | ||
private function setDimensionMode($mode, $test) | ||
{ | ||
$this->objectManager = Bootstrap::getObjectManager(); | ||
$this->modeSwitcher = $this->objectManager->get(ModeSwitcher::class); | ||
$this->configWriter = $this->objectManager->get(ConfigInterface::class); | ||
$this->configReader = $this->objectManager->get(ScopeConfigInterface::class); | ||
$this->cacheTypeList = $this->objectManager->get(TypeListInterface::class); | ||
|
||
$this->configReader->clean(); | ||
$previousMode = $this->configReader->getValue(ModeSwitcher::XML_PATH_PRICE_DIMENSIONS_MODE) ?: | ||
DimensionModeConfiguration::DIMENSION_NONE; | ||
|
||
if ($previousMode !== $mode) { | ||
//Create new tables and move data | ||
$this->modeSwitcher->createTables($mode); | ||
$this->modeSwitcher->moveData($mode, $previousMode); | ||
|
||
//Change config options | ||
$this->configWriter->saveConfig(ModeSwitcher::XML_PATH_PRICE_DIMENSIONS_MODE, $mode); | ||
$this->cacheTypeList->cleanType('config'); | ||
$this->objectManager->get(Config::class)->clean(); | ||
|
||
//Delete old tables | ||
$this->modeSwitcher->dropTables($previousMode); | ||
} else { | ||
$this->fail('Dimensions mode for indexer has not been changed', $test); | ||
} | ||
} | ||
|
||
/** | ||
* Handler for 'startTest' event | ||
* | ||
* @param TestCase $test | ||
* @return void | ||
*/ | ||
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()}'"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.