diff --git a/app/code/Magento/Log/Console/Command/LogCleanCommand.php b/app/code/Magento/Log/Console/Command/LogCleanCommand.php index 8934199373fffc7f9ad19f6cbbd10baa0a4225b2..00827c20b96c856520aa5b859e32dc73317058c5 100644 --- a/app/code/Magento/Log/Console/Command/LogCleanCommand.php +++ b/app/code/Magento/Log/Console/Command/LogCleanCommand.php @@ -46,14 +46,17 @@ class LogCleanCommand extends AbstractLogCommand */ protected function execute(InputInterface $input, OutputInterface $output) { - $errorMsg = 'Invalid value for option "' . self::INPUT_KEY_DAYS . '"'; + $errorMsg = 'Invalid value for option "' . self::INPUT_KEY_DAYS + . '". It should be a whole number greater than 0.'; $days = $input->getOption(self::INPUT_KEY_DAYS); - if (!is_numeric($days) || (strpos($days,'.') !== false)) { - throw new \InvalidArgumentException($errorMsg); + if (!is_numeric($days) || (strpos($days, '.') !== false)) { + $output->writeln('<error>' . $errorMsg . '</error>'); + return; } $days = (int) $days; if ($days <= 0) { - throw new \InvalidArgumentException($errorMsg); + $output->writeln('<error>' . $errorMsg . '</error>'); + return; } /** @var \Magento\Framework\App\Config\MutableScopeConfigInterface $mutableConfig */ $mutableConfig = $this->objectManager->create('Magento\Framework\App\Config\MutableScopeConfigInterface'); diff --git a/app/code/Magento/Log/Test/Unit/Console/Command/LogCleanCommandTest.php b/app/code/Magento/Log/Test/Unit/Console/Command/LogCleanCommandTest.php index 2b742e8ceeba227aed5f26655bdf62f86969f07b..0db32a17c32950dec9a9ea4ab20f6ed4827c31cd 100644 --- a/app/code/Magento/Log/Test/Unit/Console/Command/LogCleanCommandTest.php +++ b/app/code/Magento/Log/Test/Unit/Console/Command/LogCleanCommandTest.php @@ -57,29 +57,25 @@ class LogCleanCommandTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Invalid value for option "days" + * + * @param string $days + * @dataProvider daysDataProvider */ - public function testExecuteInvalidNegativeDays() + public function testExecuteInvalidNegativeDays($days) { - $this->commandTester->execute(['--days' => '-1']); + $this->commandTester->execute(['--days' => $days]); + //Invalid value for option "days". It should be a whole number greater than 0. + $this->assertEquals( + 'Invalid value for option "days". It should be a whole number greater than 0.' . PHP_EOL, + $this->commandTester->getDisplay() + ); } /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Invalid value for option "days" + * @return array */ - public function testExecuteInvalidFractionDays() + public function daysDataProvider() { - $this->commandTester->execute(['--days' => '5.5']); - } - - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Invalid value for option "days" - */ - public function testExecuteInvalidTexyDays() - { - $this->commandTester->execute(['--days' => 'test']); + return [['-1'], ['5.5'], ['test']]; } }