Skip to content

[12.x] assertThrowsNothing#55100

Merged
taylorotwell merged 2 commits into
laravel:12.xfrom
gdebrauwer:assert-throws-nothing
Mar 22, 2025
Merged

[12.x] assertThrowsNothing#55100
taylorotwell merged 2 commits into
laravel:12.xfrom
gdebrauwer:assert-throws-nothing

Conversation

@gdebrauwer

Copy link
Copy Markdown
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
Copy Markdown
Contributor

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

@taylorotwell taylorotwell merged commit 01b1450 into laravel:12.x Mar 22, 2025
@AhmedAlaa4611

Copy link
Copy Markdown
Contributor

Has it been documented yet?

@taylorotwell

Copy link
Copy Markdown
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