Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Closed
daniela-waranie opened this Issue · 10 comments

3 participants

@daniela-waranie

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

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

@daniela-waranie

noticed in PHPUnit 3.4.14

@daniela-waranie

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
Collaborator

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

Merged, thanks.

@daniela-waranie

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

@daniela-waranie

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

@whatthejeff
Collaborator

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
Collaborator

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

@daniela-waranie

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
Something went wrong with that request. Please try again.