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

Allow expecting any Throwable #4997

Closed
SamMousa opened this issue May 29, 2018 · 2 comments
Closed

Allow expecting any Throwable #4997

SamMousa opened this issue May 29, 2018 · 2 comments

Comments

@SamMousa
Copy link
Collaborator

What are you trying to achieve?

I'm trying to catch a TypeError.

What do you get instead?

Since expectException() only checks the class of anything that's a subclass of \Exception, throwables like \TypeError are not caught.

Snippet from https://github.com/Codeception/Codeception/blob/2.4/src/Codeception/Module/Asserts.php#L437

try {
            $callback();
        } catch (\Exception $e) {
            if (!$e instanceof $class) {
                $this->fail(sprintf("Exception of class $class expected to be thrown, but %s caught", get_class($e)));
            }

I propose catching \Throwable and doing the check.

@DavertMik
Copy link
Member

I think exceptException is very explicit and it doesn't say it expects Throwable :)

You can add send PR with 2 methods:

  • exceptError (for everything which is not an exception)
  • exceptThrow (for any throwable)

@Naktibalda
Copy link
Member

expectThrowable was implemented by #5213 long time ago.

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

3 participants