Skip to content

Commit

Permalink
Add example of Mail::fake() for unit testing in docs (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrkbingham authored Oct 14, 2024
1 parent b368919 commit 49af870
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions services/mail.md
Original file line number Diff line number Diff line change
Expand Up @@ -465,3 +465,18 @@ You can dynamically disable sending mail using the `Mail::pretend` method. When
```php
Mail::pretend();
```

### Unit testing

When unit testing, you may want to utilize Laravel's `fake` method on the Mail facade. This ensures your local configuration is ignored and mailing assertions can be performed without sending emails while your tests are running:

```php
Mail::fake();

// ... Run code that sends email 'this.is.my.email' template.

// Check that the email was sent
Mail::assertSent('this.is.my.email', function ($mail) {
return $mail->hasTo('[email protected]');
});
```

0 comments on commit 49af870

Please sign in to comment.