setExpectedException behaves as setExpectedExceptionInstance would #102

berlincount opened this Issue Jan 4, 2011 · 2 comments

2 participants



given the following code:


class ExceptionChild extends Exception {}

class DemoException extends PHPUnit_Framework_TestCase
    public function testOkay()
        throw new ExceptionChild;

    public function testImprecise()
        throw new ExceptionChild;


The call

phpunit DemoException.php

doesn't give a failure for the 'Imprecise' case. While this is technically correct (as ExceptionChild is an instance of Exception) it makes it impossible to write test code checking whether a specific Exception class has been converted to a more generic one.




This is why in PHPUnit 3.6 @expectedException (and setExpectedException()) no longer accept Exception as the expected exception class.


okay, but what about Exception vs Zend_Exception vs Zend_Ldap_Exception?


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