rogervila/laravel-email-failer

用于测试 Laravel 邮件失败的辅助类

1.0.0 2024-06-20 18:06 UTC

This package is auto-updated.

Last update: 2024-09-07 18:09:43 UTC


README

Laravel Email Failer

Build Status Build status StyleCI Latest Stable Version Total Downloads License MadeWithLaravel.com shield

Laravel Email Failer

composer require --dev rogervila/laravel-email-failer

关于

触发邮件失败,以断言在 Laravel 应用程序中邮件发送失败时会发生什么

用法

一旦将 MailFailer 实例绑定,所有邮件都将失败。这有助于断言您的应用程序正确处理了邮件异常(例如:将电子邮件地址标记为无效)

class MyService
{
    public static function sendEmail()
    {
        \Illuminate\Support\Facades\Mail::send(...);
    }
}

public function test_happy_path()
{
    Mail::fake();

    MyService::sendEmail();

    Mail::assertSent(MyMailable::class);
}

public function test_email_failures()
{
    $this->expectException(TransportException::class);

    \LaravelEmailFailer\MailFailer::bind();

    MyService::sendEmail();

    Mail::assertNotSent(MyMailable::class);

    dump(Mail::failures());
    // Assert here what happens when the email has failed
}

许可证

Laravel Email Failer 是开源软件,采用 MIT 许可证

图标由 Darius Dan 制作,来源于 www.flaticon.com,并受 CC 3.0 BY 许可。