cyber-duck/mailgrasp

This package is abandoned and no longer maintained. The author suggests using the cyber-duck/mailgrasp package instead.

A package for Laravel applications (5.1) to add support for email testing in your test classes.

1.1.1 2017-02-02 21:55 UTC

This package is auto-updated.

Last update: 2021-10-26 09:54:23 UTC


README

This functionality is redily available in later releases of Laravel.

MailGrasp

Build Status Latest Stable Version Total Downloads License

MailGrasp is a package for Laravel applications (5.1+) to add support for email testing in your test classes.

Author: Simone Todaro

Made with ❤️ by Cyber-Duck Ltd

Installation

composer require cyber-duck/mailgrasp --dev

Usage

Add the InteractsWithEmails to your test class. That's it!

use \Cyberduck\MailGrasp\Testing\InteractsWithEmails;

The custom mailer will be initialised as soon as the visit() method is called.

seeEmails

It checks if exactly $count emails have been sent or enqueued.

$this->visit('/route/which/sends/2/emails')
    ->seeEmails(2);

seeEmailsInQueue

It checks if exactly $count emails have been enqueued.

$this->visit('/route/which/enqueues/2/emails')
    ->seeEmailsInQueue(2);

dontSeeEmails / notSeeEmails

It checks that no email has been sent or enqueued.

$this->visit('/route/with/no/emails')
    ->dontSeeEmails();

// OR

$this->visit('/route/with/no/emails')
    ->notSeeEmails();

dontSeeEmailsInQueue / notSeeEmailsInQueue

It checks that no email has been enqueued.

$this->visit('/route/with/no/emails')
    ->dontSeeEmailsInQueue();

// OR

$this->visit('/route/with/no/emails')
    ->notSeeEmailsInQueue();

seeEmail

It checks that an email matching given critaria has been sent or enqueued.

$this->visit('/route/which/sends/emails')
    ->seeEmail(function($m) {
        $m->from('from@test.com');
        $m->to('to@test.com');
        $m->subject('Subject');
    });

// OR

$this->visit('/route/which/sends/emails')
    ->seeEmail($this->message()
        ->from('from@test.com')
        ->to('to@test.com')
        ->subject('Subject');
    });

dontSeeEmail

Complete opposite of seeEmail.

$this->visit('/route/which/sends/emails')
    ->dontSeeEmail(function($m) {
        $m->from('from@test.com');
        $m->to('to@test.com');
        $m->subject('Subject');
    });

// OR

$this->visit('/route/which/sends/emails')
    ->dontSeeEmail($this->message()
        ->from('from@test.com')
        ->to('to@test.com')
        ->subject('Subject');
    });

seeEmailInQueue

It checks that an email matching given critaria has been enqueued.

$this->visit('/route/which/enqueues/emails')
    ->seeEmailInQueue(function($m) {
        $m->from('from@test.com');
        $m->to('to@test.com');
        $m->subject('Subject');
    });

// OR

$this->visit('/route/which/enqueues/emails')
    ->seeEmailInQueue($this->message()
        ->from('from@test.com')
        ->to('to@test.com')
        ->subject('Subject');
    });

seeInEmail

It checks that an email matching the given critaria contains the given string.

$this->visit('/route/which/sends/emails')
    ->seeInEmail(function($m) {
        $m->from('from@test.com');
        $m->to('to@test.com');
        $m->subject('Subject');
    }, 'Lorem ipsum dolor sit amet');

// OR

$this->visit('/route/which/sends/emails')
    ->seeInEmail($this->message()
        ->from('from@test.com')
        ->to('to@test.com')
        ->subject('Subject');
    }, 'Lorem ipsum dolor sit amet);

clickInEmail

Visit the page in the email link. Useful to test activation links.

$this->visit('/route/which/enqueues/emails')
    ->clickInEmail(function($m) {
        $m->from('from@test.com');
        $m->to('to@test.com');
        $m->subject('Subject');
    });

// OR

$this->visit('/route/which/enqueues/emails')
    ->clickInEmail($this->message()
        ->from('from@test.com')
        ->to('to@test.com')
        ->subject('Subject');
    });

If there is more than one link in the email, it's possible to select the link passing a css selector as second parameter.

$this->visit('/route/which/enqueues/emails')
    ->clickInEmail(function($m) {
        $m->from('from@test.com');
        $m->to('to@test.com');
        $m->subject('Subject');
    }, 'a.activation-link');

// OR

$this->visit('/route/which/enqueues/emails')
    ->clickInEmail($this->message()
        ->from('from@test.com')
        ->to('to@test.com')
        ->subject('Subject');
    }, 'a.activation-link');