cyber-duck / mailgrasp
A package for Laravel applications (5.1) to add support for email testing in your test classes.
Installs: 7 104
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 5
Forks: 2
Open Issues: 0
Requires
- illuminate/mail: ^5.0
- illuminate/view: ^5.0
Requires (Dev)
- laravel/framework: ^5.0
- mockery/mockery: ^0.9.5
- phpunit/phpunit: ^5.5
- squizlabs/php_codesniffer: 2.*
- symfony/css-selector: 2.7.*
- symfony/dom-crawler: 2.7.*
README
This functionality is redily available in later releases of Laravel.
MailGrasp
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');