Skip to content
This repository was archived by the owner on Nov 1, 2022. It is now read-only.
This repository was archived by the owner on Nov 1, 2022. It is now read-only.

Improve mail assertions #4

@scottbedard

Description

@scottbedard

Leaving this here as a reminder to future me, mail assertions can be cleaned up by using Alxy's mail fake.

https://gist.github.com/alxy/6e74d306be7bd0c9d1f134f34d547a44

Example usage:

public function testNewFakeMailer()
{
    Mail::swap(new MailFake());

    // These variables are available inside the message as Twig
    $vars = ['name' => 'Joe', 'user' => 'Mary'];

    Mail::send('backend::mail.invite', $vars, function($message) {
        $message->to('admin@domain.tld', 'Admin Person');
        $message->subject('This is a reminder');
    });

    Mail::assertSent('backend::mail.invite', function (Mailable $mailable) use ($vars) {
        return $mailable->viewData['name'] === 'Joe' &&
            $mailable->viewData['user'] === 'Mary' &&
            $mailable->hasTo('admin@domain.tld');
    });
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions