Skip to content

A Laravel package with PHPunit assertions to test Emails generated by Mailcatcher.

License

Notifications You must be signed in to change notification settings

drakakisgeo/mailtester

Repository files navigation

Mail Tester

Latest Version on Packagist Software License Build Status Quality Score Total Downloads

A package to help with acceptance Email testing. The goal is to add usefull PHPunit assertions in a Trait that you can include when there is a need to test emails that are fired from acceptance testing packages like Laravel Dusk.

Install

This package assumes that you've already installed Mailcatcher. You can check this tutorial on how to install it to your system.

Via Composer

$ composer require drakakisgeo/mailtester

Laravel 5.*

After updating composer, add the ServiceProvider to the providers array in config/app.php

Drakakisgeo\Mailtester\MailtesterServiceProvider::class,

Copy the package config to your local config with the publish command:

$ php artisan vendor:publish --provider="Drakakisgeo\Mailtester\MailtesterServiceProvider"

Instructions

Include the InteractsWithMailCatcher Trait in your test and make sure that your test extends the Laravel's Testcase class. Immediately you have access to the following methods:

Email was send

  • assertEmailIsSent()

Email subject contains a $string

  • assertEmailFirstSubjectContains()
  • assertEmailLastSubjectContains()
  • assertEmailNthSubjectContains()

Email subject equals a $string

  • assertEmailFirstSubjectEquals()
  • assertEmailLastSubjectEquals()
  • assertEmailNthSubjectEquals()
  • assertEmailSubjectEquals()

Email Html body contains a $string

  • assertEmailFirstHtmlContains()
  • assertEmailLastHtmlContains()
  • assertEmailNthHtmlContains()
  • assertEmailHtmlContains()

Email Text body contains a $string

  • assertEmailFirstTextContains()
  • assertEmailLastTextContains()
  • assertEmailNthTextContains()
  • assertEmailTextContains()

Email sender is the target $email

  • assertEmailFirstSenderEquals()
  • assertEmailLastSenderEquals()
  • assertEmailNthSenderEquals()
  • assertEmailSenderEquals()

Email recipient is the target $email

  • assertEmailFirstRecipientsContain()
  • assertEmailLastRecipientsContain()
  • assertEmailNthRecipientsContain()
  • assertEmailRecipientsContain()

Email Cc is the target $email

  • assertEmailFirstCcContain()
  • assertEmailLastCcContain()
  • assertEmailNthCcContain()
  • assertEmailCcContain()

Email Bcc is the target $email

  • assertEmailFirstBccContain()
  • assertEmailLastBccContain()
  • assertEmailNthtBccContain()
  • assertEmailBccContain()

Email Attachment is the target $file

  • Soon!

Contributing

Please see CONTRIBUTING and CONDUCT for details.

Credits

License

The MIT License (MIT). Please see License File for more information.