-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Console] fix and refactor exit code handling #8080
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
Conversation
@@ -501,6 +501,21 @@ public function testRun() | |||
$this->assertSame('called'.PHP_EOL, $tester->getDisplay(), '->run() does not call interact() if -n is passed'); | |||
} | |||
|
|||
public function testRunReturnsIntegerExitCode() | |||
{ | |||
$exception = new \Exception('', 4); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exception->getCode() is allowed to return mixed.But unfortunately it seems impossible to test against something else than integer exception code because I cannot create such an exception.
This is not allowed: new \Exception('', 'foo');
and even mocking does not work. phpunit does not use the mocked method. Maybe phpunit bug or its impossible to mock exception completely.
$exception = $this->getMock('\Exception');
$exception->expects($this->once())
->method('getCode')
->will($this->returnValue('foo'));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Tobion getCode
is final so it cannot be mocked.
FYI, a case were exceptions are using string codes is PDOException
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah thanks for the info about final. I know about PdoException. The thing is I cannot create an exception that returns string code myself. Or do you know how? The only way seems to be that I make a wrong sql query for example so that I than get a PdoException with string code. But that seems like a bad approach.
@@ -115,7 +115,7 @@ public function run(InputInterface $input = null, OutputInterface $output = null | |||
} | |||
$statusCode = $e->getCode(); | |||
|
|||
$statusCode = is_numeric($statusCode) && $statusCode ? $statusCode : 1; | |||
$statusCode = $statusCode ? (is_numeric($statusCode) ? (int) $statusCode : 1) : 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fabpot The variable is named $exitCode
in newer branches. Just FYI when you merge upstream.
Split of #8038