Skip to content

Commit 49af870

Browse files
authored
Add example of Mail::fake() for unit testing in docs (#170)
1 parent b368919 commit 49af870

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

services/mail.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,3 +465,18 @@ You can dynamically disable sending mail using the `Mail::pretend` method. When
465465
```php
466466
Mail::pretend();
467467
```
468+
469+
### Unit testing
470+
471+
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:
472+
473+
```php
474+
Mail::fake();
475+
476+
// ... Run code that sends email 'this.is.my.email' template.
477+
478+
// Check that the email was sent
479+
Mail::assertSent('this.is.my.email', function ($mail) {
480+
return $mail->hasTo('[email protected]');
481+
});
482+
```

0 commit comments

Comments
 (0)