Download the PHP package zenstruck/mailer-test without Composer
On this page you can find all versions of the php package zenstruck/mailer-test. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package mailer-test
zenstruck/mailer-test
Alternative, opinionated helpers for testing emails sent with symfony/mailer
. This package is
an alternative to the FrameworkBundle's MailerAssertionsTrait
.
[!TIP] Want to watch a screencast 🎥 about it? Check out symfonycasts.com/mailer-test.
Installation
-
Install the library:
- If not added automatically by symfony/flex, enable
ZenstruckMailerTestBundle
in yourtest
environment
Usage
You can interact with the mailer in your tests by using the InteractsWithMailer
trait in
your KernelTestCase
/WebTestCase
tests:
NOTE: Emails are persisted between kernel reboots within each test. You can reset the
collected emails with $this->mailer()->reset()
.
SentEmails Collection
You can access all the sent emails and filter down to just the ones you want to make assertions on. Most methods are fluent.
Custom TestEmail
The TestEmail
class shown above is a decorator for \Symfony\Component\Mime\Email
with some assertions. You can extend this to add your own assertions:
Then, use in your tests:
zenstruck/browser Integration
This library provides a zenstruck/browser
"Component" and
"Extension". Since browser's
make HTTP requests to your app, the messages are accessed via the profiler (using
symfony/mailer
's data collector). Because of this, the InteractsWithMailer
trait
is not required in your test case. Since the profiler is required, this functionality
is not available with PantherBrowser
.
MailerComponent
The simplest way to get started testing emails with zenstruck/browser
is to use the
MailerComponent
:
MailerExtension
If many of your tests make email assertions the custom browser using the provided
MailerExtension
trait:
Now, within your tests using this custom browser, the following email assertion API is available:
All versions of mailer-test with dependencies
symfony/framework-bundle Version ^5.4|^6.0|^7.0
symfony/mailer Version ^5.4|^6.0|^7.0
zenstruck/assert Version ^1.0
zenstruck/callback Version ^1.1