From 38ba6efec7876d8731a6fb546fbe96b73e4298fc Mon Sep 17 00:00:00 2001 From: David Alger Date: Fri, 3 Jul 2015 14:50:41 -0500 Subject: [PATCH 1/9] Fixes bug in cache management console commands where --all is not applied by default - The commands cache:flush, cache:clear, cache:enable and cache:disable now properly default to use --all when no types explicitly given - Unit tests for cache management commands have been made simpler, resulting in less duplicate test code - Unit tests added to verify --all is applied by default --- .../Command/AbstractCacheManageCommand.php | 13 ++ .../Command/CacheDisableCommandTest.php | 107 ++++++---------- .../Command/CacheEnableCommandTest.php | 121 ++++++++---------- .../Console/Command/CacheFlushCommandTest.php | 26 +--- .../CacheManageCommandTestAbstract.php | 60 +++++++++ 5 files changed, 167 insertions(+), 160 deletions(-) create mode 100644 app/code/Magento/Backend/Test/Unit/Console/Command/CacheManageCommandTestAbstract.php diff --git a/app/code/Magento/Backend/Console/Command/AbstractCacheManageCommand.php b/app/code/Magento/Backend/Console/Command/AbstractCacheManageCommand.php index 0644e7d41de44..9df730079929d 100644 --- a/app/code/Magento/Backend/Console/Command/AbstractCacheManageCommand.php +++ b/app/code/Magento/Backend/Console/Command/AbstractCacheManageCommand.php @@ -9,6 +9,7 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; abstract class AbstractCacheManageCommand extends AbstractCacheCommand { @@ -41,6 +42,18 @@ protected function configure() parent::configure(); } + /** + * Initialize defaults dependent on argument input + * + * @param InputInterface $input + * @param OutputInterface $output + */ + protected function initialize(InputInterface $input, OutputInterface $output) + { + if ($input->getArgument(self::INPUT_KEY_TYPES) === []) { + $input->setOption(self::INPUT_KEY_ALL, true); + } + } /** * Get requested cache types diff --git a/app/code/Magento/Backend/Test/Unit/Console/Command/CacheDisableCommandTest.php b/app/code/Magento/Backend/Test/Unit/Console/Command/CacheDisableCommandTest.php index 82a477ad92457..c2c06ed86bbb0 100644 --- a/app/code/Magento/Backend/Test/Unit/Console/Command/CacheDisableCommandTest.php +++ b/app/code/Magento/Backend/Test/Unit/Console/Command/CacheDisableCommandTest.php @@ -9,89 +9,64 @@ use Magento\Backend\Console\Command\CacheDisableCommand; use Symfony\Component\Console\Tester\CommandTester; -class CacheDisableCommandTest extends \PHPUnit_Framework_TestCase +class CacheDisableManageCommandTest extends CacheManageCommandTestAbstract { /** - * @var \Magento\Framework\App\Cache\Manager|\PHPUnit_Framework_MockObject_MockObject + * @var AbstractCacheManageCommand */ - private $cacheManager; - - /** - * @var CacheDisableCommand - */ - private $command; + protected $command; public function setUp() { - $this->cacheManager = $this->getMock('Magento\Framework\App\Cache\Manager', [], [], '', false); + parent::setUp(); $this->command = new CacheDisableCommand($this->cacheManager); } - public function testExecute() - { - $this->cacheManager->expects($this->once())->method('getAvailableTypes')->willReturn(['A', 'B', 'C']); - $this->cacheManager - ->expects($this->once()) - ->method('setEnabled') - ->with(['A', 'B'], false) - ->willReturn(['A', 'B']); - $param = ['types' => ['A', 'B']]; - $commandTester = new CommandTester($this->command); - $commandTester->execute($param); - - $expect = 'Changed cache status:' . PHP_EOL; - foreach (['A', 'B'] as $cacheType) { - $expect .= sprintf('%30s: %d -> %d', $cacheType, true, false) . PHP_EOL; - } - - $this->assertEquals($expect, $commandTester->getDisplay()); - } - - public function testExecuteAll() + /** + * @param $param + * @param $enable + * @param $result + * @param $output + * @dataProvider testExecuteDataProvider + */ + public function testExecute($param, $enable, $result, $output) { $this->cacheManager->expects($this->once())->method('getAvailableTypes')->willReturn(['A', 'B', 'C']); - $this->cacheManager - ->expects($this->once()) - ->method('setEnabled') - ->with(['A', 'B', 'C'], false) - ->willReturn(['A', 'B', 'C']); - $param = ['--all' => true]; - $commandTester = new CommandTester($this->command); - $commandTester->execute($param); + $this->cacheManager->expects($this->once())->method('setEnabled')->with($enable, false)->willReturn($result); - $expect = 'Changed cache status:' . PHP_EOL; - foreach (['A', 'B', 'C'] as $cacheType) { - $expect .= sprintf('%30s: %d -> %d', $cacheType, true, false) . PHP_EOL; - } - $this->assertEquals($expect, $commandTester->getDisplay()); - } - - public function testExecuteNoChanges() - { - $this->cacheManager->expects($this->once())->method('getAvailableTypes')->willReturn(['A', 'B', 'C']); - $this->cacheManager - ->expects($this->once()) - ->method('setEnabled') - ->with(['A', 'B'], false) - ->willReturn([]); - $this->cacheManager->expects($this->never())->method('clean'); - $param = ['types' => ['A', 'B']]; $commandTester = new CommandTester($this->command); $commandTester->execute($param); - $expect = 'There is nothing to change in cache status' . PHP_EOL; - $this->assertEquals($expect, $commandTester->getDisplay()); + $this->assertEquals($output, $commandTester->getDisplay()); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage The following requested cache types are not supported: - */ - public function testExecuteInvalidCacheType() + public function testExecuteDataProvider () { - $this->cacheManager->expects($this->once())->method('getAvailableTypes')->willReturn(['A', 'B', 'C']); - $param = ['types' => ['A', 'D']]; - $commandTester = new CommandTester($this->command); - $commandTester->execute($param); + return [ + 'no parameters' => [ + [], + ['A', 'B', 'C'], + ['A', 'B', 'C'], + $this->getExpectedChangeOutput(['A', 'B', 'C'], false), + ], + 'explicit --all' => [ + ['--all' => true, 'types' => 'A'], + ['A', 'B', 'C'], + ['A', 'B', 'C'], + $this->getExpectedChangeOutput(['A', 'B', 'C'], false), + ], + 'specific types' => [ + ['types' => ['A', 'B']], + ['A', 'B'], + ['A', 'B'], + $this->getExpectedChangeOutput(['A', 'B'], false), + ], + 'no changes' => [ + ['types' => ['A', 'B']], + ['A', 'B'], + [], + $this->getExpectedChangeOutput([], false), + ], + ]; } } diff --git a/app/code/Magento/Backend/Test/Unit/Console/Command/CacheEnableCommandTest.php b/app/code/Magento/Backend/Test/Unit/Console/Command/CacheEnableCommandTest.php index f5b9ea8e8ec4f..f4927e2725246 100644 --- a/app/code/Magento/Backend/Test/Unit/Console/Command/CacheEnableCommandTest.php +++ b/app/code/Magento/Backend/Test/Unit/Console/Command/CacheEnableCommandTest.php @@ -9,94 +9,75 @@ use Magento\Backend\Console\Command\CacheEnableCommand; use Symfony\Component\Console\Tester\CommandTester; -class CacheEnableCommandTest extends \PHPUnit_Framework_TestCase +class CacheEnableManageCommandTest extends CacheManageCommandTestAbstract { - /** - * @var \Magento\Framework\App\Cache\Manager|\PHPUnit_Framework_MockObject_MockObject - */ - private $cacheManager; - - /** - * @var CacheEnableCommand - */ - private $command; - public function setUp() { - $this->cacheManager = $this->getMock('Magento\Framework\App\Cache\Manager', [], [], '', false); + parent::setUp(); $this->command = new CacheEnableCommand($this->cacheManager); } - public function testExecute() + /** + * @param $param + * @param $enable + * @param $result + * @param $output + * @dataProvider testExecuteDataProvider + */ + public function testExecute($param, $enable, $result, $output) { $this->cacheManager->expects($this->once())->method('getAvailableTypes')->willReturn(['A', 'B', 'C']); - $this->cacheManager - ->expects($this->once()) - ->method('setEnabled') - ->with(['A', 'B'], true) - ->willReturn(['A', 'B']); - $this->cacheManager->expects($this->once())->method('clean')->with(['A', 'B']); - $param = ['types' => ['A', 'B']]; - $commandTester = new CommandTester($this->command); - $commandTester->execute($param); - - $expect = 'Changed cache status:' . PHP_EOL; - foreach (['A', 'B'] as $cacheType) { - $expect .= sprintf('%30s: %d -> %d', $cacheType, false, true) . PHP_EOL; - } - $expect .= 'Cleaned cache types:' . PHP_EOL; - $expect .= 'A' . PHP_EOL . 'B' . PHP_EOL; - $this->assertEquals($expect, $commandTester->getDisplay()); - } + $this->cacheManager->expects($this->once())->method('setEnabled')->with($enable, true)->willReturn($result); + $this->cacheManager->expects($result == [] ? $this->never() : $this->once())->method('clean')->with($enable); - public function testExecuteAll() - { - $this->cacheManager->expects($this->once())->method('getAvailableTypes')->willReturn(['A', 'B', 'C']); - $this->cacheManager - ->expects($this->once()) - ->method('setEnabled') - ->with(['A', 'B', 'C'], true) - ->willReturn(['A', 'B', 'C']); - $this->cacheManager->expects($this->once())->method('clean')->with(['A', 'B', 'C']); - $param = ['--all' => true]; $commandTester = new CommandTester($this->command); $commandTester->execute($param); - $expect = 'Changed cache status:' . PHP_EOL; - foreach (['A', 'B', 'C'] as $cacheType) { - $expect .= sprintf('%30s: %d -> %d', $cacheType, false, true) . PHP_EOL; - } - $expect .= 'Cleaned cache types:' . PHP_EOL; - $expect .= 'A' . PHP_EOL . 'B' . PHP_EOL . 'C' . PHP_EOL; - $this->assertEquals($expect, $commandTester->getDisplay()); + $this->assertEquals($output, $commandTester->getDisplay()); } - public function testExecuteNoChanges() - { - $this->cacheManager->expects($this->once())->method('getAvailableTypes')->willReturn(['A', 'B', 'C']); - $this->cacheManager - ->expects($this->once()) - ->method('setEnabled') - ->with(['A', 'B'], true) - ->willReturn([]); - $this->cacheManager->expects($this->never())->method('clean'); - $param = ['types' => ['A', 'B']]; - $commandTester = new CommandTester($this->command); - $commandTester->execute($param); - - $expect = 'There is nothing to change in cache status' . PHP_EOL; - $this->assertEquals($expect, $commandTester->getDisplay()); + public function testExecuteDataProvider() { + return [ + 'no parameters' => [ + [], + ['A', 'B', 'C'], + ['A', 'B', 'C'], + $this->getExpectedEnableOutput(['A', 'B', 'C']), + ], + 'explicit --all' => [ + ['--all' => true, 'types' => 'A'], + ['A', 'B', 'C'], + ['A', 'B', 'C'], + $this->getExpectedEnableOutput(['A', 'B', 'C']), + ], + 'specific types' => [ + ['types' => ['A', 'B']], + ['A', 'B'], + ['A', 'B'], + $this->getExpectedEnableOutput(['A', 'B']), + ], + 'no changes' => [ + ['types' => ['A', 'B']], + ['A', 'B'], + [], + $this->getExpectedEnableOutput([]), + ], + ]; } /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage The following requested cache types are not supported: + * Formats expected output string of cache enable command + * + * @param array $enabled + * @return string */ - public function testExecuteInvalidCacheType() + public function getExpectedEnableOutput(array $enabled) { - $this->cacheManager->expects($this->once())->method('getAvailableTypes')->willReturn(['A', 'B', 'C']); - $param = ['types' => ['A', 'D']]; - $commandTester = new CommandTester($this->command); - $commandTester->execute($param); + $output = $this->getExpectedChangeOutput($enabled, true); + if ($enabled) { + $output .= 'Cleaned cache types:' . PHP_EOL; + $output .= implode(PHP_EOL, $enabled) . PHP_EOL; + } + return $output; } } diff --git a/app/code/Magento/Backend/Test/Unit/Console/Command/CacheFlushCommandTest.php b/app/code/Magento/Backend/Test/Unit/Console/Command/CacheFlushCommandTest.php index b443efd1a93e0..096b3410b1af7 100644 --- a/app/code/Magento/Backend/Test/Unit/Console/Command/CacheFlushCommandTest.php +++ b/app/code/Magento/Backend/Test/Unit/Console/Command/CacheFlushCommandTest.php @@ -9,21 +9,11 @@ use Magento\Backend\Console\Command\CacheFlushCommand; use Symfony\Component\Console\Tester\CommandTester; -class CacheFlushCommandTest extends \PHPUnit_Framework_TestCase +class CacheFlushManageCommandTest extends CacheManageCommandTestAbstract { - /** - * @var \Magento\Framework\App\Cache\Manager|\PHPUnit_Framework_MockObject_MockObject - */ - private $cacheManager; - - /** - * @var CacheFlushCommand - */ - private $command; - public function setUp() { - $this->cacheManager = $this->getMock('Magento\Framework\App\Cache\Manager', [], [], '', false); + parent::setUp(); $this->command = new CacheFlushCommand($this->cacheManager); } @@ -38,18 +28,6 @@ public function testExecute() $this->assertEquals($expect, $commandTester->getDisplay()); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage The following requested cache types are not supported: - */ - public function testExecuteInvalidCacheType() - { - $this->cacheManager->expects($this->once())->method('getAvailableTypes')->willReturn(['A', 'B', 'C']); - $param = ['types' => ['A', 'D']]; - $commandTester = new CommandTester($this->command); - $commandTester->execute($param); - } - public function testExecuteAllCacheType() { $this->cacheManager->expects($this->once())->method('getAvailableTypes')->willReturn(['A', 'B', 'C']); diff --git a/app/code/Magento/Backend/Test/Unit/Console/Command/CacheManageCommandTestAbstract.php b/app/code/Magento/Backend/Test/Unit/Console/Command/CacheManageCommandTestAbstract.php new file mode 100644 index 0000000000000..58af865d198cb --- /dev/null +++ b/app/code/Magento/Backend/Test/Unit/Console/Command/CacheManageCommandTestAbstract.php @@ -0,0 +1,60 @@ +cacheManager = $this->getMock('Magento\Framework\App\Cache\Manager', [], [], '', false); + } + + /** + * Formats expected output of cache status change + * + * @param array $changes + * @param bool $enabled + * @return string + */ + public function getExpectedChangeOutput(array $changes, $enabled) + { + if ($changes) { + $output = 'Changed cache status:' . PHP_EOL; + foreach ($changes as $type) { + $output .= sprintf('%30s: %d -> %d', $type, $enabled === false, $enabled === true) . PHP_EOL; + } + } else { + $output = 'There is nothing to change in cache status' . PHP_EOL; + } + return $output; + } + + /** + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage The following requested cache types are not supported: + */ + public function testExecuteInvalidCacheType() + { + $this->cacheManager->expects($this->once())->method('getAvailableTypes')->willReturn(['A', 'B', 'C']); + $param = ['types' => ['A', 'D']]; + $commandTester = new CommandTester($this->command); + $commandTester->execute($param); + } +} From 053479c330f97ffd7627b87bb866f5800324aa92 Mon Sep 17 00:00:00 2001 From: David Alger Date: Fri, 3 Jul 2015 15:19:53 -0500 Subject: [PATCH 2/9] Fixes bug in cache management console commands where --all is not applied by default - Unit tests for cache management commands have been made simpler, resulting in less duplicate test code - Unit tests added to verify --all is applied by default --- .../Console/Command/CacheCleanCommandTest.php | 72 ++++++++++--------- .../Command/CacheDisableCommandTest.php | 12 ++-- .../Command/CacheEnableCommandTest.php | 6 +- .../Console/Command/CacheFlushCommandTest.php | 56 +++++++++++---- 4 files changed, 93 insertions(+), 53 deletions(-) diff --git a/app/code/Magento/Backend/Test/Unit/Console/Command/CacheCleanCommandTest.php b/app/code/Magento/Backend/Test/Unit/Console/Command/CacheCleanCommandTest.php index 5177df7711e43..2defc9c285f08 100644 --- a/app/code/Magento/Backend/Test/Unit/Console/Command/CacheCleanCommandTest.php +++ b/app/code/Magento/Backend/Test/Unit/Console/Command/CacheCleanCommandTest.php @@ -9,55 +9,63 @@ use Magento\Backend\Console\Command\CacheCleanCommand; use Symfony\Component\Console\Tester\CommandTester; -class CacheCleanCommandTest extends \PHPUnit_Framework_TestCase +class CacheCleanCommandTest extends CacheManageCommandTestAbstract { - /** - * @var \Magento\Framework\App\Cache\Manager|\PHPUnit_Framework_MockObject_MockObject - */ - private $cacheManager; - - /** - * @var CacheCleanCommand - */ - private $command; - public function setUp() { - $this->cacheManager = $this->getMock('Magento\Framework\App\Cache\Manager', [], [], '', false); + parent::setUp(); $this->command = new CacheCleanCommand($this->cacheManager); } - public function testExecute() + /** + * @param $param + * @param $types + * @param $output + * @dataProvider testExecuteDataProvider + */ + public function testExecute($param, $types, $output) { $this->cacheManager->expects($this->once())->method('getAvailableTypes')->willReturn(['A', 'B', 'C']); - $this->cacheManager->expects($this->once())->method('clean')->with(['A', 'B']); - $param = ['types' => ['A', 'B']]; + $this->cacheManager->expects($this->once())->method('clean')->with($types); + $commandTester = new CommandTester($this->command); $commandTester->execute($param); - $expect = 'Cleaned cache types:' . PHP_EOL . 'A' . PHP_EOL . 'B' . PHP_EOL; - $this->assertEquals($expect, $commandTester->getDisplay()); + + $this->assertEquals($output, $commandTester->getDisplay()); } /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage The following requested cache types are not supported: + * @return array */ - public function testExecuteInvalidCacheType() + public function testExecuteDataProvider() { - $this->cacheManager->expects($this->once())->method('getAvailableTypes')->willReturn(['A', 'B', 'C']); - $param = ['types' => ['A', 'D']]; - $commandTester = new CommandTester($this->command); - $commandTester->execute($param); + return [ + 'no parameters' => [ + [], + ['A', 'B', 'C'], + $this->getExpectedOutput(['A', 'B', 'C']), + ], + 'explicit --all' => [ + ['--all' => true, 'types' => 'A'], + ['A', 'B', 'C'], + $this->getExpectedOutput(['A', 'B', 'C']), + ], + 'specific types' => [ + ['types' => ['A', 'B']], + ['A', 'B'], + $this->getExpectedOutput(['A', 'B']), + ], + ]; } - public function testExecuteAllCacheType() + /** + * Get expected output based on set of types operated on + * + * @param array $types + * @return string + */ + public function getExpectedOutput(array $types) { - $this->cacheManager->expects($this->once())->method('getAvailableTypes')->willReturn(['A', 'B', 'C']); - $this->cacheManager->expects($this->once())->method('clean')->with(['A', 'B', 'C']); - $param = ['--all' => true]; - $commandTester = new CommandTester($this->command); - $commandTester->execute($param); - $expect = 'Cleaned cache types:' . PHP_EOL . 'A' . PHP_EOL . 'B' . PHP_EOL . 'C' . PHP_EOL; - $this->assertEquals($expect, $commandTester->getDisplay()); + return 'Cleaned cache types:' . PHP_EOL . implode(PHP_EOL, $types) . PHP_EOL; } } diff --git a/app/code/Magento/Backend/Test/Unit/Console/Command/CacheDisableCommandTest.php b/app/code/Magento/Backend/Test/Unit/Console/Command/CacheDisableCommandTest.php index c2c06ed86bbb0..6fb03efcc2f30 100644 --- a/app/code/Magento/Backend/Test/Unit/Console/Command/CacheDisableCommandTest.php +++ b/app/code/Magento/Backend/Test/Unit/Console/Command/CacheDisableCommandTest.php @@ -9,13 +9,8 @@ use Magento\Backend\Console\Command\CacheDisableCommand; use Symfony\Component\Console\Tester\CommandTester; -class CacheDisableManageCommandTest extends CacheManageCommandTestAbstract +class CacheDisableCommandTest extends CacheManageCommandTestAbstract { - /** - * @var AbstractCacheManageCommand - */ - protected $command; - public function setUp() { parent::setUp(); @@ -40,7 +35,10 @@ public function testExecute($param, $enable, $result, $output) $this->assertEquals($output, $commandTester->getDisplay()); } - public function testExecuteDataProvider () + /** + * @return array + */ + public function testExecuteDataProvider() { return [ 'no parameters' => [ diff --git a/app/code/Magento/Backend/Test/Unit/Console/Command/CacheEnableCommandTest.php b/app/code/Magento/Backend/Test/Unit/Console/Command/CacheEnableCommandTest.php index f4927e2725246..dadfdefcb4281 100644 --- a/app/code/Magento/Backend/Test/Unit/Console/Command/CacheEnableCommandTest.php +++ b/app/code/Magento/Backend/Test/Unit/Console/Command/CacheEnableCommandTest.php @@ -36,7 +36,11 @@ public function testExecute($param, $enable, $result, $output) $this->assertEquals($output, $commandTester->getDisplay()); } - public function testExecuteDataProvider() { + /** + * @return array + */ + public function testExecuteDataProvider() + { return [ 'no parameters' => [ [], diff --git a/app/code/Magento/Backend/Test/Unit/Console/Command/CacheFlushCommandTest.php b/app/code/Magento/Backend/Test/Unit/Console/Command/CacheFlushCommandTest.php index 096b3410b1af7..789cca0542a5e 100644 --- a/app/code/Magento/Backend/Test/Unit/Console/Command/CacheFlushCommandTest.php +++ b/app/code/Magento/Backend/Test/Unit/Console/Command/CacheFlushCommandTest.php @@ -17,25 +17,55 @@ public function setUp() $this->command = new CacheFlushCommand($this->cacheManager); } - public function testExecute() + /** + * @param $param + * @param $types + * @param $output + * @dataProvider testExecuteDataProvider + */ + public function testExecute($param, $types, $output) { $this->cacheManager->expects($this->once())->method('getAvailableTypes')->willReturn(['A', 'B', 'C']); - $this->cacheManager->expects($this->once())->method('flush')->with(['A', 'B']); - $param = ['types' => ['A', 'B']]; + $this->cacheManager->expects($this->once())->method('flush')->with($types); + $commandTester = new CommandTester($this->command); $commandTester->execute($param); - $expect = 'Flushed cache types:' . PHP_EOL . 'A' . PHP_EOL . 'B' . PHP_EOL; - $this->assertEquals($expect, $commandTester->getDisplay()); + + $this->assertEquals($output, $commandTester->getDisplay()); } - public function testExecuteAllCacheType() + /** + * @return array + */ + public function testExecuteDataProvider() { - $this->cacheManager->expects($this->once())->method('getAvailableTypes')->willReturn(['A', 'B', 'C']); - $this->cacheManager->expects($this->once())->method('flush')->with(['A', 'B', 'C']); - $param = ['--all' => true]; - $commandTester = new CommandTester($this->command); - $commandTester->execute($param); - $expect = 'Flushed cache types:' . PHP_EOL . 'A' . PHP_EOL . 'B' . PHP_EOL . 'C' . PHP_EOL; - $this->assertEquals($expect, $commandTester->getDisplay()); + return [ + 'no parameters' => [ + [], + ['A', 'B', 'C'], + $this->getExpectedOutput(['A', 'B', 'C']), + ], + 'explicit --all' => [ + ['--all' => true, 'types' => 'A'], + ['A', 'B', 'C'], + $this->getExpectedOutput(['A', 'B', 'C']), + ], + 'specific types' => [ + ['types' => ['A', 'B']], + ['A', 'B'], + $this->getExpectedOutput(['A', 'B']), + ], + ]; + } + + /** + * Get expected output based on set of types operated on + * + * @param array $types + * @return string + */ + public function getExpectedOutput(array $types) + { + return 'Flushed cache types:' . PHP_EOL . implode(PHP_EOL, $types) . PHP_EOL; } } From 364966db9b296adcf076709e906273d707998b5a Mon Sep 17 00:00:00 2001 From: David Alger Date: Wed, 15 Jul 2015 09:51:15 -0500 Subject: [PATCH 3/9] Removed the --all option from the cache set and cache-type manage commands --- .../Command/AbstractCacheManageCommand.php | 26 +------------------ .../Command/AbstractCacheSetCommand.php | 6 +---- .../AbstractCacheTypeManageCommand.php | 6 +---- 3 files changed, 3 insertions(+), 35 deletions(-) diff --git a/app/code/Magento/Backend/Console/Command/AbstractCacheManageCommand.php b/app/code/Magento/Backend/Console/Command/AbstractCacheManageCommand.php index 9df730079929d..862e4b742062e 100644 --- a/app/code/Magento/Backend/Console/Command/AbstractCacheManageCommand.php +++ b/app/code/Magento/Backend/Console/Command/AbstractCacheManageCommand.php @@ -18,11 +18,6 @@ abstract class AbstractCacheManageCommand extends AbstractCacheCommand */ const INPUT_KEY_TYPES = 'types'; - /** - * Input key all - */ - const INPUT_KEY_ALL = 'all'; - /** * {@inheritdoc} */ @@ -33,28 +28,9 @@ protected function configure() InputArgument::IS_ARRAY, 'List of cache types, space separated. If omitted, all caches will be affected' ); - $this->addOption( - self::INPUT_KEY_ALL, - null, - InputOption::VALUE_NONE, - 'All cache types' - ); parent::configure(); } - /** - * Initialize defaults dependent on argument input - * - * @param InputInterface $input - * @param OutputInterface $output - */ - protected function initialize(InputInterface $input, OutputInterface $output) - { - if ($input->getArgument(self::INPUT_KEY_TYPES) === []) { - $input->setOption(self::INPUT_KEY_ALL, true); - } - } - /** * Get requested cache types * @@ -69,7 +45,7 @@ protected function getRequestedTypes(InputInterface $input) $requestedTypes = array_filter(array_map('trim', $requestedTypes), 'strlen'); } if (empty($requestedTypes)) { - return []; + return $this->cacheManager->getAvailableTypes(); } else { $availableTypes = $this->cacheManager->getAvailableTypes(); $unsupportedTypes = array_diff($requestedTypes, $availableTypes); diff --git a/app/code/Magento/Backend/Console/Command/AbstractCacheSetCommand.php b/app/code/Magento/Backend/Console/Command/AbstractCacheSetCommand.php index b1330c0de2d05..fdb770890548c 100644 --- a/app/code/Magento/Backend/Console/Command/AbstractCacheSetCommand.php +++ b/app/code/Magento/Backend/Console/Command/AbstractCacheSetCommand.php @@ -24,11 +24,7 @@ abstract protected function isEnable(); protected function execute(InputInterface $input, OutputInterface $output) { $isEnable = $this->isEnable(); - if ($input->getOption(self::INPUT_KEY_ALL)) { - $types = $this->cacheManager->getAvailableTypes(); - } else { - $types = $this->getRequestedTypes($input); - } + $types = $this->getRequestedTypes($input); $changedTypes = $this->cacheManager->setEnabled($types, $isEnable); if ($changedTypes) { $output->writeln('Changed cache status:'); diff --git a/app/code/Magento/Backend/Console/Command/AbstractCacheTypeManageCommand.php b/app/code/Magento/Backend/Console/Command/AbstractCacheTypeManageCommand.php index 79583c2f08a2a..5974798f74be4 100644 --- a/app/code/Magento/Backend/Console/Command/AbstractCacheTypeManageCommand.php +++ b/app/code/Magento/Backend/Console/Command/AbstractCacheTypeManageCommand.php @@ -35,11 +35,7 @@ abstract protected function getDisplayMessage(); */ protected function execute(InputInterface $input, OutputInterface $output) { - if ($input->getOption(self::INPUT_KEY_ALL)) { - $types = $this->cacheManager->getAvailableTypes(); - } else { - $types = $this->getRequestedTypes($input); - } + $types = $this->getRequestedTypes($input); $this->performAction($types); $output->writeln($this->getDisplayMessage()); $output->writeln(join(PHP_EOL, $types)); From 0acc395651fc6a0c241172fd3113d9933b161435 Mon Sep 17 00:00:00 2001 From: David Alger Date: Wed, 15 Jul 2015 10:25:29 -0500 Subject: [PATCH 4/9] Updated cache command tests --- .../Command/AbstractCacheManageCommand.php | 2 - .../Command/AbstractCacheCommandTest.php | 36 +++++++++++ .../AbstractCacheManageCommandTest.php | 43 +++++++++++++ .../Command/AbstractCacheSetCommandTest.php | 57 ++++++++++++++++++ .../Console/Command/CacheCleanCommandTest.php | 34 ++--------- .../Command/CacheDisableCommandTest.php | 41 +++---------- .../Command/CacheEnableCommandTest.php | 50 +++------------- .../Console/Command/CacheFlushCommandTest.php | 39 ++---------- .../CacheManageCommandTestAbstract.php | 60 ------------------- .../Command/CacheStatusCommandTest.php | 31 +++++----- 10 files changed, 177 insertions(+), 216 deletions(-) create mode 100644 app/code/Magento/Backend/Test/Unit/Console/Command/AbstractCacheCommandTest.php create mode 100644 app/code/Magento/Backend/Test/Unit/Console/Command/AbstractCacheManageCommandTest.php create mode 100644 app/code/Magento/Backend/Test/Unit/Console/Command/AbstractCacheSetCommandTest.php delete mode 100644 app/code/Magento/Backend/Test/Unit/Console/Command/CacheManageCommandTestAbstract.php diff --git a/app/code/Magento/Backend/Console/Command/AbstractCacheManageCommand.php b/app/code/Magento/Backend/Console/Command/AbstractCacheManageCommand.php index 862e4b742062e..1ef1c42e79401 100644 --- a/app/code/Magento/Backend/Console/Command/AbstractCacheManageCommand.php +++ b/app/code/Magento/Backend/Console/Command/AbstractCacheManageCommand.php @@ -8,8 +8,6 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Input\InputOption; -use Symfony\Component\Console\Output\OutputInterface; abstract class AbstractCacheManageCommand extends AbstractCacheCommand { diff --git a/app/code/Magento/Backend/Test/Unit/Console/Command/AbstractCacheCommandTest.php b/app/code/Magento/Backend/Test/Unit/Console/Command/AbstractCacheCommandTest.php new file mode 100644 index 0000000000000..0681a0b60f2a3 --- /dev/null +++ b/app/code/Magento/Backend/Test/Unit/Console/Command/AbstractCacheCommandTest.php @@ -0,0 +1,36 @@ +cacheManager = $this->getMock('Magento\Framework\App\Cache\Manager', [], [], '', false); + } + + /** + * Formats expected output for testExecute data providers + * + * @param array $types + * @return string + */ + abstract function getExpectedExecutionOutput(array $types); + +} diff --git a/app/code/Magento/Backend/Test/Unit/Console/Command/AbstractCacheManageCommandTest.php b/app/code/Magento/Backend/Test/Unit/Console/Command/AbstractCacheManageCommandTest.php new file mode 100644 index 0000000000000..53ed624db4768 --- /dev/null +++ b/app/code/Magento/Backend/Test/Unit/Console/Command/AbstractCacheManageCommandTest.php @@ -0,0 +1,43 @@ + [ + [], + ['A', 'B', 'C'], + $this->getExpectedExecutionOutput(['A', 'B', 'C']), + ], + 'specified types' => [ + ['types' => ['A', 'B']], + ['A', 'B'], + $this->getExpectedExecutionOutput(['A', 'B']), + ], + ]; + } + + /** + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage The following requested cache types are not supported: + */ + public function testExecuteInvalidCacheType() + { + $this->cacheManager->expects($this->once())->method('getAvailableTypes')->willReturn(['A', 'B', 'C']); + $param = ['types' => ['A', 'D']]; + $commandTester = new CommandTester($this->command); + $commandTester->execute($param); + } +} diff --git a/app/code/Magento/Backend/Test/Unit/Console/Command/AbstractCacheSetCommandTest.php b/app/code/Magento/Backend/Test/Unit/Console/Command/AbstractCacheSetCommandTest.php new file mode 100644 index 0000000000000..7a3349f5b7316 --- /dev/null +++ b/app/code/Magento/Backend/Test/Unit/Console/Command/AbstractCacheSetCommandTest.php @@ -0,0 +1,57 @@ + [ + [], + ['A', 'B', 'C'], + ['A', 'B', 'C'], + $this->getExpectedExecutionOutput(['A', 'B', 'C']), + ], + 'specified types' => [ + ['types' => ['A', 'B']], + ['A', 'B'], + ['A', 'B'], + $this->getExpectedExecutionOutput(['A', 'B']), + ], + 'no changes' => [ + ['types' => ['A', 'B']], + ['A', 'B'], + [], + $this->getExpectedExecutionOutput([]), + ], + ]; + } + + /** + * Formats expected output of cache status change + * + * @param array $changes + * @param bool $enabled + * @return string + */ + public function getExpectedChangeOutput(array $changes, $enabled) + { + if ($changes) { + $output = 'Changed cache status:' . PHP_EOL; + foreach ($changes as $type) { + $output .= sprintf('%30s: %d -> %d', $type, $enabled === false, $enabled === true) . PHP_EOL; + } + } else { + $output = 'There is nothing to change in cache status' . PHP_EOL; + } + return $output; + } +} diff --git a/app/code/Magento/Backend/Test/Unit/Console/Command/CacheCleanCommandTest.php b/app/code/Magento/Backend/Test/Unit/Console/Command/CacheCleanCommandTest.php index 2defc9c285f08..a51fa92c1addf 100644 --- a/app/code/Magento/Backend/Test/Unit/Console/Command/CacheCleanCommandTest.php +++ b/app/code/Magento/Backend/Test/Unit/Console/Command/CacheCleanCommandTest.php @@ -9,7 +9,7 @@ use Magento\Backend\Console\Command\CacheCleanCommand; use Symfony\Component\Console\Tester\CommandTester; -class CacheCleanCommandTest extends CacheManageCommandTestAbstract +class CacheCleanCommandTest extends AbstractCacheManageCommandTest { public function setUp() { @@ -18,9 +18,9 @@ public function setUp() } /** - * @param $param - * @param $types - * @param $output + * @param array $param + * @param array $types + * @param string $output * @dataProvider testExecuteDataProvider */ public function testExecute($param, $types, $output) @@ -34,37 +34,13 @@ public function testExecute($param, $types, $output) $this->assertEquals($output, $commandTester->getDisplay()); } - /** - * @return array - */ - public function testExecuteDataProvider() - { - return [ - 'no parameters' => [ - [], - ['A', 'B', 'C'], - $this->getExpectedOutput(['A', 'B', 'C']), - ], - 'explicit --all' => [ - ['--all' => true, 'types' => 'A'], - ['A', 'B', 'C'], - $this->getExpectedOutput(['A', 'B', 'C']), - ], - 'specific types' => [ - ['types' => ['A', 'B']], - ['A', 'B'], - $this->getExpectedOutput(['A', 'B']), - ], - ]; - } - /** * Get expected output based on set of types operated on * * @param array $types * @return string */ - public function getExpectedOutput(array $types) + public function getExpectedExecutionOutput(array $types) { return 'Cleaned cache types:' . PHP_EOL . implode(PHP_EOL, $types) . PHP_EOL; } diff --git a/app/code/Magento/Backend/Test/Unit/Console/Command/CacheDisableCommandTest.php b/app/code/Magento/Backend/Test/Unit/Console/Command/CacheDisableCommandTest.php index 6fb03efcc2f30..1eb4cffd23fd6 100644 --- a/app/code/Magento/Backend/Test/Unit/Console/Command/CacheDisableCommandTest.php +++ b/app/code/Magento/Backend/Test/Unit/Console/Command/CacheDisableCommandTest.php @@ -9,7 +9,7 @@ use Magento\Backend\Console\Command\CacheDisableCommand; use Symfony\Component\Console\Tester\CommandTester; -class CacheDisableCommandTest extends CacheManageCommandTestAbstract +class CacheDisableCommandTest extends AbstractCacheSetCommandTest { public function setUp() { @@ -18,10 +18,10 @@ public function setUp() } /** - * @param $param - * @param $enable - * @param $result - * @param $output + * @param array $param + * @param array $enable + * @param array $result + * @param string $output * @dataProvider testExecuteDataProvider */ public function testExecute($param, $enable, $result, $output) @@ -36,35 +36,10 @@ public function testExecute($param, $enable, $result, $output) } /** - * @return array + * {@inheritdoc} */ - public function testExecuteDataProvider() + public function getExpectedExecutionOutput(array $changes) { - return [ - 'no parameters' => [ - [], - ['A', 'B', 'C'], - ['A', 'B', 'C'], - $this->getExpectedChangeOutput(['A', 'B', 'C'], false), - ], - 'explicit --all' => [ - ['--all' => true, 'types' => 'A'], - ['A', 'B', 'C'], - ['A', 'B', 'C'], - $this->getExpectedChangeOutput(['A', 'B', 'C'], false), - ], - 'specific types' => [ - ['types' => ['A', 'B']], - ['A', 'B'], - ['A', 'B'], - $this->getExpectedChangeOutput(['A', 'B'], false), - ], - 'no changes' => [ - ['types' => ['A', 'B']], - ['A', 'B'], - [], - $this->getExpectedChangeOutput([], false), - ], - ]; + return $this->getExpectedChangeOutput($changes, false); } } diff --git a/app/code/Magento/Backend/Test/Unit/Console/Command/CacheEnableCommandTest.php b/app/code/Magento/Backend/Test/Unit/Console/Command/CacheEnableCommandTest.php index dadfdefcb4281..6925d9517edaa 100644 --- a/app/code/Magento/Backend/Test/Unit/Console/Command/CacheEnableCommandTest.php +++ b/app/code/Magento/Backend/Test/Unit/Console/Command/CacheEnableCommandTest.php @@ -9,7 +9,7 @@ use Magento\Backend\Console\Command\CacheEnableCommand; use Symfony\Component\Console\Tester\CommandTester; -class CacheEnableManageCommandTest extends CacheManageCommandTestAbstract +class CacheEnableManageCommandTest extends AbstractCacheSetCommandTest { public function setUp() { @@ -18,10 +18,10 @@ public function setUp() } /** - * @param $param - * @param $enable - * @param $result - * @param $output + * @param array $param + * @param array $enable + * @param array $result + * @param string $output * @dataProvider testExecuteDataProvider */ public function testExecute($param, $enable, $result, $output) @@ -37,45 +37,9 @@ public function testExecute($param, $enable, $result, $output) } /** - * @return array + * {@inheritdoc} */ - public function testExecuteDataProvider() - { - return [ - 'no parameters' => [ - [], - ['A', 'B', 'C'], - ['A', 'B', 'C'], - $this->getExpectedEnableOutput(['A', 'B', 'C']), - ], - 'explicit --all' => [ - ['--all' => true, 'types' => 'A'], - ['A', 'B', 'C'], - ['A', 'B', 'C'], - $this->getExpectedEnableOutput(['A', 'B', 'C']), - ], - 'specific types' => [ - ['types' => ['A', 'B']], - ['A', 'B'], - ['A', 'B'], - $this->getExpectedEnableOutput(['A', 'B']), - ], - 'no changes' => [ - ['types' => ['A', 'B']], - ['A', 'B'], - [], - $this->getExpectedEnableOutput([]), - ], - ]; - } - - /** - * Formats expected output string of cache enable command - * - * @param array $enabled - * @return string - */ - public function getExpectedEnableOutput(array $enabled) + public function getExpectedExecutionOutput(array $enabled) { $output = $this->getExpectedChangeOutput($enabled, true); if ($enabled) { diff --git a/app/code/Magento/Backend/Test/Unit/Console/Command/CacheFlushCommandTest.php b/app/code/Magento/Backend/Test/Unit/Console/Command/CacheFlushCommandTest.php index 789cca0542a5e..46868e70adb55 100644 --- a/app/code/Magento/Backend/Test/Unit/Console/Command/CacheFlushCommandTest.php +++ b/app/code/Magento/Backend/Test/Unit/Console/Command/CacheFlushCommandTest.php @@ -9,7 +9,7 @@ use Magento\Backend\Console\Command\CacheFlushCommand; use Symfony\Component\Console\Tester\CommandTester; -class CacheFlushManageCommandTest extends CacheManageCommandTestAbstract +class CacheFlushManageCommandTest extends AbstractCacheManageCommandTest { public function setUp() { @@ -18,9 +18,9 @@ public function setUp() } /** - * @param $param - * @param $types - * @param $output + * @param array $param + * @param array $types + * @param string $output * @dataProvider testExecuteDataProvider */ public function testExecute($param, $types, $output) @@ -35,36 +35,9 @@ public function testExecute($param, $types, $output) } /** - * @return array - */ - public function testExecuteDataProvider() - { - return [ - 'no parameters' => [ - [], - ['A', 'B', 'C'], - $this->getExpectedOutput(['A', 'B', 'C']), - ], - 'explicit --all' => [ - ['--all' => true, 'types' => 'A'], - ['A', 'B', 'C'], - $this->getExpectedOutput(['A', 'B', 'C']), - ], - 'specific types' => [ - ['types' => ['A', 'B']], - ['A', 'B'], - $this->getExpectedOutput(['A', 'B']), - ], - ]; - } - - /** - * Get expected output based on set of types operated on - * - * @param array $types - * @return string + * {@inheritdoc} */ - public function getExpectedOutput(array $types) + public function getExpectedExecutionOutput(array $types) { return 'Flushed cache types:' . PHP_EOL . implode(PHP_EOL, $types) . PHP_EOL; } diff --git a/app/code/Magento/Backend/Test/Unit/Console/Command/CacheManageCommandTestAbstract.php b/app/code/Magento/Backend/Test/Unit/Console/Command/CacheManageCommandTestAbstract.php deleted file mode 100644 index 58af865d198cb..0000000000000 --- a/app/code/Magento/Backend/Test/Unit/Console/Command/CacheManageCommandTestAbstract.php +++ /dev/null @@ -1,60 +0,0 @@ -cacheManager = $this->getMock('Magento\Framework\App\Cache\Manager', [], [], '', false); - } - - /** - * Formats expected output of cache status change - * - * @param array $changes - * @param bool $enabled - * @return string - */ - public function getExpectedChangeOutput(array $changes, $enabled) - { - if ($changes) { - $output = 'Changed cache status:' . PHP_EOL; - foreach ($changes as $type) { - $output .= sprintf('%30s: %d -> %d', $type, $enabled === false, $enabled === true) . PHP_EOL; - } - } else { - $output = 'There is nothing to change in cache status' . PHP_EOL; - } - return $output; - } - - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage The following requested cache types are not supported: - */ - public function testExecuteInvalidCacheType() - { - $this->cacheManager->expects($this->once())->method('getAvailableTypes')->willReturn(['A', 'B', 'C']); - $param = ['types' => ['A', 'D']]; - $commandTester = new CommandTester($this->command); - $commandTester->execute($param); - } -} diff --git a/app/code/Magento/Backend/Test/Unit/Console/Command/CacheStatusCommandTest.php b/app/code/Magento/Backend/Test/Unit/Console/Command/CacheStatusCommandTest.php index 158c2a7783c90..4c792a4548dd1 100644 --- a/app/code/Magento/Backend/Test/Unit/Console/Command/CacheStatusCommandTest.php +++ b/app/code/Magento/Backend/Test/Unit/Console/Command/CacheStatusCommandTest.php @@ -9,21 +9,11 @@ use Magento\Backend\Console\Command\CacheStatusCommand; use Symfony\Component\Console\Tester\CommandTester; -class CacheStatusCommandTest extends \PHPUnit_Framework_TestCase +class CacheStatusCommandTest extends AbstractCacheCommandTest { - /** - * @var \Magento\Framework\App\Cache\Manager|\PHPUnit_Framework_MockObject_MockObject - */ - private $cacheManager; - - /** - * @var CacheStatusCommand - */ - private $command; - public function setUp() { - $this->cacheManager = $this->getMock('Magento\Framework\App\Cache\Manager', [], [], '', false); + parent::setUp(); $this->command = new CacheStatusCommand($this->cacheManager); } @@ -33,10 +23,19 @@ public function testExecute() $this->cacheManager->expects($this->once())->method('getStatus')->willReturn($cacheTypes); $commandTester = new CommandTester($this->command); $commandTester->execute([]); - $expect = 'Current status:' . PHP_EOL; - foreach ($cacheTypes as $cacheType => $status) { - $expect .= sprintf('%30s: %d', $cacheType, $status) . PHP_EOL; + + $this->assertEquals($this->getExpectedExecutionOutput($cacheTypes), $commandTester->getDisplay()); + } + + /** + * {@inheritdoc} + */ + public function getExpectedExecutionOutput(array $types) + { + $output = 'Current status:' . PHP_EOL; + foreach ($types as $type => $status) { + $output .= sprintf('%30s: %d', $type, $status) . PHP_EOL; } - $this->assertEquals($expect, $commandTester->getDisplay()); + return $output; } } From e503d021922020c67705f91dffa170e6dba8e5d6 Mon Sep 17 00:00:00 2001 From: David Alger Date: Wed, 15 Jul 2015 10:37:35 -0500 Subject: [PATCH 5/9] Corrected abstract indexer test class name and doc blocks --- ...TestSetup.php => AbstractIndexerCommandCommonTest.php} | 8 ++++---- .../Test/Unit/Console/Command/IndexerInfoCommandTest.php | 2 +- .../Unit/Console/Command/IndexerReindexCommandTest.php | 2 +- .../Unit/Console/Command/IndexerSetModeCommandTest.php | 2 +- .../Unit/Console/Command/IndexerShowModeCommandTest.php | 2 +- .../Unit/Console/Command/IndexerStatusCommandTest.php | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) rename app/code/Magento/Indexer/Test/Unit/Console/Command/{IndexerCommandCommonTestSetup.php => AbstractIndexerCommandCommonTest.php} (85%) diff --git a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerCommandCommonTestSetup.php b/app/code/Magento/Indexer/Test/Unit/Console/Command/AbstractIndexerCommandCommonTest.php similarity index 85% rename from app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerCommandCommonTestSetup.php rename to app/code/Magento/Indexer/Test/Unit/Console/Command/AbstractIndexerCommandCommonTest.php index 77fdccf9bc594..d999c1f0c884b 100644 --- a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerCommandCommonTestSetup.php +++ b/app/code/Magento/Indexer/Test/Unit/Console/Command/AbstractIndexerCommandCommonTest.php @@ -7,20 +7,20 @@ use Magento\Framework\App\ObjectManagerFactory; -class IndexerCommandCommonTestSetup extends \PHPUnit_Framework_TestCase +abstract class AbstractIndexerCommandCommonTest extends \PHPUnit_Framework_TestCase { /** - * @var \PHPUnit_Framework_MockObject_MockObject|IndexerFactory + * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Indexer\Model\IndexerFactory */ protected $indexerFactory; /** - * @var \PHPUnit_Framework_MockObject_MockObject|CollectionFactory + * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Indexer\Model\IndexerFactory */ protected $collectionFactory; /** - * @var \PHPUnit_Framework_MockObject_MockObject|ObjectManagerFactory + * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\App\ObjectManagerFactory */ protected $objectManagerFactory; 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 2f6da06042dd6..ba01ab6e6e32a 100644 --- a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerInfoCommandTest.php +++ b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerInfoCommandTest.php @@ -8,7 +8,7 @@ use Magento\Indexer\Console\Command\IndexerInfoCommand; use Symfony\Component\Console\Tester\CommandTester; -class IndexerInfoCommandTest extends IndexerCommandCommonTestSetup +class IndexerInfoCommandTest extends AbstractIndexerCommandCommonTest { /** * Command being tested 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 80eb1d9c2f84f..ebb1612acf5e7 100644 --- a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerReindexCommandTest.php +++ b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerReindexCommandTest.php @@ -8,7 +8,7 @@ use Magento\Indexer\Console\Command\IndexerReindexCommand; use Symfony\Component\Console\Tester\CommandTester; -class IndexerReindexCommandTest extends IndexerCommandCommonTestSetup +class IndexerReindexCommandTest extends AbstractIndexerCommandCommonTest { /** * Command being tested 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 dcd345dc6ffe5..2e7c795792f87 100644 --- a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerSetModeCommandTest.php +++ b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerSetModeCommandTest.php @@ -11,7 +11,7 @@ /** * Command for updating installed application after the code base has changed */ -class IndexerSetModeCommandTest extends IndexerCommandCommonTestSetup +class IndexerSetModeCommandTest extends AbstractIndexerCommandCommonTest { /** * Command being tested 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 8c7a527ae4392..d122771561620 100644 --- a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerShowModeCommandTest.php +++ b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerShowModeCommandTest.php @@ -8,7 +8,7 @@ use Magento\Indexer\Console\Command\IndexerShowModeCommand; use Symfony\Component\Console\Tester\CommandTester; -class IndexerShowModeCommandTest extends IndexerCommandCommonTestSetup +class IndexerShowModeCommandTest extends AbstractIndexerCommandCommonTest { /** * Command being tested 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 b5fd291e330c0..066bb07c88876 100644 --- a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusCommandTest.php +++ b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusCommandTest.php @@ -8,7 +8,7 @@ use Magento\Indexer\Console\Command\IndexerStatusCommand; use Symfony\Component\Console\Tester\CommandTester; -class IndexerStatusCommandTest extends IndexerCommandCommonTestSetup +class IndexerStatusCommandTest extends AbstractIndexerCommandCommonTest { /** * Command being tested From d4d942dae11a89bf2d053c9620905560156e9eb1 Mon Sep 17 00:00:00 2001 From: David Alger Date: Wed, 15 Jul 2015 10:38:02 -0500 Subject: [PATCH 6/9] Fixed incorrect use of string vs admin area constant --- .../Indexer/Console/Command/AbstractIndexerCommand.php | 2 +- .../Console/Command/AbstractIndexerCommandCommonTest.php | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Indexer/Console/Command/AbstractIndexerCommand.php b/app/code/Magento/Indexer/Console/Command/AbstractIndexerCommand.php index 8296069d60f50..48c98ab23ae7d 100644 --- a/app/code/Magento/Indexer/Console/Command/AbstractIndexerCommand.php +++ b/app/code/Magento/Indexer/Console/Command/AbstractIndexerCommand.php @@ -53,7 +53,7 @@ public function __construct(ObjectManagerFactory $objectManagerFactory) /** @var \Magento\Framework\App\State $appState */ $appState = $objectManager->get('Magento\Framework\App\State'); - $appState->setAreaCode('adminmhtml'); //TODO: temporary fix. + $appState->setAreaCode(\Magento\Framework\App\Area::AREA_ADMIN); $this->collectionFactory = $objectManager->create('Magento\Indexer\Model\Indexer\CollectionFactory'); $this->indexerFactory = $objectManager->create('Magento\Indexer\Model\IndexerFactory'); parent::__construct(); diff --git a/app/code/Magento/Indexer/Test/Unit/Console/Command/AbstractIndexerCommandCommonTest.php b/app/code/Magento/Indexer/Test/Unit/Console/Command/AbstractIndexerCommandCommonTest.php index d999c1f0c884b..54933b83cc2b2 100644 --- a/app/code/Magento/Indexer/Test/Unit/Console/Command/AbstractIndexerCommandCommonTest.php +++ b/app/code/Magento/Indexer/Test/Unit/Console/Command/AbstractIndexerCommandCommonTest.php @@ -36,7 +36,10 @@ protected function setUp() //TODO: temporary fix unit $stateMock = $this->getMock('Magento\Framework\App\State', [], [], '', false); - $stateMock->expects($this->once())->method('setAreaCode')->with('adminmhtml')->willReturnSelf(); + $stateMock->expects($this->once()) + ->method('setAreaCode') + ->with(\Magento\Framework\App\Area::AREA_ADMIN) + ->willReturnSelf(); $this->objectManager->expects($this->once()) ->method('get') From c4e2aa632e5c21004e12cc9635a2c595dd88fabf Mon Sep 17 00:00:00 2001 From: David Alger Date: Wed, 15 Jul 2015 11:07:52 -0500 Subject: [PATCH 7/9] Removed the --all argument from indexer console commands --- .../Indexer/Console/Command/AbstractIndexerCommand.php | 5 +---- .../Console/Command/AbstractIndexerManageCommand.php | 3 +-- .../Indexer/Console/Command/IndexerReindexCommand.php | 9 +++++---- .../Indexer/Console/Command/IndexerSetModeCommand.php | 9 +++++---- .../Indexer/Console/Command/IndexerShowModeCommand.php | 1 + .../Indexer/Console/Command/IndexerStatusCommand.php | 1 + .../Console/Command/AbstractIndexerCommandCommonTest.php | 3 --- .../Unit/Console/Command/IndexerReindexCommandTest.php | 5 ++--- .../Unit/Console/Command/IndexerSetModeCommandTest.php | 5 ++--- .../Unit/Console/Command/IndexerShowModeCommandTest.php | 5 ++--- 10 files changed, 20 insertions(+), 26 deletions(-) diff --git a/app/code/Magento/Indexer/Console/Command/AbstractIndexerCommand.php b/app/code/Magento/Indexer/Console/Command/AbstractIndexerCommand.php index 48c98ab23ae7d..514222867751e 100644 --- a/app/code/Magento/Indexer/Console/Command/AbstractIndexerCommand.php +++ b/app/code/Magento/Indexer/Console/Command/AbstractIndexerCommand.php @@ -18,12 +18,10 @@ */ 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 @@ -66,7 +64,6 @@ public function __construct(ObjectManagerFactory $objectManagerFactory) */ protected function getAllIndexers() { - /** @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 index 0105728d25404..233667a64a0ed 100644 --- a/app/code/Magento/Indexer/Console/Command/AbstractIndexerManageCommand.php +++ b/app/code/Magento/Indexer/Console/Command/AbstractIndexerManageCommand.php @@ -51,11 +51,10 @@ protected function getIndexers(InputInterface $input, OutputInterface $output) 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' + 'List of index types, space separated. If omitted, all indexes will be affected' ), ]; } diff --git a/app/code/Magento/Indexer/Console/Command/IndexerReindexCommand.php b/app/code/Magento/Indexer/Console/Command/IndexerReindexCommand.php index b52d1da6154e1..63b63c1ce4b7f 100644 --- a/app/code/Magento/Indexer/Console/Command/IndexerReindexCommand.php +++ b/app/code/Magento/Indexer/Console/Command/IndexerReindexCommand.php @@ -5,6 +5,7 @@ */ namespace Magento\Indexer\Console\Command; +use Magento\Framework\Exception\LocalizedException; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -19,9 +20,9 @@ class IndexerReindexCommand extends AbstractIndexerManageCommand protected function configure() { $this->setName('indexer:reindex') - ->setDescription( - 'Reindexes Data' - )->setDefinition($this->getInputList()); + ->setDescription('Reindexes Data') + ->setDefinition($this->getInputList()); + parent::configure(); } @@ -39,7 +40,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $output->writeln( $indexer->getTitle() . ' index has been rebuilt successfully in ' . gmdate('H:i:s', $resultTime) ); - } catch (\Magento\Framework\Exception\LocalizedException $e) { + } catch (LocalizedException $e) { $output->writeln($e->getMessage()); } catch (\Exception $e) { $output->writeln($indexer->getTitle() . ' indexer process unknown error:'); diff --git a/app/code/Magento/Indexer/Console/Command/IndexerSetModeCommand.php b/app/code/Magento/Indexer/Console/Command/IndexerSetModeCommand.php index e5901edc53d58..a77153f314e6b 100644 --- a/app/code/Magento/Indexer/Console/Command/IndexerSetModeCommand.php +++ b/app/code/Magento/Indexer/Console/Command/IndexerSetModeCommand.php @@ -5,6 +5,7 @@ */ namespace Magento\Indexer\Console\Command; +use Magento\Framework\Exception\LocalizedException; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Input\InputOption; @@ -29,9 +30,9 @@ class IndexerSetModeCommand extends AbstractIndexerManageCommand protected function configure() { $this->setName('indexer:set-mode') - ->setDescription( - 'Sets index mode type' - )->setDefinition($this->getInputList()); + ->setDescription('Sets index mode type') + ->setDefinition($this->getInputList()); + parent::configure(); } @@ -60,7 +61,7 @@ protected function execute(InputInterface $input, OutputInterface $output) } else { $output->writeln('Index mode for Indexer ' . $indexer->getTitle() . ' has not been changed'); } - } catch (\Magento\Framework\Exception\LocalizedException $e) { + } catch (LocalizedException $e) { $output->writeln($e->getMessage() . PHP_EOL); } catch (\Exception $e) { $output->writeln($indexer->getTitle() . " indexer process unknown error:" . PHP_EOL); diff --git a/app/code/Magento/Indexer/Console/Command/IndexerShowModeCommand.php b/app/code/Magento/Indexer/Console/Command/IndexerShowModeCommand.php index 35c3886de1e72..e053cbd9bb1d5 100644 --- a/app/code/Magento/Indexer/Console/Command/IndexerShowModeCommand.php +++ b/app/code/Magento/Indexer/Console/Command/IndexerShowModeCommand.php @@ -21,6 +21,7 @@ protected function configure() $this->setName('indexer:show-mode') ->setDescription('Shows Index Mode') ->setDefinition($this->getInputList()); + parent::configure(); } diff --git a/app/code/Magento/Indexer/Console/Command/IndexerStatusCommand.php b/app/code/Magento/Indexer/Console/Command/IndexerStatusCommand.php index 6eda0f852453d..98977854aac1c 100644 --- a/app/code/Magento/Indexer/Console/Command/IndexerStatusCommand.php +++ b/app/code/Magento/Indexer/Console/Command/IndexerStatusCommand.php @@ -21,6 +21,7 @@ protected function configure() $this->setName('indexer:status') ->setDescription('Shows status of Indexer') ->setDefinition($this->getInputList()); + parent::configure(); } diff --git a/app/code/Magento/Indexer/Test/Unit/Console/Command/AbstractIndexerCommandCommonTest.php b/app/code/Magento/Indexer/Test/Unit/Console/Command/AbstractIndexerCommandCommonTest.php index 54933b83cc2b2..8633db1f30f25 100644 --- a/app/code/Magento/Indexer/Test/Unit/Console/Command/AbstractIndexerCommandCommonTest.php +++ b/app/code/Magento/Indexer/Test/Unit/Console/Command/AbstractIndexerCommandCommonTest.php @@ -5,8 +5,6 @@ */ namespace Magento\Indexer\Test\Unit\Console\Command; -use Magento\Framework\App\ObjectManagerFactory; - abstract class AbstractIndexerCommandCommonTest extends \PHPUnit_Framework_TestCase { /** @@ -34,7 +32,6 @@ protected function setUp() $this->objectManagerFactory = $this->getMock('Magento\Framework\App\ObjectManagerFactory', [], [], '', false); $this->objectManager = $this->getMockForAbstractClass('Magento\Framework\ObjectManagerInterface'); - //TODO: temporary fix unit $stateMock = $this->getMock('Magento\Framework\App\State', [], [], '', false); $stateMock->expects($this->once()) ->method('setAreaCode') 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 ebb1612acf5e7..2333588e1bfc5 100644 --- a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerReindexCommandTest.php +++ b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerReindexCommandTest.php @@ -21,9 +21,8 @@ public function testGetOptions() { $this->command = new IndexerReindexCommand($this->objectManagerFactory); $optionsList = $this->command->getInputList(); - $this->assertSame(2, sizeof($optionsList)); - $this->assertSame('all', $optionsList[0]->getName()); - $this->assertSame('index', $optionsList[1]->getName()); + $this->assertSame(1, sizeof($optionsList)); + $this->assertSame('index', $optionsList[0]->getName()); } public function testExecuteAll() 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 2e7c795792f87..e06be22d36035 100644 --- a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerSetModeCommandTest.php +++ b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerSetModeCommandTest.php @@ -24,10 +24,9 @@ public function testGetOptions() { $this->command = new IndexerSetModeCommand($this->objectManagerFactory); $optionsList = $this->command->getInputList(); - $this->assertSame(3, sizeof($optionsList)); + $this->assertSame(2, sizeof($optionsList)); $this->assertSame('mode', $optionsList[0]->getName()); - $this->assertSame('all', $optionsList[1]->getName()); - $this->assertSame('index', $optionsList[2]->getName()); + $this->assertSame('index', $optionsList[1]->getName()); } /** 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 d122771561620..439aa99413135 100644 --- a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerShowModeCommandTest.php +++ b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerShowModeCommandTest.php @@ -21,9 +21,8 @@ public function testGetOptions() { $this->command = new IndexerShowModeCommand($this->objectManagerFactory); $optionsList = $this->command->getInputList(); - $this->assertSame(2, sizeof($optionsList)); - $this->assertSame('all', $optionsList[0]->getName()); - $this->assertSame('index', $optionsList[1]->getName()); + $this->assertSame(1, sizeof($optionsList)); + $this->assertSame('index', $optionsList[0]->getName()); } public function testExecuteAll() From a8a129d68e5b0bf9356a83d13327dceb0e579a3e Mon Sep 17 00:00:00 2001 From: David Alger Date: Wed, 15 Jul 2015 11:17:37 -0500 Subject: [PATCH 8/9] Updated indexer command to output valid index types when invalid type given --- .../Command/AbstractIndexerManageCommand.php | 28 +++++++++++++++---- .../Command/IndexerReindexCommandTest.php | 12 ++++++-- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/app/code/Magento/Indexer/Console/Command/AbstractIndexerManageCommand.php b/app/code/Magento/Indexer/Console/Command/AbstractIndexerManageCommand.php index 233667a64a0ed..9270049c1eb2d 100644 --- a/app/code/Magento/Indexer/Console/Command/AbstractIndexerManageCommand.php +++ b/app/code/Magento/Indexer/Console/Command/AbstractIndexerManageCommand.php @@ -25,20 +25,36 @@ abstract class AbstractIndexerManageCommand extends AbstractIndexerCommand */ protected function getIndexers(InputInterface $input, OutputInterface $output) { - $inputArguments = $input->getArgument(self::INPUT_KEY_INDEXERS); - if (isset($inputArguments) && sizeof($inputArguments)>0) { + $requestedTypes = []; + if ($input->getArgument(self::INPUT_KEY_INDEXERS)) { + $requestedTypes = $input->getArgument(self::INPUT_KEY_INDEXERS); + $requestedTypes = array_filter(array_map('trim', $requestedTypes), 'strlen'); + } + if (empty($requestedTypes)) { + return $this->getAllIndexers(); + } else { $indexers = []; - foreach ($inputArguments as $code) { + $unsupportedTypes = []; + foreach ($requestedTypes as $code) { $indexer = $this->indexerFactory->create(); try { $indexer->load($code); $indexers[] = $indexer; } catch (\Exception $e) { - $output->writeln('Warning: Unknown indexer with code ' . trim($code)); + $unsupportedTypes[] = $code; } } - } else { - $indexers = $this->getAllIndexers(); + if ($unsupportedTypes) { + $availableTypes = []; + $indexers = $this->getAllIndexers(); + foreach ($indexers as $indexer) { + $availableTypes[] = $indexer->getId(); + } + throw new \InvalidArgumentException( + "The following requested index types are not supported: '" . join("', '", $unsupportedTypes) + . "'." . PHP_EOL . 'Supported types: ' . join(", ", $availableTypes) + ); + } } return $indexers; } 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 2333588e1bfc5..20f1ecd3692ff 100644 --- a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerReindexCommandTest.php +++ b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerReindexCommandTest.php @@ -92,18 +92,24 @@ public function testExecuteWithException() $this->assertStringStartsWith('Title_indexerOne indexer process unknown error:', $actualValue); } + /** + * @expectedException \InvalidArgumentException + * @expectedExceptionMessageRegExp The following requested cache types are not supported:.* + */ public function testExecuteWithExceptionInLoad() { + $collection = $this->getMock('Magento\Indexer\Model\Indexer\Collection', [], [], '', false); $indexerOne = $this->getMock('Magento\Indexer\Model\Indexer', [], [], '', false); + $indexerOne->expects($this->once())->method('getId')->willReturn('id_indexer1'); + $collection->expects($this->once())->method('getItems')->willReturn([$indexerOne]); + $exception = new \Exception(); $indexerOne->expects($this->once())->method('load')->will($this->throwException($exception)); $indexerOne->expects($this->never())->method('getTitle'); - $this->collectionFactory->expects($this->never())->method('create'); + $this->collectionFactory->expects($this->once())->method('create')->will($this->returnValue($collection)); $this->indexerFactory->expects($this->once())->method('create')->willReturn($indexerOne); $this->command = new IndexerReindexCommand($this->objectManagerFactory); $commandTester = new CommandTester($this->command); $commandTester->execute(['index' => ['id_indexerOne']]); - $actualValue = $commandTester->getDisplay(); - $this->assertStringStartsWith('Warning: Unknown indexer with code', $actualValue); } } From 3b6b5462d76d552d1631415da4a078394dcb218d Mon Sep 17 00:00:00 2001 From: David Alger Date: Wed, 15 Jul 2015 12:22:36 -0500 Subject: [PATCH 9/9] Updated integration test application install process to conform to new cache:disable usage --- .../integration/framework/Magento/TestFramework/Application.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/tests/integration/framework/Magento/TestFramework/Application.php b/dev/tests/integration/framework/Magento/TestFramework/Application.php index e5d71b3055b8f..3aa2826ead126 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/Application.php +++ b/dev/tests/integration/framework/Magento/TestFramework/Application.php @@ -460,7 +460,7 @@ public function install() // enable only specified list of caches $initParamsQuery = $this->getInitParamsQuery(); - $this->_shell->execute('php -f %s cache:disable --all --bootstrap=%s', [BP . '/bin/magento', $initParamsQuery]); + $this->_shell->execute('php -f %s cache:disable --bootstrap=%s', [BP . '/bin/magento', $initParamsQuery]); $this->_shell->execute( 'php -f %s cache:enable %s %s %s %s --bootstrap=%s', [