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

[2.x] allow to expect toThrow against an exception instance #797

Merged
merged 1 commit into from May 1, 2023

Conversation

fabio-ivona
Copy link
Collaborator

This PR implements Throwable support as argument of a toThrow expectation. This will allow to:

expect(fn() => $user->subscribe($team))
        ->toThrow(new TeamException("user is already subscribed to team"));

in this case, the expectation will pass if the Throwable is an instance of TeamException and has user is already subscribed to team as exception message

this will allow a fast check when using static exception constructors like the following one, without the need to enter the code and check the exception message:

expect(fn() => $user->subscribe($team))
        ->toThrow(TeamException::alreadySubscribed());

@nunomaduro nunomaduro merged commit cddddc3 into pestphp:2.x May 1, 2023
14 checks passed
@nunomaduro
Copy link
Member

Good job here. Can you add docs?

fabio-ivona added a commit to pestphp/docs that referenced this pull request May 2, 2023
This PR will add a new example for `toThrow()` including the new check implemented in pestphp/pest#797
@fabio-ivona fabio-ivona deleted the toThrow-improvement branch May 2, 2023 06:29
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

Successfully merging this pull request may close these issues.

None yet

2 participants