sebastianbergmann/phpunit — Issue #415: Pass exception to tearDown()
Author: fbrnc
Created: 2011-11-20 19:28:42+00:00
State: open

A testcase's tearDown() method always gets called before the onNotSuccessfulTest() method in case an exception has been thrown somewhere.

If you need the current testenvironment in onNotSuccessfulTest() you must not "clean" it in tearDown(), but inside onNotSuccessfulTest(). Currently this is only possible using some workarounds.

Passing the exception to tearDown() would enable you to decide inside that method what to do.

Example Usecase: I use tearDown() to close the connection to a Selenium2 server (I'm not using PHPUnit_Selenium...). If an execption occured I'd like to take a screenshot in onNotSuccessfulTest(), so session needs to be closed inside onNotSuccessfulTest() and not in tearDown(). But if no exception occured session needs to be closed inside tearDown().

Another nice approach would be to have a template method that will be called at the very end (after tearDown and onNotSuccessfulTest).