Skip to content

Exception handling fix #88

Closed
wants to merge 1 commit into from

7 participants

@Seldaek
Seldaek commented Dec 13, 2010

See the commit description, this is a really annoying side effect which has led to bad code making it through the tests, and then failing in real conditions.

@Seldaek Seldaek setExpectedException should not catch exceptions coming from PHPUnit'…
…s error handler

Too often tests are believed to work because they catch an Exception, while they are in fact just catching a PHP warning/notice/error that has been converted to an Exception by PHPUnit
e9a352e
@lsmith77

+1

@sebastianbergmann

Closed by 4ad409a.

@visor visor added a commit that referenced this pull request Aug 18, 2011
@sebastianbergmann Close #88. 54d1cad
@ardell ardell pushed a commit to apinstein/phpunit that referenced this pull request Oct 6, 2011
@sebastianbergmann Close #88. 4ad409a
@convissor

This change is problematic. Now one can't write a simple test case for PHP core functions (like DateTime) that throw plain old Exceptions. Let alone, this change breaks BC, so now existing code out there that did $this->setExpectedException('Exception'); no longer works and we all have to rewrite the tests with try/catch blocks.

@slusarz
slusarz commented Feb 3, 2012

Agreed... this commit was not thought out very well. And it doesn't make any sense in relation to the problem it allegedly solves. When I explictly say I am expecting an Exception to be thrown, I'm expecting just that: an Exception to be thrown. This shouldn't catch an ErrorException, an Extended_Exception, or anything else. So I don't see the issue. (I am guessing PHPUnit is not throwing plain Exceptions when it catches things like syntax/runtime errors.)

Not to mention this is blatantly counterintuitive. And not mentioned anywhere in the documentation.

@sebastianbergmann
Owner

You are beating a dead horse. Expecting the generic Exception class is possible again in the master branch (which will become PHPUnit 3.7). That does not mean, however, that using the generic Exception class in your code is suddenly a good idea.

@lathspell

Any chance that this fix of the fix gets into the next 3.6.x release?

@sebastianbergmann

No.

@mattcg
mattcg commented Mar 22, 2012

@lathspell You could always use the Standard PHP Library Exceptions if you think writing exception classes is overkill. They're all allowed by PHPUnit, even pre-3.7.

@greglamb greglamb pushed a commit to greglamb/phpunit that referenced this pull request Apr 19, 2013
@sebastianbergmann Close #88. f9466a6
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.