Laravel unit testing emails

前端 未结 8 1536
难免孤独
难免孤独 2021-02-20 10:12

My system sends a couple of important emails. What is the best way to unit test that?

I see you can put it in pretend mode and it goes in the log. Is there something t

8条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-20 10:44

    if you are using Notifcations in laravel you can do that like below

    Notification::fake();
    $this->post(...);
    $user = User::first();
    Notification::assertSentTo([$user], VerifyEmail::class);
    

    https://laravel.com/docs/7.x/mocking#notification-fake

提交回复
热议问题