Laravel 5.4 using Mail fake with Mail::queue, Mail::assertSent not working

Viewed 2442

I am writing unit test for a code that sends email with Mail::queue function, like the one in the documentation: https://laravel.com/docs/5.4/mocking#mail-fake

My Test:

/** @test */
public function send_reminder()
{
     Mail::fake();

     $response = $this->actingAs($this->existing_account)->json('POST', '/timeline-send-reminder', []);
     $response->assertStatus(302);

     Mail::assertSent(ClientEmail::class, function ($mail) use ($approver) {
          return $mail->approver->id === $approver->id;
     });
}

Code being Tested:

Mail::to($email, $name)->queue(new ClientEmail(Auth::user()));

Error Message:

The expected [App\Mail\ClientEmail] mailable was not sent.
Failed asserting that false is true.

The email is sent when I manually test it, but not from Unit Test. I'm thinking it might be because I am using Mail::queue instead of Mail::send function.

In .env file, I have

QUEUE_DRIVER=sync and MAIL_DRIVER=log

How can I test Mail::queue for Laravel?

1 Answers
Related