Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example of Mail::fake() for unit testing in docs #170

Merged
merged 2 commits into from
Oct 14, 2024

Conversation

Mrkbingham
Copy link
Contributor

It appears this section of the docs is outdated. The Mail::pretend() method was a part of Laravel's Mail facade in versions prior to Laravel 5.5. This method was used to prevent emails from actually being sent during testing, and instead write them to the application's log files.

However, this method has been removed in Laravel 5.5 and later versions. The recommended way to prevent emails from being sent during testing is to use the Mail::fake() method, which is part of the Mail facade in Laravel 5.5 and later versions.

There is one example added here that is not very clear in the Laravel documentation since theirs only passes through classes, and checking for templates will be very relevant to WinterCMS developers.

@bennothommo
Copy link
Member

@Mrkbingham thanks for submitting this PR.

We still provide the pretend() method in our Mailer implementation for backwards compatibility, and it does serve a separate purpose to the fake Mail instances provided by the Mail::fake() facade method - dynamically recording mail in logs as opposed to allowing test assertions through the MailFake instance.

I would suggest that perhaps we display both in the docs and outline the scenarios in which you would use one or the other - ie. use pretend() for quick logging of mail during development, and use fake() for unit testing.

Any thoughts on this?

@Mrkbingham
Copy link
Contributor Author

Mrkbingham commented Oct 11, 2024

@bennothommo I've only let this languish for nearly a year! Apologies for the massive delay here, but I like your suggestion of including both. I've updated my PR, let me know what you think.

@bennothommo
Copy link
Member

@Mrkbingham great work! :)

@bennothommo bennothommo changed the title Updates Mail::pretend to Mail::fake and adds template-based testing example Add example of Mail::fake() for unit testing in docs Oct 14, 2024
@bennothommo bennothommo merged commit 49af870 into wintercms:develop Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants