Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PriceIndexerDimensionsModeSetCommandTest.php
Go to the documentation of this file.
1 <?php
7 
9 use Symfony\Component\Console\Tester\CommandTester;
13 
18 {
20  private $objectManager;
21 
23  private $command;
24 
26  private $commandTester;
27 
31  public function setUp()
32  {
33  $this->objectManager = Bootstrap::getObjectManager();
34 
35  $this->objectManager->get(\Magento\TestFramework\App\Config::class)->clean();
36 
37  $this->command = $this->objectManager->create(
38  \Magento\Indexer\Console\Command\IndexerSetDimensionsModeCommand::class
39  );
40 
41  $this->commandTester = new CommandTester($this->command);
42 
43  parent::setUp();
44  }
45 
49  public static function setUpBeforeClass()
50  {
51  $db = Bootstrap::getInstance()->getBootstrap()
52  ->getApplication()
53  ->getDbInstance();
54  if (!$db->isDbDumpExists()) {
55  throw new \LogicException('DB dump does not exist.');
56  }
57  $db->restoreFromDbDump();
58 
59  parent::setUpBeforeClass();
60  }
61 
70  public function testSwitchMode($previousMode, $currentMode)
71  {
72  $this->commandTester->execute(
73  [
74  'indexer' => 'catalog_product_price',
75  'mode' => $currentMode,
76  ]
77  );
78  $expectedOutput = 'Dimensions mode for indexer "Product Price" was changed from \''
79  . $previousMode . '\' to \'' . $currentMode . '\'' . PHP_EOL;
80 
81  $actualOutput = $this->commandTester->getDisplay();
82 
83  $this->assertContains($expectedOutput, $actualOutput);
84 
85  static::assertEquals(
87  $this->commandTester->getStatusCode(),
88  $this->commandTester->getDisplay(true)
89  );
90  }
91 
96  public function modesDataProvider()
97  {
98  return [
101  [
104  ],
105  [
108  ],
109  [
112  ],
113  [
116  ],
119  ];
120  }
121 
126  public function testSwitchModeForSameMode()
127  {
128  $this->commandTester->execute(
129  [
130  'indexer' => 'catalog_product_price',
132  ]
133  );
134  $expectedOutput = 'Dimensions mode for indexer "Product Price" has not been changed' . PHP_EOL;
135 
136  $actualOutput = $this->commandTester->getDisplay();
137 
138  $this->assertContains($expectedOutput, $actualOutput);
139 
140  static::assertEquals(
142  $this->commandTester->getStatusCode(),
143  $this->commandTester->getDisplay(true)
144  );
145  }
146 
154  {
155  $this->commandTester->execute(
156  [
157  'indexer' => 'indexer_not_valid'
158  ]
159  );
160  }
161 }