Skip to content

Commit c5e3ebd

Browse files
committed
MAGETWO-36068: Move dev/shell/log.php
- Changes based on code review feedback.
1 parent 198e825 commit c5e3ebd

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

app/code/Magento/Log/Console/Command/LogCleanCommand.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,17 @@ protected function configure()
4646
*/
4747
protected function execute(InputInterface $input, OutputInterface $output)
4848
{
49-
$errorMsg = 'Invalid value for option "' . self::INPUT_KEY_DAYS . '"';
49+
$errorMsg = 'Invalid value for option "' . self::INPUT_KEY_DAYS
50+
. '". It should be a whole number greater than 0.';
5051
$days = $input->getOption(self::INPUT_KEY_DAYS);
51-
if (!is_numeric($days) || (strpos($days,'.') !== false)) {
52-
throw new \InvalidArgumentException($errorMsg);
52+
if (!is_numeric($days) || (strpos($days, '.') !== false)) {
53+
$output->writeln('<error>' . $errorMsg . '</error>');
54+
return;
5355
}
5456
$days = (int) $days;
5557
if ($days <= 0) {
56-
throw new \InvalidArgumentException($errorMsg);
58+
$output->writeln('<error>' . $errorMsg . '</error>');
59+
return;
5760
}
5861
/** @var \Magento\Framework\App\Config\MutableScopeConfigInterface $mutableConfig */
5962
$mutableConfig = $this->objectManager->create('Magento\Framework\App\Config\MutableScopeConfigInterface');

app/code/Magento/Log/Test/Unit/Console/Command/LogCleanCommandTest.php

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,29 +57,25 @@ public function testExecute()
5757
}
5858

5959
/**
60-
* @expectedException \InvalidArgumentException
61-
* @expectedExceptionMessage Invalid value for option "days"
60+
*
61+
* @param string $days
62+
* @dataProvider daysDataProvider
6263
*/
63-
public function testExecuteInvalidNegativeDays()
64+
public function testExecuteInvalidNegativeDays($days)
6465
{
65-
$this->commandTester->execute(['--days' => '-1']);
66+
$this->commandTester->execute(['--days' => $days]);
67+
//Invalid value for option "days". It should be a whole number greater than 0.
68+
$this->assertEquals(
69+
'Invalid value for option "days". It should be a whole number greater than 0.' . PHP_EOL,
70+
$this->commandTester->getDisplay()
71+
);
6672
}
6773

6874
/**
69-
* @expectedException \InvalidArgumentException
70-
* @expectedExceptionMessage Invalid value for option "days"
75+
* @return array
7176
*/
72-
public function testExecuteInvalidFractionDays()
77+
public function daysDataProvider()
7378
{
74-
$this->commandTester->execute(['--days' => '5.5']);
75-
}
76-
77-
/**
78-
* @expectedException \InvalidArgumentException
79-
* @expectedExceptionMessage Invalid value for option "days"
80-
*/
81-
public function testExecuteInvalidTexyDays()
82-
{
83-
$this->commandTester->execute(['--days' => 'test']);
79+
return [['-1'], ['5.5'], ['test']];
8480
}
8581
}

0 commit comments

Comments
 (0)