Skip to content


Subversion checkout URL

You can clone with
Download ZIP


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

daniela-waranie opened this Issue · 10 comments

3 participants


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.


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


noticed in PHPUnit 3.4.14


a workaround is:
try {
//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.


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: I'll send a pull request.


Merged, thanks.


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


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


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

pear channel-discover
pear channel-discover
pear channel-discover

pear install phpunit/PHPUnit-beta

There's also if you don't want to use the PEAR installer.


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.