Skip to content

[12.x] assertThrowsNothing #55100

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

Merged
merged 2 commits into from
Mar 22, 2025
Merged

Conversation

gdebrauwer
Copy link
Contributor

Sometimes I assert multiple situations in a single test, for example, different situations in which an exception should be thrown or not. The different situations where an exception is thrown are easy to assert thanks to the assertThrows method. This PR introduces the inverse method assertThrowsNothing method so you can easily and explicitly assert situations where you want to be sure that no exception is thrown.

$this->assertThrowsNothing(function () {
    throw new Exception(); // fails if an exception is thrown
});

@gdebrauwer gdebrauwer changed the title [11.x] assertThrowsNothing [12.x] assertThrowsNothing Mar 20, 2025
@cosmastech
Copy link
Contributor

Would love to see this and the assertThrown PR get merged.

@taylorotwell taylorotwell merged commit 01b1450 into laravel:12.x Mar 22, 2025
38 of 39 checks passed
@AhmedAlaa4611
Copy link
Contributor

Has it been documented yet?

@taylorotwell
Copy link
Member

@AhmedAlaa4611 just did. 👍

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.

4 participants