Skip to content

This package adds support for email testing in a Laravel application (>5.0)

License

Notifications You must be signed in to change notification settings

Cyber-Duck/Mail-Grasp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚨 Discontinued 🚨

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('[email protected]');
        $m->to('[email protected]');
        $m->subject('Subject');
    });

// OR

$this->visit('/route/which/sends/emails')
    ->seeEmail($this->message()
        ->from('[email protected]')
        ->to('[email protected]')
        ->subject('Subject');
    });

dontSeeEmail

Complete opposite of seeEmail.

$this->visit('/route/which/sends/emails')
    ->dontSeeEmail(function($m) {
        $m->from('[email protected]');
        $m->to('[email protected]');
        $m->subject('Subject');
    });

// OR

$this->visit('/route/which/sends/emails')
    ->dontSeeEmail($this->message()
        ->from('[email protected]')
        ->to('[email protected]')
        ->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('[email protected]');
        $m->to('[email protected]');
        $m->subject('Subject');
    });

// OR

$this->visit('/route/which/enqueues/emails')
    ->seeEmailInQueue($this->message()
        ->from('[email protected]')
        ->to('[email protected]')
        ->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('[email protected]');
        $m->to('[email protected]');
        $m->subject('Subject');
    }, 'Lorem ipsum dolor sit amet');

// OR

$this->visit('/route/which/sends/emails')
    ->seeInEmail($this->message()
        ->from('[email protected]')
        ->to('[email protected]')
        ->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('[email protected]');
        $m->to('[email protected]');
        $m->subject('Subject');
    });

// OR

$this->visit('/route/which/enqueues/emails')
    ->clickInEmail($this->message()
        ->from('[email protected]')
        ->to('[email protected]')
        ->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('[email protected]');
        $m->to('[email protected]');
        $m->subject('Subject');
    }, 'a.activation-link');

// OR

$this->visit('/route/which/enqueues/emails')
    ->clickInEmail($this->message()
        ->from('[email protected]')
        ->to('[email protected]')
        ->subject('Subject');
    }, 'a.activation-link');