diff --git a/app/code/Magento/Indexer/Console/Command/AbstractIndexerCommand.php b/app/code/Magento/Indexer/Console/Command/AbstractIndexerCommand.php index 3ae1291f7dcaef90cdb2791c2cb5a198da1c08d1..36f9ec1dd5b273cb2b94efaa0266afb2495e09e8 100644 --- a/app/code/Magento/Indexer/Console/Command/AbstractIndexerCommand.php +++ b/app/code/Magento/Indexer/Console/Command/AbstractIndexerCommand.php @@ -5,10 +5,6 @@ */ namespace Magento\Indexer\Console\Command; -use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Input\InputOption; -use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Command\Command; use Magento\Indexer\Model\IndexerFactory; use Magento\Indexer\Model\Indexer\CollectionFactory; @@ -18,15 +14,16 @@ use Magento\Store\Model\StoreManager; use Magento\Framework\App\ObjectManagerFactory; /** - * An Abstract class for all Indexer related commands. + * An Abstract class for Indexer related commands. */ -class AbstractIndexerCommand extends Command +abstract class AbstractIndexerCommand extends Command { - /** + /**#@+ * Names of input arguments or options */ const INPUT_KEY_ALL = 'all'; const INPUT_KEY_INDEXERS = 'index'; + /**#@- */ /** * Collection of Indexers factory @@ -58,66 +55,13 @@ class AbstractIndexerCommand extends Command } /** - * Gets list of indexers - * - * @param InputInterface $input - * @param OutputInterface $output - * @return IndexerInterface[] - */ - protected function getIndexers(InputInterface $input, OutputInterface $output) - { - $inputArguments = $input->getArgument(self::INPUT_KEY_INDEXERS); - if (isset($inputArguments) && sizeof($inputArguments)>0) { - $indexes = implode(',', $inputArguments); - } else { - $indexes = self::INPUT_KEY_ALL; - } - $indexers = $this->parseIndexerString($indexes, $output); - return $indexers; - } - - /** - * Get list of options and arguments for the command - * - * @return mixed - */ - public function getInputList() - { - return [ - new InputOption(self::INPUT_KEY_ALL, 'a', InputOption::VALUE_NONE, 'All Indexes'), - new InputArgument( - self::INPUT_KEY_INDEXERS, - InputArgument::OPTIONAL | InputArgument::IS_ARRAY, - 'List of Indexes' - ), - ]; - } - - /** - * Parses string with indexers and return array of indexer instances + * Returns all indexers * - * @param string $string - * @param OutputInterface $output * @return IndexerInterface[] */ - protected function parseIndexerString($string, OutputInterface $output) + protected function getAllIndexers() { - $indexers = []; - if ($string === self::INPUT_KEY_ALL) { - /** @var Indexer[] $indexers */ - $indexers = $this->collectionFactory->create()->getItems(); - } elseif (!empty($string)) { - $codes = explode(',', $string); - foreach ($codes as $code) { - $indexer = $this->indexerFactory->create(); - try { - $indexer->load($code); - $indexers[] = $indexer; - } catch (\Exception $e) { - $output->writeln('Warning: Unknown indexer with code ' . trim($code)); - } - } - } - return $indexers; + /** @var Indexer[] $indexers */ + return $this->collectionFactory->create()->getItems(); } } diff --git a/app/code/Magento/Indexer/Console/Command/AbstractIndexerManageCommand.php b/app/code/Magento/Indexer/Console/Command/AbstractIndexerManageCommand.php new file mode 100644 index 0000000000000000000000000000000000000000..018f7ae1669bcaa11533705ec473dfe1cbd06bdc --- /dev/null +++ b/app/code/Magento/Indexer/Console/Command/AbstractIndexerManageCommand.php @@ -0,0 +1,61 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Indexer\Console\Command; + +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Input\InputArgument; + +/** + * An Abstract class for all Indexer related commands. + */ +abstract class AbstractIndexerManageCommand extends AbstractIndexerCommand +{ + /** + * Gets list of indexers + * + * @param InputInterface $input + * @param OutputInterface $output + * @return IndexerInterface[] + */ + protected function getIndexers(InputInterface $input, OutputInterface $output) + { + $inputArguments = $input->getArgument(self::INPUT_KEY_INDEXERS); + if (isset($inputArguments) && sizeof($inputArguments)>0) { + $indexers = []; + foreach ($inputArguments as $code) { + $indexer = $this->indexerFactory->create(); + try { + $indexer->load($code); + $indexers[] = $indexer; + } catch (\Exception $e) { + $output->writeln('Warning: Unknown indexer with code ' . trim($code)); + } + } + } else { + $indexers = $this->getAllIndexers(); + } + return $indexers; + } + + /** + * Get list of options and arguments for the command + * + * @return mixed + */ + public function getInputList() + { + return [ + new InputOption(self::INPUT_KEY_ALL, 'a', InputOption::VALUE_NONE, 'All Indexes'), + new InputArgument( + self::INPUT_KEY_INDEXERS, + InputArgument::OPTIONAL | InputArgument::IS_ARRAY, + 'List of Indexes' + ), + ]; + } +} diff --git a/app/code/Magento/Indexer/Console/Command/IndexerInfoCommand.php b/app/code/Magento/Indexer/Console/Command/IndexerInfoCommand.php index 9176d4901c0b501b50a17e963a4b8dadc2043a15..e0b724a2b1e82e098d15e6ad19ea8a45ca1a3421 100644 --- a/app/code/Magento/Indexer/Console/Command/IndexerInfoCommand.php +++ b/app/code/Magento/Indexer/Console/Command/IndexerInfoCommand.php @@ -7,7 +7,6 @@ namespace Magento\Indexer\Console\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Input\InputOption; /** * Command for displaying information related to indexers. @@ -27,19 +26,9 @@ class IndexerInfoCommand extends AbstractIndexerCommand */ protected function execute(InputInterface $input, OutputInterface $output) { - $indexers = $this->parseIndexerString(AbstractIndexerCommand::INPUT_KEY_ALL, $output); + $indexers = $this->getAllIndexers(); foreach ($indexers as $indexer) { $output->writeln(sprintf('%-40s %s', $indexer->getId(), $indexer->getTitle())); } } - - /** - * Get list of arguments for the command - * - * @return InputOption[] - */ - public function getInputList() - { - return []; - } } diff --git a/app/code/Magento/Indexer/Console/Command/IndexerReindexCommand.php b/app/code/Magento/Indexer/Console/Command/IndexerReindexCommand.php index 01f8206d4b5bb40105f0e90de8222ab2dc9d87de..b52d1da6154e1288a14c414d8b2765a2afcb653d 100644 --- a/app/code/Magento/Indexer/Console/Command/IndexerReindexCommand.php +++ b/app/code/Magento/Indexer/Console/Command/IndexerReindexCommand.php @@ -11,7 +11,7 @@ use Symfony\Component\Console\Output\OutputInterface; /** * Command for reindexing indexers. */ -class IndexerReindexCommand extends AbstractIndexerCommand +class IndexerReindexCommand extends AbstractIndexerManageCommand { /** * {@inheritdoc} diff --git a/app/code/Magento/Indexer/Console/Command/IndexerSetModeCommand.php b/app/code/Magento/Indexer/Console/Command/IndexerSetModeCommand.php index 9e82381d6154249bfd79d1368a17386c7060802b..e5901edc53d588da92892863b25d821298df3064 100644 --- a/app/code/Magento/Indexer/Console/Command/IndexerSetModeCommand.php +++ b/app/code/Magento/Indexer/Console/Command/IndexerSetModeCommand.php @@ -13,14 +13,15 @@ use Symfony\Component\Console\Input\InputArgument; /** * Command for setting index mode for indexers. */ -class IndexerSetModeCommand extends AbstractIndexerCommand +class IndexerSetModeCommand extends AbstractIndexerManageCommand { - /** + /**#@+ * Names of input arguments or options */ const INPUT_KEY_MODE = 'mode'; const INPUT_KEY_REALTIME = 'realtime'; const INPUT_KEY_SCHEDULE = 'schedule'; + /**#@- */ /** * {@inheritdoc} diff --git a/app/code/Magento/Indexer/Console/Command/IndexerShowModeCommand.php b/app/code/Magento/Indexer/Console/Command/IndexerShowModeCommand.php index a7ac55993cb2f28cd9cf7fd1bd80f7f34e1878f5..35c3886de1e72fff56b3ec7013a599cab4956282 100644 --- a/app/code/Magento/Indexer/Console/Command/IndexerShowModeCommand.php +++ b/app/code/Magento/Indexer/Console/Command/IndexerShowModeCommand.php @@ -11,7 +11,7 @@ use Symfony\Component\Console\Output\OutputInterface; /** * Command for displaying current index mode for indexers. */ -class IndexerShowModeCommand extends AbstractIndexerCommand +class IndexerShowModeCommand extends AbstractIndexerManageCommand { /** * {@inheritdoc} diff --git a/app/code/Magento/Indexer/Console/Command/IndexerStatusCommand.php b/app/code/Magento/Indexer/Console/Command/IndexerStatusCommand.php index 78ccc538711c1da105466f350c20b21b6c3467d3..6eda0f852453d7278c818c85f23628b817c31143 100644 --- a/app/code/Magento/Indexer/Console/Command/IndexerStatusCommand.php +++ b/app/code/Magento/Indexer/Console/Command/IndexerStatusCommand.php @@ -11,7 +11,7 @@ use Symfony\Component\Console\Output\OutputInterface; /** * Command for displaying status of indexers. */ -class IndexerStatusCommand extends AbstractIndexerCommand +class IndexerStatusCommand extends AbstractIndexerManageCommand { /** * {@inheritdoc} diff --git a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerInfoCommandTest.php b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerInfoCommandTest.php index 2abaadc57c026ac1ed7de1aa5e84663701c15396..2f6da06042dd634065895283c8250a8234684180 100644 --- a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerInfoCommandTest.php +++ b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerInfoCommandTest.php @@ -17,19 +17,13 @@ class IndexerInfoCommandTest extends IndexerCommandCommonTestSetup */ private $command; - public function testGetOptions() - { - $this->command = new IndexerInfoCommand($this->objectManagerFactory); - $this->assertSame([], $this->command->getInputList()); - } - public function testExecute() { $collection = $this->getMock('Magento\Indexer\Model\Indexer\Collection', [], [], '', false); - $indexer1 = $this->getMock('Magento\Indexer\Model\Indexer', [], [], '', false); - $indexer1->expects($this->once())->method('getId')->willReturn('id_indexer1'); - $indexer1->expects($this->once())->method('getTitle')->willReturn('Title_indexer1'); - $collection->expects($this->once())->method('getItems')->willReturn([$indexer1]); + $indexerOne = $this->getMock('Magento\Indexer\Model\Indexer', [], [], '', false); + $indexerOne->expects($this->once())->method('getId')->willReturn('id_indexerOne'); + $indexerOne->expects($this->once())->method('getTitle')->willReturn('Title_indexerOne'); + $collection->expects($this->once())->method('getItems')->willReturn([$indexerOne]); $this->collectionFactory->expects($this->once())->method('create')->will($this->returnValue($collection)); $this->indexerFactory->expects($this->never())->method('create'); @@ -37,6 +31,6 @@ class IndexerInfoCommandTest extends IndexerCommandCommonTestSetup $commandTester = new CommandTester($this->command); $commandTester->execute([]); $actualValue = $commandTester->getDisplay(); - $this->assertSame(sprintf('%-40s %s', 'id_indexer1', 'Title_indexer1') . PHP_EOL, $actualValue); + $this->assertSame(sprintf('%-40s %s', 'id_indexerOne', 'Title_indexerOne') . PHP_EOL, $actualValue); } } diff --git a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerReindexCommandTest.php b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerReindexCommandTest.php index 210c848dae9fcbee79d5b3f6852b3885d5b1b2a4..80eb1d9c2f84fc87da14881672f91c48be33e90e 100644 --- a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerReindexCommandTest.php +++ b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerReindexCommandTest.php @@ -29,9 +29,9 @@ class IndexerReindexCommandTest extends IndexerCommandCommonTestSetup public function testExecuteAll() { $collection = $this->getMock('Magento\Indexer\Model\Indexer\Collection', [], [], '', false); - $indexer1 = $this->getMock('Magento\Indexer\Model\Indexer', [], [], '', false); - $indexer1->expects($this->once())->method('getTitle')->willReturn('Title_indexer1'); - $collection->expects($this->once())->method('getItems')->willReturn([$indexer1]); + $indexerOne = $this->getMock('Magento\Indexer\Model\Indexer', [], [], '', false); + $indexerOne->expects($this->once())->method('getTitle')->willReturn('Title_indexerOne'); + $collection->expects($this->once())->method('getItems')->willReturn([$indexerOne]); $this->collectionFactory->expects($this->once())->method('create')->will($this->returnValue($collection)); $this->indexerFactory->expects($this->never())->method('create'); @@ -39,71 +39,71 @@ class IndexerReindexCommandTest extends IndexerCommandCommonTestSetup $commandTester = new CommandTester($this->command); $commandTester->execute([]); $actualValue = $commandTester->getDisplay(); - $this->assertStringStartsWith('Title_indexer1 index has been rebuilt successfully in', $actualValue); + $this->assertStringStartsWith('Title_indexerOne index has been rebuilt successfully in', $actualValue); } public function testExecuteWithIndex() { - $indexer1 = $this->getMock('Magento\Indexer\Model\Indexer', [], [], '', false); - $indexer1->expects($this->once())->method('reindexAll'); - $indexer1->expects($this->once())->method('getTitle')->willReturn('Title_indexer1'); - $indexer1->expects($this->once())->method('load')->with('id_indexer1')->willReturn($indexer1); + $indexerOne = $this->getMock('Magento\Indexer\Model\Indexer', [], [], '', false); + $indexerOne->expects($this->once())->method('reindexAll'); + $indexerOne->expects($this->once())->method('getTitle')->willReturn('Title_indexerOne'); + $indexerOne->expects($this->once())->method('load')->with('id_indexerOne')->willReturn($indexerOne); - $indexer2 = $this->getMock('Magento\Indexer\Model\Indexer', [], [], '', false); - $indexer2->expects($this->once())->method('reindexAll'); - $indexer2->expects($this->once())->method('getTitle')->willReturn('Title_indexer2'); - $indexer2->expects($this->once())->method('load')->with('id_indexer2')->willReturn($indexer2); + $indexerTwo = $this->getMock('Magento\Indexer\Model\Indexer', [], [], '', false); + $indexerTwo->expects($this->once())->method('reindexAll'); + $indexerTwo->expects($this->once())->method('getTitle')->willReturn('Title_indexerTwo'); + $indexerTwo->expects($this->once())->method('load')->with('id_indexerTwo')->willReturn($indexerTwo); $this->collectionFactory->expects($this->never())->method('create'); - $this->indexerFactory->expects($this->at(0))->method('create')->willReturn($indexer1); - $this->indexerFactory->expects($this->at(1))->method('create')->willReturn($indexer2); + $this->indexerFactory->expects($this->at(0))->method('create')->willReturn($indexerOne); + $this->indexerFactory->expects($this->at(1))->method('create')->willReturn($indexerTwo); $this->command = new IndexerReindexCommand($this->objectManagerFactory); $commandTester = new CommandTester($this->command); - $commandTester->execute(['index' => ['id_indexer1,id_indexer2']]); + $commandTester->execute(['index' => ['id_indexerOne', 'id_indexerTwo']]); $actualValue = $commandTester->getDisplay(); - $this->assertStringStartsWith('Title_indexer1 index has been rebuilt successfully in', $actualValue); + $this->assertStringStartsWith('Title_indexerOne index has been rebuilt successfully in', $actualValue); } public function testExecuteWithLocalizedException() { - $indexer1 = $this->getMock('Magento\Indexer\Model\Indexer', [], [], '', false); + $indexerOne = $this->getMock('Magento\Indexer\Model\Indexer', [], [], '', false); $localizedException = new \Magento\Framework\Exception\LocalizedException(__('Some Exception Message')); - $indexer1->expects($this->once())->method('reindexAll')->will($this->throwException($localizedException)); + $indexerOne->expects($this->once())->method('reindexAll')->will($this->throwException($localizedException)); $this->collectionFactory->expects($this->never())->method('create'); - $this->indexerFactory->expects($this->once())->method('create')->willReturn($indexer1); + $this->indexerFactory->expects($this->once())->method('create')->willReturn($indexerOne); $this->command = new IndexerReindexCommand($this->objectManagerFactory); $commandTester = new CommandTester($this->command); - $commandTester->execute(['index' => ['id_indexer1']]); + $commandTester->execute(['index' => ['id_indexerOne']]); $actualValue = $commandTester->getDisplay(); $this->assertStringStartsWith('Some Exception Message', $actualValue); } public function testExecuteWithException() { - $indexer1 = $this->getMock('Magento\Indexer\Model\Indexer', [], [], '', false); + $indexerOne = $this->getMock('Magento\Indexer\Model\Indexer', [], [], '', false); $exception = new \Exception(); - $indexer1->expects($this->once())->method('reindexAll')->will($this->throwException($exception)); - $indexer1->expects($this->once())->method('getTitle')->willReturn('Title_indexer1'); + $indexerOne->expects($this->once())->method('reindexAll')->will($this->throwException($exception)); + $indexerOne->expects($this->once())->method('getTitle')->willReturn('Title_indexerOne'); $this->collectionFactory->expects($this->never())->method('create'); - $this->indexerFactory->expects($this->once())->method('create')->willReturn($indexer1); + $this->indexerFactory->expects($this->once())->method('create')->willReturn($indexerOne); $this->command = new IndexerReindexCommand($this->objectManagerFactory); $commandTester = new CommandTester($this->command); - $commandTester->execute(['index' => ['id_indexer1']]); + $commandTester->execute(['index' => ['id_indexerOne']]); $actualValue = $commandTester->getDisplay(); - $this->assertStringStartsWith('Title_indexer1 indexer process unknown error:', $actualValue); + $this->assertStringStartsWith('Title_indexerOne indexer process unknown error:', $actualValue); } public function testExecuteWithExceptionInLoad() { - $indexer1 = $this->getMock('Magento\Indexer\Model\Indexer', [], [], '', false); + $indexerOne = $this->getMock('Magento\Indexer\Model\Indexer', [], [], '', false); $exception = new \Exception(); - $indexer1->expects($this->once())->method('load')->will($this->throwException($exception)); - $indexer1->expects($this->never())->method('getTitle'); + $indexerOne->expects($this->once())->method('load')->will($this->throwException($exception)); + $indexerOne->expects($this->never())->method('getTitle'); $this->collectionFactory->expects($this->never())->method('create'); - $this->indexerFactory->expects($this->once())->method('create')->willReturn($indexer1); + $this->indexerFactory->expects($this->once())->method('create')->willReturn($indexerOne); $this->command = new IndexerReindexCommand($this->objectManagerFactory); $commandTester = new CommandTester($this->command); - $commandTester->execute(['index' => ['id_indexer1']]); + $commandTester->execute(['index' => ['id_indexerOne']]); $actualValue = $commandTester->getDisplay(); $this->assertStringStartsWith('Warning: Unknown indexer with code', $actualValue); } diff --git a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerSetModeCommandTest.php b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerSetModeCommandTest.php index 2ccf19c0095d9975589156da645b5c715d8b1fdf..dcd345dc6ffe505a1f3049c48faff5f784d39fcb 100644 --- a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerSetModeCommandTest.php +++ b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerSetModeCommandTest.php @@ -55,14 +55,14 @@ class IndexerSetModeCommandTest extends IndexerCommandCommonTestSetup public function testExecuteAll() { $collection = $this->getMock('Magento\Indexer\Model\Indexer\Collection', [], [], '', false); - $indexer1 = $this->getMock('Magento\Indexer\Model\Indexer', [], [], '', false); + $indexerOne = $this->getMock('Magento\Indexer\Model\Indexer', [], [], '', false); - $indexer1->expects($this->at(0))->method('isScheduled')->willReturn(true); - $indexer1->expects($this->at(2))->method('isScheduled')->willReturn(false); + $indexerOne->expects($this->at(0))->method('isScheduled')->willReturn(true); + $indexerOne->expects($this->at(2))->method('isScheduled')->willReturn(false); - $indexer1->expects($this->once())->method('setScheduled')->with(false); - $indexer1->expects($this->once())->method('getTitle')->willReturn('Title_indexer1'); - $collection->expects($this->once())->method('getItems')->willReturn([$indexer1]); + $indexerOne->expects($this->once())->method('setScheduled')->with(false); + $indexerOne->expects($this->once())->method('getTitle')->willReturn('Title_indexerOne'); + $collection->expects($this->once())->method('getItems')->willReturn([$indexerOne]); $this->collectionFactory->expects($this->once())->method('create')->will($this->returnValue($collection)); $this->indexerFactory->expects($this->never())->method('create'); @@ -71,7 +71,7 @@ class IndexerSetModeCommandTest extends IndexerCommandCommonTestSetup $commandTester->execute(['mode' => 'realtime']); $actualValue = $commandTester->getDisplay(); $this->assertSame( - 'Index mode for Indexer Title_indexer1 was changed from '. '\'Update by Schedule\' to \'Update on Save\'' + 'Index mode for Indexer Title_indexerOne was changed from '. '\'Update by Schedule\' to \'Update on Save\'' . PHP_EOL, $actualValue ); @@ -87,19 +87,19 @@ class IndexerSetModeCommandTest extends IndexerCommandCommonTestSetup */ public function testExecuteWithIndex($isScheduled, $previous, $current, $mode, $expectedValue) { - $indexer1 = $this->getMock('Magento\Indexer\Model\Indexer', [], [], '', false); - $indexer1->expects($this->once())->method('getTitle')->willReturn('Title_indexer1'); - $indexer1->expects($this->once())->method('load')->with('id_indexer1')->willReturn($indexer1); - $indexer1->expects($this->once())->method('setScheduled')->with($isScheduled); - $indexer1->expects($this->at(1))->method('isScheduled')->willReturn($previous); - $indexer1->expects($this->at(3))->method('isScheduled')->willReturn($current); + $indexerOne = $this->getMock('Magento\Indexer\Model\Indexer', [], [], '', false); + $indexerOne->expects($this->once())->method('getTitle')->willReturn('Title_indexerOne'); + $indexerOne->expects($this->once())->method('load')->with('id_indexerOne')->willReturn($indexerOne); + $indexerOne->expects($this->once())->method('setScheduled')->with($isScheduled); + $indexerOne->expects($this->at(1))->method('isScheduled')->willReturn($previous); + $indexerOne->expects($this->at(3))->method('isScheduled')->willReturn($current); $this->collectionFactory->expects($this->never())->method('create'); - $this->indexerFactory->expects($this->once())->method('create')->willReturn($indexer1); + $this->indexerFactory->expects($this->once())->method('create')->willReturn($indexerOne); $this->command = new IndexerSetModeCommand($this->objectManagerFactory); $commandTester = new CommandTester($this->command); - $commandTester->execute(['mode' => $mode, 'index' => ['id_indexer1']]); + $commandTester->execute(['mode' => $mode, 'index' => ['id_indexerOne']]); $actualValue = $commandTester->getDisplay(); $this->assertSame($expectedValue, $actualValue); } @@ -115,7 +115,7 @@ class IndexerSetModeCommandTest extends IndexerCommandCommonTestSetup true, false, 'realtime', - 'Index mode for Indexer Title_indexer1 was changed from \'Update by Schedule\' to \'Update on Save\'' + 'Index mode for Indexer Title_indexerOne was changed from \'Update by Schedule\' to \'Update on Save\'' . PHP_EOL ], [ @@ -123,7 +123,7 @@ class IndexerSetModeCommandTest extends IndexerCommandCommonTestSetup false, false, 'realtime', - 'Index mode for Indexer Title_indexer1 has not been changed' + 'Index mode for Indexer Title_indexerOne has not been changed' . PHP_EOL ], [ @@ -131,7 +131,7 @@ class IndexerSetModeCommandTest extends IndexerCommandCommonTestSetup true, true, 'schedule', - 'Index mode for Indexer Title_indexer1 has not been changed' + 'Index mode for Indexer Title_indexerOne has not been changed' . PHP_EOL ], [ @@ -139,7 +139,7 @@ class IndexerSetModeCommandTest extends IndexerCommandCommonTestSetup false, true, 'schedule', - 'Index mode for Indexer Title_indexer1 was changed from \'Update on Save\' to \'Update by Schedule\'' + 'Index mode for Indexer Title_indexerOne was changed from \'Update on Save\' to \'Update by Schedule\'' . PHP_EOL ], ]; @@ -147,30 +147,30 @@ class IndexerSetModeCommandTest extends IndexerCommandCommonTestSetup public function testExecuteWithLocalizedException() { - $indexer1 = $this->getMock('Magento\Indexer\Model\Indexer', [], [], '', false); + $indexerOne = $this->getMock('Magento\Indexer\Model\Indexer', [], [], '', false); $localizedException = new \Magento\Framework\Exception\LocalizedException(__('Some Exception Message')); - $indexer1->expects($this->once())->method('setScheduled')->will($this->throwException($localizedException)); + $indexerOne->expects($this->once())->method('setScheduled')->will($this->throwException($localizedException)); $this->collectionFactory->expects($this->never())->method('create'); - $this->indexerFactory->expects($this->once())->method('create')->willReturn($indexer1); + $this->indexerFactory->expects($this->once())->method('create')->willReturn($indexerOne); $this->command = new IndexerSetModeCommand($this->objectManagerFactory); $commandTester = new CommandTester($this->command); - $commandTester->execute(['mode' => 'schedule', 'index' => ['id_indexer1']]); + $commandTester->execute(['mode' => 'schedule', 'index' => ['id_indexerOne']]); $actualValue = $commandTester->getDisplay(); $this->assertStringStartsWith('Some Exception Message', $actualValue); } public function testExecuteWithException() { - $indexer1 = $this->getMock('Magento\Indexer\Model\Indexer', [], [], '', false); + $indexerOne = $this->getMock('Magento\Indexer\Model\Indexer', [], [], '', false); $exception = new \Exception(); - $indexer1->expects($this->once())->method('setScheduled')->will($this->throwException($exception)); - $indexer1->expects($this->once())->method('getTitle')->willReturn('Title_indexer1'); + $indexerOne->expects($this->once())->method('setScheduled')->will($this->throwException($exception)); + $indexerOne->expects($this->once())->method('getTitle')->willReturn('Title_indexerOne'); $this->collectionFactory->expects($this->never())->method('create'); - $this->indexerFactory->expects($this->once())->method('create')->willReturn($indexer1); + $this->indexerFactory->expects($this->once())->method('create')->willReturn($indexerOne); $this->command = new IndexerSetModeCommand($this->objectManagerFactory); $commandTester = new CommandTester($this->command); - $commandTester->execute(['mode' => 'schedule', 'index' => ['id_indexer1']]); + $commandTester->execute(['mode' => 'schedule', 'index' => ['id_indexerOne']]); $actualValue = $commandTester->getDisplay(); - $this->assertStringStartsWith('Title_indexer1 indexer process unknown error:', $actualValue); + $this->assertStringStartsWith('Title_indexerOne indexer process unknown error:', $actualValue); } } diff --git a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerShowModeCommandTest.php b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerShowModeCommandTest.php index 1fe11acdb1886105d5d99d0c41d08874371be930..8c7a527ae4392a66f3e0b350099e2e73a5e472ef 100644 --- a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerShowModeCommandTest.php +++ b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerShowModeCommandTest.php @@ -13,7 +13,7 @@ class IndexerShowModeCommandTest extends IndexerCommandCommonTestSetup /** * Command being tested * - * @var IndexerInfoCommand + * @var IndexerShowModeCommand */ private $command; @@ -30,13 +30,13 @@ class IndexerShowModeCommandTest extends IndexerCommandCommonTestSetup { $collection = $this->getMock('Magento\Indexer\Model\Indexer\Collection', [], [], '', false); - $indexer1 = $this->getMock('Magento\Indexer\Model\Indexer', [], [], '', false); - $indexer1->expects($this->once())->method('getTitle')->willReturn('Title_indexer1'); - $indexer1->expects($this->once())->method('isScheduled')->willReturn(true); - $indexer2 = $this->getMock('Magento\Indexer\Model\Indexer', [], [], '', false); - $indexer2->expects($this->once())->method('getTitle')->willReturn('Title_indexer2'); - $indexer2->expects($this->once())->method('isScheduled')->willReturn(false); - $collection->expects($this->once())->method('getItems')->willReturn([$indexer1, $indexer2]); + $indexerOne = $this->getMock('Magento\Indexer\Model\Indexer', [], [], '', false); + $indexerOne->expects($this->once())->method('getTitle')->willReturn('Title_indexerOne'); + $indexerOne->expects($this->once())->method('isScheduled')->willReturn(true); + $indexerTwo = $this->getMock('Magento\Indexer\Model\Indexer', [], [], '', false); + $indexerTwo->expects($this->once())->method('getTitle')->willReturn('Title_indexerTwo'); + $indexerTwo->expects($this->once())->method('isScheduled')->willReturn(false); + $collection->expects($this->once())->method('getItems')->willReturn([$indexerOne, $indexerTwo]); $this->collectionFactory->expects($this->once())->method('create')->will($this->returnValue($collection)); $this->indexerFactory->expects($this->never())->method('create'); @@ -45,33 +45,33 @@ class IndexerShowModeCommandTest extends IndexerCommandCommonTestSetup $commandTester = new CommandTester($this->command); $commandTester->execute([]); $actualValue = $commandTester->getDisplay(); - $expectedValue = sprintf('%-50s ', 'Title_indexer1' . ':') . 'Update by Schedule' . PHP_EOL - . sprintf('%-50s ', 'Title_indexer2' . ':') . 'Update on Save'; + $expectedValue = sprintf('%-50s ', 'Title_indexerOne' . ':') . 'Update by Schedule' . PHP_EOL + . sprintf('%-50s ', 'Title_indexerTwo' . ':') . 'Update on Save'; $this->assertStringStartsWith($expectedValue, $actualValue); } public function testExecuteWithIndex() { - $indexer1 = $this->getMock('Magento\Indexer\Model\Indexer', [], [], '', false); - $indexer1->expects($this->once())->method('getTitle')->willReturn('Title_indexer1'); - $indexer1->expects($this->once())->method('isScheduled')->willReturn(true); - $indexer2 = $this->getMock('Magento\Indexer\Model\Indexer', [], [], '', false); - $indexer2->expects($this->once())->method('getTitle')->willReturn('Title_indexer2'); - $indexer2->expects($this->once())->method('isScheduled')->willReturn(false); - $indexer3 = $this->getMock('Magento\Indexer\Model\Indexer', [], [], '', false); - $indexer3->expects($this->never())->method('getTitle')->willReturn('Title_indexer3'); - $indexer3->expects($this->never())->method('isScheduled')->willReturn(false); + $indexerOne = $this->getMock('Magento\Indexer\Model\Indexer', [], [], '', false); + $indexerOne->expects($this->once())->method('getTitle')->willReturn('Title_indexerOne'); + $indexerOne->expects($this->once())->method('isScheduled')->willReturn(true); + $indexerTwo = $this->getMock('Magento\Indexer\Model\Indexer', [], [], '', false); + $indexerTwo->expects($this->once())->method('getTitle')->willReturn('Title_indexerTwo'); + $indexerTwo->expects($this->once())->method('isScheduled')->willReturn(false); + $indexerThree = $this->getMock('Magento\Indexer\Model\Indexer', [], [], '', false); + $indexerThree->expects($this->never())->method('getTitle')->willReturn('Title_indexer3'); + $indexerThree->expects($this->never())->method('isScheduled')->willReturn(false); $this->collectionFactory->expects($this->never())->method('create'); - $this->indexerFactory->expects($this->at(0))->method('create')->willReturn($indexer1); - $this->indexerFactory->expects($this->at(1))->method('create')->willReturn($indexer2); + $this->indexerFactory->expects($this->at(0))->method('create')->willReturn($indexerOne); + $this->indexerFactory->expects($this->at(1))->method('create')->willReturn($indexerTwo); $this->command = new IndexerShowModeCommand($this->objectManagerFactory); $commandTester = new CommandTester($this->command); - $commandTester->execute(['index' => ['id_indexer1,id_indexer2']]); + $commandTester->execute(['index' => ['id_indexerOne', 'id_indexerTwo']]); $actualValue = $commandTester->getDisplay(); - $expectedValue = sprintf('%-50s ', 'Title_indexer1' . ':') . 'Update by Schedule' . PHP_EOL - . sprintf('%-50s ', 'Title_indexer2' . ':') . 'Update on Save'; + $expectedValue = sprintf('%-50s ', 'Title_indexerOne' . ':') . 'Update by Schedule' . PHP_EOL + . sprintf('%-50s ', 'Title_indexerTwo' . ':') . 'Update on Save'; $this->assertStringStartsWith($expectedValue, $actualValue); } } diff --git a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusCommandTest.php b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusCommandTest.php index e9d0a09f2fba00da4981fbef14155e1ce2a8e476..b5fd291e330c07b5080b74e3764927d739d03bd3 100644 --- a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusCommandTest.php +++ b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusCommandTest.php @@ -20,30 +20,30 @@ class IndexerStatusCommandTest extends IndexerCommandCommonTestSetup public function testExecuteAll() { $collection = $this->getMock('Magento\Indexer\Model\Indexer\Collection', [], [], '', false); - $indexer1 = $this->getMock('Magento\Indexer\Model\Indexer', [], [], '', false); - $indexer1->expects($this->once())->method('getTitle')->willReturn('Title_indexer1'); - $indexer1 + $indexerOne = $this->getMock('Magento\Indexer\Model\Indexer', [], [], '', false); + $indexerOne->expects($this->once())->method('getTitle')->willReturn('Title_indexerOne'); + $indexerOne ->expects($this->once()) ->method('getStatus') ->willReturn(\Magento\Indexer\Model\Indexer\State::STATUS_VALID); - $indexer2 = $this->getMock('Magento\Indexer\Model\Indexer', [], [], '', false); - $indexer2->expects($this->once())->method('getTitle')->willReturn('Title_indexer2'); - $indexer2 + $indexerTwo = $this->getMock('Magento\Indexer\Model\Indexer', [], [], '', false); + $indexerTwo->expects($this->once())->method('getTitle')->willReturn('Title_indexerTwo'); + $indexerTwo ->expects($this->once()) ->method('getStatus') ->willReturn(\Magento\Indexer\Model\Indexer\State::STATUS_INVALID); - $indexer3 = $this->getMock('Magento\Indexer\Model\Indexer', [], [], '', false); - $indexer3->expects($this->once())->method('getTitle')->willReturn('Title_indexer3'); - $indexer3 + $indexerThree = $this->getMock('Magento\Indexer\Model\Indexer', [], [], '', false); + $indexerThree->expects($this->once())->method('getTitle')->willReturn('Title_indexerThree'); + $indexerThree ->expects($this->once()) ->method('getStatus') ->willReturn(\Magento\Indexer\Model\Indexer\State::STATUS_WORKING); - $indexer4 = $this->getMock('Magento\Indexer\Model\Indexer', [], [], '', false); - $indexer4->expects($this->once())->method('getTitle')->willReturn('Title_indexer4'); + $indexerFour = $this->getMock('Magento\Indexer\Model\Indexer', [], [], '', false); + $indexerFour->expects($this->once())->method('getTitle')->willReturn('Title_indexerFour'); $collection ->expects($this->once()) ->method('getItems') - ->willReturn([$indexer1, $indexer2, $indexer3, $indexer4]); + ->willReturn([$indexerOne, $indexerTwo, $indexerThree, $indexerFour]); $this->collectionFactory->expects($this->once())->method('create')->will($this->returnValue($collection)); $this->indexerFactory->expects($this->never())->method('create'); @@ -51,11 +51,10 @@ class IndexerStatusCommandTest extends IndexerCommandCommonTestSetup $commandTester = new CommandTester($this->command); $commandTester->execute([]); $actualValue = $commandTester->getDisplay(); - $expectedValue = sprintf('%-50s ', 'Title_indexer1' . ':') . 'Ready' . PHP_EOL - . sprintf('%-50s ', 'Title_indexer2' . ':') . 'Reindex required' . PHP_EOL - . sprintf('%-50s ', 'Title_indexer3' . ':') . 'Processing' . PHP_EOL - . sprintf('%-50s ', 'Title_indexer4' . ':') . 'unknown' . PHP_EOL; - + $expectedValue = sprintf('%-50s ', 'Title_indexerOne' . ':') . 'Ready' . PHP_EOL + . sprintf('%-50s ', 'Title_indexerTwo' . ':') . 'Reindex required' . PHP_EOL + . sprintf('%-50s ', 'Title_indexerThree' . ':') . 'Processing' . PHP_EOL + . sprintf('%-50s ', 'Title_indexerFour' . ':') . 'unknown' . PHP_EOL; $this->assertStringStartsWith($expectedValue, $actualValue); }