From 49af8701fae33d7fdeb8a0fd7340385bdbb196df Mon Sep 17 00:00:00 2001 From: Mark Bingham Date: Mon, 14 Oct 2024 06:48:33 -0500 Subject: [PATCH] Add example of Mail::fake() for unit testing in docs (#170) --- services/mail.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/services/mail.md b/services/mail.md index d12a010a..2bccead7 100644 --- a/services/mail.md +++ b/services/mail.md @@ -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('test@example.com'); +}); +```