Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

Tobion
Copy link
Contributor

@Tobion Tobion commented May 17, 2013

Split of #8038

Copy link
Contributor 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
Contributor 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.

Copy link
Contributor 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