Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Mailer Test Laravel Package

zenstruck/mailer-test

Opinionated helpers to test emails sent with symfony/mailer. Use InteractsWithMailer in KernelTestCase/WebTestCase for fluent assertions like assertNoEmailSent, assertSentEmailCount, and inspect messages with TestEmail (subject, recipients, body, attachments).

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Enhanced Test Coverage for Email Workflows: Adopt this package to build robust email testing capabilities into your Laravel/Symfony-based applications, ensuring critical user flows (e.g., password resets, notifications, transactional emails) are validated rigorously. This aligns with QA-driven development and reduces production email-related bugs.
  • Roadmap: Shift from Manual to Automated Email Validation: Replace ad-hoc email checks (e.g., logging to a file or console) with structured assertions, improving test reliability and developer productivity. Prioritize this for projects where email reliability is a core feature (e.g., SaaS platforms, e-commerce, or communication tools).
  • Build vs. Buy: Buy this lightweight, opinionated solution over custom implementations or frameworks like MailerAssertionsTrait to avoid reinventing wheel. It’s maintained, Symfony 8/Laravel-compatible, and integrates seamlessly with existing testing stacks.
  • Use Cases:
    • User Onboarding: Verify welcome emails contain correct links/placeholders.
    • Password Resets: Assert emails include valid tokens and subject lines.
    • Transactional Emails: Test receipts, shipping updates, or payment confirmations.
    • Marketing Campaigns: Validate templated emails (e.g., newsletters) for content accuracy.
    • Third-Party Integrations: Ensure webhook-triggered emails (e.g., Stripe, Slack) meet specs.

When to Consider This Package

  • Adopt if:

    • Your app relies on email as a critical user interaction (e.g., authentication, notifications).
    • You use Symfony Mailer or Laravel’s Mail system (compatible via Symfony’s bridge).
    • Your team prioritizes test automation over manual email verification.
    • You want fluent assertions (e.g., assertEmailSentTo()->assertSubjectContains()) over verbose PHPUnit assertions.
    • You’re using Zenstruck/Browser for end-to-end testing and need email assertions in browser tests.
  • Look Elsewhere if:

    • Your stack doesn’t use Symfony Mailer/Laravel Mail (e.g., pure PHPMailer or AWS SES direct).
    • You need email previews (consider tools like MailHog or Laravel’s Mail::pretend()).
    • Your team prefers BDD frameworks (e.g., Behat) over unit/integration tests.
    • You’re constrained by legacy PHP < 8.0 or Symfony < 5.4.
    • You require attachments validation beyond basic assertions (e.g., PDF rendering).

How to Pitch It (Stakeholders)

For Executives:

"This package lets us automate email testing—a pain point in our QA process. Right now, we manually verify emails (e.g., checking inboxes or logs), which is error-prone and slow. With zenstruck/mailer-test, we’ll catch issues like broken links, missing content, or wrong recipients in CI, saving hours of manual work and reducing production bugs. It’s a low-risk, high-reward upgrade: minimal dev effort, immediate ROI in reliability. For example, if our password reset emails fail in staging, we’ll know before users see it."

Ask: "Should we prioritize this for the next sprint to harden our email workflows?"


For Engineering/Dev Teams:

*"This replaces Symfony’s built-in MailerAssertionsTrait with a more expressive, maintainable API. Key wins:

  • Fluent assertions: Chain methods like assertEmailSentTo()->assertSubjectContains() for cleaner tests.
  • Browser test support: Works with zenstruck/browser for E2E email validation (e.g., testing a checkout flow that sends a receipt).
  • Custom assertions: Extend TestEmail to add app-specific checks (e.g., Postmark tags, custom headers).
  • No flakiness: Emails persist between kernel reboots in tests, so you don’t lose track of sent messages.

Migration path:

  1. Add to composer.json (dev dependency).
  2. Replace use Symfony\Bridge\Doctrine\Test\MailerAssertionsTrait with use Zenstruck\Mailer\Test\InteractsWithMailer.
  3. Update assertions to use the new fluent syntax.

Example:

// Old (verbose)
$this->assertCount(1, $this->container->get('test.mailer.message_collector')->getMessages());
$email = $messages[0];
$this->assertEquals('kevin@example.com', $email->getTo()[0]);

// New (fluent)
$this->mailer()->assertEmailSentTo('kevin@example.com');

Blockers? Let’s discuss if your team needs custom assertions or has constraints on Symfony versions."*


Metrics to Highlight:

  • Time saved: ~30% faster email test writing (subjective, but backed by fluent API).
  • Risk reduction: Catches email bugs in CI, not production.
  • Future-proof: Actively maintained (last release: 2026, Symfony 8 support).
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
daikazu/eloquent-salesforce-objects
unseen-codes/chat
romalytar/yammi-jobs-monitoring-laravel
kisame76/filament-db-table-state
nqxcode/laravel-lucene-search
dpfx/laravel-livewire-wizards
workos/workos-php-laravel
sofa/laravel-global-scope
nawasara/auth-primitives
adhocrat-io/arkhe-main
make-dev/orca-harpoon
itsemon245/lamet
baks-dev/dashboard
amoifr/pickle-panther-bundle
make-dev/orca
dmstr/symfony-system-resources-bundle
dmstr/symfony-job-queue-bundle
dmstr/openapi-json-schema-bundle
dmstr/keycloak-security-bundle
dmstr/doctrine-audit-log-bundle