Skip to content

Commit

Permalink
improve fail() fails() documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
dansysanalyst committed Jan 12, 2024
1 parent 182faea commit cc01149
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions exceptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,33 +64,37 @@ it('throws no exceptions', function () {
Sometimes, you may want to simply mark a test as failed. You can use the `fail()` method to do so.

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

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

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

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

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

Just like the `fail()` method, you may also provide a message to the `fails()` method.
You can also assert the failure reason by providing a message to the `fails()` method.

```php
it('fails', function () {
throw new Exception('Something happened.');
})->fails('Something went wrong.');
it('fails as expected', function () {
$this->fail('Something happened.');
})->fails('Something happened.'); // Pass

it('fails in an unexpected way', function () {
$this->fail('Something unexpected happened.');
})->fails('Something happened.'); // Fail
```

---
Expand Down

0 comments on commit cc01149

Please sign in to comment.