Skip to content

Commit 088483a

Browse files
committed
Test run console with invalid command
1 parent 6d9b18c commit 088483a

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

phpunit.xml.dist

+3
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,7 @@
1818
<directory suffix="Test.php">tests</directory>
1919
</testsuite>
2020
<logging/>
21+
<php>
22+
<const name="TESTING" value="true"/>
23+
</php>
2124
</phpunit>

src/Console.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,8 @@ public function run() : void
258258
CLI::error(CLI::style(
259259
$this->getLanguage()->render('cli', 'commandNotFound', [$this->command]),
260260
CLI::FG_BRIGHT_RED
261-
));
261+
), \defined('TESTING') ? null : 1);
262+
return;
262263
}
263264
$command->run();
264265
}

tests/ConsoleTest.php

+15
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace Tests\CLI;
1111

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

@@ -215,6 +216,20 @@ public function testRun() : void
215216
self::assertSame($this->getContentsOfCommandMock(), Stdout::getContents());
216217
}
217218

219+
public function testRunWithInvalidCommand() : void
220+
{
221+
$this->console->prepare([
222+
'file.php',
223+
'unknown',
224+
]);
225+
Stderr::init();
226+
$this->console->run();
227+
self::assertStringContainsString(
228+
'Command not found: "unknown"',
229+
Stderr::getContents()
230+
);
231+
}
232+
218233
protected function getContentsOfCommandMock() : string
219234
{
220235
return \print_r(['option' => 'foo', 'o' => 1], true) . \PHP_EOL

0 commit comments

Comments
 (0)