Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

setExpectedException behaves as setExpectedExceptionInstance would #102

Closed
berlincount opened this Issue · 2 comments

2 participants

@berlincount

Hello,

given the following code:

<?php

class ExceptionChild extends Exception {}

class DemoException extends PHPUnit_Framework_TestCase
{
    public function testOkay()
    {
        $this->setExpectedException("ExceptionChild");
        throw new ExceptionChild;
    }

    public function testImprecise()
    {
        $this->setExpectedException("Exception");
        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.

Cheers,

Andreas

@sebastianbergmann

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

@berlincount

okay, but what about Exception vs Zend_Exception vs Zend_Ldap_Exception?

reopen?

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.