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

$this->setExpectedException(): stacktrace is missing when no exception was not raised #5

Closed
daniela-waranie opened this issue Aug 13, 2010 · 10 comments

Comments

@daniela-waranie
Copy link

I expect to have the test methods name and test methods line number in stack trace, when a expected exception was not raised on the test method where i used the setExpectedException() method. Would be great if we can have the line number of the setExpectedException() call also in the stack trace.

The missing stack trace (and missing line numbers) makes my IDE (netbeans) unable to navigate to the failing test method by clicking on the failing test in the "Test Results" windows.

@daniela-waranie
Copy link
Author

stack trace is missing e.g. in cli in the non-verbose mode.

@daniela-waranie
Copy link
Author

noticed in PHPUnit 3.4.14

@daniela-waranie
Copy link
Author

a workaround is:
try {
$this->_object->setWeight(0.0);
//force a stack trace:
$this->fail('Webapp_Model_MyClass_WeightZeroNotAllowedException not raised.');
} catch (Webapp_Model_MyClass_WeightZeroNotAllowedException $exc) {
return; //everything is fine
}

But this is very bad "verbose code".
setExpectedException() is one line code - and better to read.

@whatthejeff
Copy link
Contributor

This happens because PHPUnit_Framework_TestCase::setExpectedException() doesn't actually raise the PHPUnit_Framework_AssertionFailedError exception. Instead, the exception is raised internally from PHPUnit_Framework_TestCase::runTest(). Consequently, when the stack trace is filtered with PHPUnit_Util_Filter::getFilteredStacktrace(), the entire trace is filtered out.

The solution for this is to make note of the stack trace at the moment PHPUnit_Framework_TestCase::setExpectedException() is called and use that stack trace instead.

I've created a topic branch that solves this issue here: http://github.com/whatthejeff/phpunit/tree/issue_5. I'll send a pull request.

@sebastianbergmann
Copy link
Owner

Merged, thanks.

@daniela-waranie
Copy link
Author

On what date (or week or month) do you plan to release 3.5.0?

@daniela-waranie
Copy link
Author

It is not listed here (*) that issue 5 is part of release 3.5.0, please update, or did i misunderstand you?

@whatthejeff
Copy link
Contributor

You can actually get 3.5.0RC2 (which contains this fix) with the PEAR installer. Try this:

pear channel-discover pear.phpunit.de
pear channel-discover pear.symfony-project.com
pear channel-discover components.ez.no

pear install phpunit/PHPUnit-beta

@whatthejeff
Copy link
Contributor

There's also http://github.com/knplabs/phpunit-easyinstall if you don't want to use the PEAR installer.

@daniela-waranie
Copy link
Author

Works, good job. Thanks.

This issue was closed.
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

No branches or pull requests

3 participants