File tree Expand file tree Collapse file tree 2 files changed +20
-21
lines changed
Test/Unit/Console/Command Expand file tree Collapse file tree 2 files changed +20
-21
lines changed Original file line number Diff line number Diff line change @@ -46,14 +46,17 @@ protected function configure()
46
46
*/
47
47
protected function execute (InputInterface $ input , OutputInterface $ output )
48
48
{
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. ' ;
50
51
$ 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 ;
53
55
}
54
56
$ days = (int ) $ days ;
55
57
if ($ days <= 0 ) {
56
- throw new \InvalidArgumentException ($ errorMsg );
58
+ $ output ->writeln ('<error> ' . $ errorMsg . '</error> ' );
59
+ return ;
57
60
}
58
61
/** @var \Magento\Framework\App\Config\MutableScopeConfigInterface $mutableConfig */
59
62
$ mutableConfig = $ this ->objectManager ->create ('Magento\Framework\App\Config\MutableScopeConfigInterface ' );
Original file line number Diff line number Diff line change @@ -57,29 +57,25 @@ public function testExecute()
57
57
}
58
58
59
59
/**
60
- * @expectedException \InvalidArgumentException
61
- * @expectedExceptionMessage Invalid value for option "days"
60
+ *
61
+ * @param string $days
62
+ * @dataProvider daysDataProvider
62
63
*/
63
- public function testExecuteInvalidNegativeDays ()
64
+ public function testExecuteInvalidNegativeDays ($ days )
64
65
{
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
+ );
66
72
}
67
73
68
74
/**
69
- * @expectedException \InvalidArgumentException
70
- * @expectedExceptionMessage Invalid value for option "days"
75
+ * @return array
71
76
*/
72
- public function testExecuteInvalidFractionDays ()
77
+ public function daysDataProvider ()
73
78
{
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 ' ]];
84
80
}
85
81
}
You can’t perform that action at this time.
0 commit comments