Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
IndexerDimensionMode.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
19 use PHPUnit\Framework\TestCase;
20 
25 {
27  private $cacheTypeList;
28 
30  private $configReader;
31 
33  private $modeSwitcher;
34 
36  private $objectManager;
37 
39  private $db;
40 
42  private $isDimensionMode = false;
43 
47  private function restoreDb()
48  {
49  $this->db = Bootstrap::getInstance()->getBootstrap()->getApplication()->getDbInstance();
50  $this->objectManager = Bootstrap::getObjectManager();
51  $this->db->restoreFromDbDump();
52  $this->cacheTypeList = $this->objectManager->get(TypeListInterface::class);
53  $this->cacheTypeList->cleanType('config');
54  $this->objectManager->get(Config::class)->clean();
55  }
56 
62  private function setDimensionMode(string $mode, TestCase $test)
63  {
64  $this->objectManager = Bootstrap::getObjectManager();
65  $this->modeSwitcher = $this->objectManager->get(ModeSwitcher::class);
66  $this->configReader = $this->objectManager->get(ScopeConfigInterface::class);
67  $this->cacheTypeList = $this->objectManager->get(TypeListInterface::class);
68 
69  $this->configReader->clean();
70  $previousMode = $this->configReader->getValue(ModeSwitcherConfiguration::XML_PATH_PRICE_DIMENSIONS_MODE) ?:
72 
73  if ($previousMode !== $mode) {
74  //Create new tables and move data
75  $this->modeSwitcher->switchMode($mode, $previousMode);
76  $this->objectManager->get(Config::class)->clean();
77  } else {
78  $this->fail('Dimensions mode for indexer has not been changed', $test);
79  }
80  }
81 
89  public function startTest(TestCase $test)
90  {
91  $source = $test->getAnnotations();
92 
93  if (isset($source['method']['magentoIndexerDimensionMode'])) {
94  $annotations = $source['method']['magentoIndexerDimensionMode'];
95  } elseif (isset($source['class']['magentoIndexerDimensionMode'])) {
96  $annotations = $source['class']['magentoIndexerDimensionMode'];
97  } else {
98  return;
99  }
100 
101  $dbIsolation = $source['method']['magentoDbIsolation']
102  ?? $source['class']['magentoDbIsolation']
103  ?? ['disabled'];
104 
105  if ($dbIsolation[0] != 'disabled') {
106  $this->fail("Invalid @magentoDbIsolation declaration: $dbIsolation[0]", $test);
107  }
108 
109  list($indexerType, $indexerMode) = explode(' ', $annotations[0]);
110 
111  if ($indexerType == Processor::INDEXER_ID) {
112  $this->isDimensionMode = true;
113  $this->setDimensionMode($indexerMode, $test);
114  }
115  }
116 
122  public function endTest()
123  {
124  if ($this->isDimensionMode) {
125  $this->restoreDb();
126  $this->isDimensionMode = false;
127  }
128  }
129 
137  private function fail($message, TestCase $test)
138  {
139  $test->fail("{$message} in the test '{$test->toString()}'");
140  }
141 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$source
Definition: source.php:23
$message
if($exist=($block->getProductCollection() && $block->getProductCollection() ->getSize())) $mode
Definition: grid.phtml:15