Skip to content

Commit

Permalink
Adds fail and fails documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
nunomaduro authored Dec 28, 2023
1 parent 989e3d5 commit d5751d8
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions exceptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,38 @@ it('throws no exceptions', function () {
})->throwsNoExceptions();
```

Sometimes, you may want to simply mark a test as failed. You can use the `fail()` method to do so.

```php
it('fail', function () {
$this->fail();
});
```

You may also provide a message to the `fail()` method.

```php
it('fail', function () {
$this->fail('Something went wrong.');
});
```

In addition, you can also use the `fails()` method to verify the test fails.

```php
it('fails', function () {
throw new Exception('Something happened.');
})->fails();
```

Just like the `fail()` method, you may also provide a message to the `fails()` method.

```php
it('fails', function () {
throw new Exception('Something happened.');
})->fails('Something went wrong.');
```

---

After learning how to write tests that assert exceptions, the next step is to explore "Test Filtering". This feature allows you to efficiently run specific tests based on criteria like test name, dirty files, and more: [Filtering Tests →](/docs/filtering-tests)

0 comments on commit d5751d8

Please sign in to comment.