Skip to content

Commit

Permalink
Merge pull request #217 from devajmeireles/throws-unless
Browse files Browse the repository at this point in the history
[2.x] Adding `throwsUnless`
  • Loading branch information
nunomaduro authored Oct 17, 2023
2 parents ce0ae54 + abd55e6 commit 6d773b1
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions exceptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ it('throws exception', function () {
})->throwsIf(fn() => DB::getDriverName() === 'mysql', Exception::class, 'MySQL is not supported.');
```

Just like `throwsIf()` method, you can use the `throwsUnless()` method to conditionally verify an exception if a given boolean expression evaluates to false.

```php
it('throws exception', function () {
//
})->throwsUnless(fn() => DB::getDriverName() === 'mysql', Exception::class, 'Only MySQL is supported.');
```

You can also verify that a given closure throws one or more exceptions using the [toThrow()](/docs/expectations#expect-toThrow) method of the expectation API.

```php
Expand Down

0 comments on commit 6d773b1

Please sign in to comment.