Deferred error handling #672

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
3 participants

Domini commented Sep 27, 2012

When you write a functional test on a method that acquires a resource, does something that leads to a trigger_error(), and then releases the resource, PHPUnit_Util_ErrorHandler will convert the error to exception and throw it right where it happened, so the resource won't be released. If you want to assert whether error was triggered, you use setExpectedException(). But in this case the resource won't be released and test won't be isolated enough.

I've implemented setExpectedExceptionDeferred() to continue execution in case of trigger_error().

Contributor

sun commented Aug 24, 2014

Very belated reply:

When … a functional test … acquires a resource, does something that leads to a trigger_error(), … the resource won't be released.

tearDown() is still invoked for each test (at least in 4.x; can't tell for 3.x, but it's recommended to update anyway).

Normally you should be able to clean up all state and resources in tearDown(), even in case the test threw an error/exception. Did you try that?

Contributor

whatthejeff commented Aug 24, 2014

Sorry for the very delayed response, @Domini. Thanks for your work on this, but I agree with @sun. The solution for this problem is to cleanup in tearDown().

Domini commented Aug 24, 2014

Cleanup in tearDown() in cases where deferred error handling was necessary is quite more complex.

Currently PHP supports try {} finally {} so I guess this should be used (i. e. code being tested should handle its side effects whatever happens without relying on 3rd parties), not tearDown() or anything.

Anyway thanks for the late reply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment