Skip to content
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

[Console] fix and refactor exit code handling #8080

Merged
merged 1 commit into from
May 19, 2013

Conversation

Tobion
Copy link
Member

@Tobion Tobion commented May 17, 2013

Split of #8038

@@ -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);
Copy link
Member Author

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'));

Copy link
Member

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

Copy link
Member Author

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;
Copy link
Member Author

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.

fabpot added a commit that referenced this pull request May 19, 2013
This PR was merged into the 2.1 branch.

Discussion
----------

[Console] fix and refactor exit code handling

Split of #8038

Commits
-------

5c317b7 [Console] fix and refactor exit code handling
@fabpot fabpot merged commit 5c317b7 into symfony:2.1 May 19, 2013
@Tobion Tobion deleted the console-exit-code branch May 19, 2013 20:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants