Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/2.2-develop' into MAGETWO-75086
Browse files Browse the repository at this point in the history
  • Loading branch information
OlgaVasyltsun committed Jul 26, 2018
2 parents 1c72191 + 7be2b8c commit 4901a5f
Show file tree
Hide file tree
Showing 22 changed files with 1,647 additions and 3 deletions.
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@
"lusitanian/oauth": "~0.8.10",
"sebastian/phpcpd": "2.0.4"
},
"suggest": {
"ext-pcntl": "Need for run processes in parallel mode"
},
"replace": {
"magento/module-marketplace": "100.2.2",
"magento/module-admin-notification": "100.2.3",
Expand Down
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()}'");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ public function install($cleanup)
);

// right after a clean installation, store DB dump for future reuse in tests or running the test suite again
if (!$db->isDbDumpExists()) {
if (!$db->isDbDumpExists() || $cleanup) {
$this->getDbInstance()->storeDbDump();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ protected function _getSubscribers(\Magento\TestFramework\Application $applicati
new \Magento\TestFramework\Isolation\WorkingDirectory(),
new \Magento\TestFramework\Isolation\DeploymentConfig(),
new \Magento\TestFramework\Annotation\AppIsolation($application),
new \Magento\TestFramework\Annotation\IndexerDimensionMode($application),
new \Magento\TestFramework\Isolation\AppConfig(),
new \Magento\TestFramework\Annotation\ConfigFixture(),
new \Magento\TestFramework\Annotation\DataFixtureBeforeTransaction($this->_fixturesBaseDir),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

/**
* @magentoDataFixture Magento/Bundle/_files/product.php
* @magentoDbIsolation disabled
* @magentoAppArea frontend
*/
class BundleTest extends \PHPUnit\Framework\TestCase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class ProductTest extends \Magento\TestFramework\TestCase\AbstractController
{
/**
* @magentoDataFixture Magento/Bundle/_files/product.php
* @magentoDbIsolation disabled
*/
public function testViewAction()
{
Expand Down
Loading

0 comments on commit 4901a5f

Please sign in to comment.