Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Mar 14, 2024. It is now read-only.

tighten/mailthief

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Codeship Status for tightenco/mailthief

MailThief

MailThief is a fake mailer for Laravel applications that makes it easy to test mail without actually sending any emails.

Quickstart

Installation:

composer require tightenco/mailthief --dev

Example route:

Route::post('register', function () {
    // <snip> Validation, create account, etc. </snip>

    Mail::send('emails.welcome', [], function ($m) {
        $email = request('email');
        $m->to($email);
        $m->subject('Welcome to my app!');
        $m->from('[email protected]');
        $m->bcc('[email protected]');
    });

    // <snip> Return response </snip>
});

If you're copying this sample test, remember to create an email view at resources/views/emails/welcome.blade.php.

Example test:

use MailThief\Facades\MailThief;

class RegistrationTest extends TestCase
{
    public function test_new_users_are_sent_a_welcome_email()
    {
        // Block and intercept outgoing mail, important!
        MailThief::hijack();

        $this->post('register', [
            'name' => 'John Doe',
            'email' => '[email protected]',
            'password' => 'secret',
        ]);

        // Check that an email was sent to this email address
        $this->assertTrue(MailThief::hasMessageFor('[email protected]'));

        // BCC addresses are included too
        $this->assertTrue(MailThief::hasMessageFor('[email protected]'));

        // Make sure the email has the correct subject
        $this->assertEquals('Welcome to my app!', MailThief::lastMessage()->subject);

        // Make sure the email was sent from the correct address
        // (`from` can be a list, so we return it as a collection)
        $this->assertEquals('[email protected]', MailThief::lastMessage()->from->first());
    }
}

MailThief supports just about everything you can do with the regular Laravel Mailer and Message classes. More detailed documentation is coming soon, but in the mean time, explore the MailThief and Message classes to get an idea of what's available.

About

A fake mailer for Laravel Applications for testing mail.

Topics

Resources

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 28

Languages