Skip to content

[Console] Fix Docblock for CommandTester::getExitCode #37241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Symfony/Component/Console/Tester/TesterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ trait TesterTrait
/**
* Gets the display returned by the last execution of the command or application.
*
* @throws \RuntimeException If it's called before the execute method
*
* @return string The display
*/
public function getDisplay(bool $normalize = false)
Expand Down Expand Up @@ -95,10 +97,16 @@ public function getOutput()
/**
* Gets the status code returned by the last execution of the command or application.
*
* @throws \RuntimeException If it's called before the execute method
*
* @return int The status code
*/
public function getStatusCode()
{
if (null === $this->statusCode) {
throw new \RuntimeException('Status code not initialized, did you execute the command before requesting the status code?');
}

return $this->statusCode;
}

Expand Down
20 changes: 20 additions & 0 deletions src/Symfony/Component/Console/Tests/Tester/CommandTesterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,31 @@ public function testGetDisplay()
$this->assertEquals('foo'.PHP_EOL, $this->tester->getDisplay(), '->getDisplay() returns the display of the last execution');
}

public function testGetDisplayWithoutCallingExecuteBefore()
{
$tester = new CommandTester(new Command());

$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('Output not initialized');

$tester->getDisplay();
}

public function testGetStatusCode()
{
$this->assertSame(0, $this->tester->getStatusCode(), '->getStatusCode() returns the status code');
}

public function testGetStatusCodeWithoutCallingExecuteBefore()
{
$tester = new CommandTester(new Command());

$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('Status code not initialized');

$tester->getStatusCode();
}

public function testCommandFromApplication()
{
$application = new Application();
Expand Down