Skip to content

Commit feb4f4a

Browse files
committed
Test help command error
1 parent 8ebf836 commit feb4f4a

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/Commands/Help.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ protected function showCommand(string $commandName) : void
3434
$command = $this->console->getCommand($commandName);
3535
if ($command === null) {
3636
CLI::error(
37-
$this->console->getLanguage()->render('cli', 'commandNotFound', [$commandName])
37+
$this->console->getLanguage()->render('cli', 'commandNotFound', [$commandName]),
38+
\defined('TESTING') ? null : 1
3839
);
40+
return;
3941
}
4042
CLI::write(CLI::style(
4143
$this->console->getLanguage()->render('cli', 'command') . ': ',

tests/Commands/HelpTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace Tests\CLI\Commands;
1111

1212
use Framework\CLI\Console;
13+
use Framework\CLI\Streams\Stderr;
1314
use Framework\CLI\Streams\Stdout;
1415
use PHPUnit\Framework\TestCase;
1516

@@ -28,4 +29,15 @@ public function testHelp() : void
2829
self::assertStringContainsString('Group', Stdout::getContents());
2930
self::assertStringContainsString('Options', Stdout::getContents());
3031
}
32+
33+
public function testError() : void
34+
{
35+
$console = new Console();
36+
Stderr::init();
37+
$console->exec('help foo');
38+
self::assertStringContainsString(
39+
'Command not found: "foo"',
40+
Stderr::getContents()
41+
);
42+
}
3143
}

0 commit comments

Comments
 (0)