Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expectException($e) passing class fix #2221

Closed
stampycode opened this issue Jun 17, 2016 · 0 comments
Closed

expectException($e) passing class fix #2221

stampycode opened this issue Jun 17, 2016 · 0 comments

Comments

@stampycode
Copy link

(example extends PHPUnit_Framework_TestCase)

This works fine:

public function testThrow()
{
    $expected = new \Exception("FOO");
    $this->expectException(get_class($expected));
    throw $expected;
}

This doesn't:

public function testThrow()
{
    $expected = new \Exception("FOO");
    $this->expectException($expected);
    throw $expected;
}

The method signature/PHPDoc for expectException($e) is to accept "mixed" parameter, and doesn't mind when you submit an Exception object - but it won't catch that exception object when it is thrown, even if it's that exact object that is thrown.

I'd suggest either passing instances of Exception generates an InvalidArgumentException, or instances of Exception passed in are just used to call get_class on to stringify them, or the actual instance of that exception is then expected (which I think would be less useful generally).

Either way, accepting the exception object then basically ignoring it isn't ideal...

(using PHPUnit 5.4.4)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant