Skip to content

Commit

Permalink
test: improve stream checking
Browse files Browse the repository at this point in the history
  • Loading branch information
g105b committed Sep 18, 2023
1 parent 42ca4a0 commit 1565507
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Application {
protected HelpCommand $helpCommand;
protected VersionCommand $versionCommand;
private int $exitCode;
/** @var callable */
/** @var ?callable */
private $exitHandler;

public function __construct(
Expand Down
8 changes: 7 additions & 1 deletion test/phpunit/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public function testCommandRun() {
);
}

public function testExitCodeNotEnoughArtguments() {
public function testExitCodeNotEnoughArguments() {
$parameter = self::createMock(NamedParameter::class);
$argumentsList = self::createMock(ArgumentList::class);
$argumentsList->method("getCommandName")
Expand Down Expand Up @@ -223,11 +223,17 @@ public function getOptionalParameterList():array { return []; }
};
$actualErrorCode = null;
$sut = new Application("Test app", $argumentsList, $command1);
$sut->setStream(
$this->inPath,
$this->outPath,
$this->errPath
);
$sut->setExitHandler(function(int $errorCode) use(&$actualErrorCode) {
$actualErrorCode = $errorCode;
});
$sut->run();
self::assertSame(1, $actualErrorCode);
self::assertStreamContains("Error: Not enough arguments passed. Passed: 0 required: 1.", Stream::ERROR);
}

protected function assertStreamContains(
Expand Down

0 comments on commit 1565507

Please sign in to comment.