tijmen-wierenga/laravel-mail-tester

An extension to Laravel's TestCase which allows you to run unit tests on emails
196
Install
composer require tijmen-wierenga/laravel-mail-tester
Latest Version:v0.1.2
License:MIT
Last Updated:Jul 28, 2016
Links: GitHub  ·  Packagist
Maintainer: TijmenWierenga

LaravelMailTester

An extension to Laravel's TestCase which allows you to run unit tests on emails.

Installation

composer require tijmen-wierenga/laravel-mail-tester

Next, add the trait to the TestCase class located at tests/TestCase:

use TijmenWierenga\LaravelMailTester\TestsEmail;

class TestCase extends Laravel\Lumen\Testing\TestCase
{

    use TestsEmail;
    
    ...
    
}

How it works

LaravelMailTester adds an event listener as a plugin when in a testing environment. It tracks when an email is sent, and stores all data in the test case. You can then perform assertions against it.

Usage

class AuthenticationTest extends TestCase
{
  /**
  * @test
  */
  public function it_sends_an_email() {
    // Send an email
    Mail::raw('Wow, awesome email testing!', function($mail) {
      $mail->to('tijmen@floown.com');
      $mail->from('no-reply@floown.com');
      $mail->subject('Read this awesome email');
    }
    
    $this->assertEmailWasSent()
      ->assertEmailWasSentTo('tijmen@floown.com')
      ->assertEmailWasSentFrom('no-reply@floown.com')
      ->assertEmailBodyContains('awesome email testing')
  }
}

More assertions to come.

License

The MIT License (MIT).

Related Packages

erirk/paypalpayment

laravel-paypalpayment is simple package help you process direct credit card paym...

0
gabrieloliverio/laravel5-generators

Database metadata-based generators for Laravel 5

1
doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

628,058,007 9,707
laravel/framework

The Laravel Framework.

572,249,171 34,893
laravel/tinker

Powerful REPL for the Laravel framework.

485,678,092 7,440