4
我寫單元測試用於發送電子郵件的Mail ::隊列功能,如一個文檔中的代碼:https://laravel.com/docs/5.4/mocking#mail-fakeLaravel 5.4,郵件:: assertSent不工作
我的測試:
/** @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;
});
}
:被測試代碼:
Mail::to($email, $name)->queue(new ClientEmail(Auth::user()));
錯誤消息:
The expected [App\Mail\ClientEmail] mailable was not sent.
Failed asserting that false is true.
當我手動測試,但不會從單元測試中發送電子郵件。我想這可能是因爲我使用Mail::queue
而不是Mail::send
函數。
在.env
文件,我有
QUEUE_DRIVER=sync and MAIL_DRIVER=log
如何測試Mail::queue
爲Laravel?
您嘗試過'QUEUE_DRIVER =數據庫嗎?當我測試它時,這工作。 –
什麼是「批准者」屬性?看起來它是一個實體,你應該比較'approver-> id'而不是'approver'。 –
謝謝@ shukshin.ivan,我已修復它,它應該是審批者 - > ID。問題仍然存在。它仍然不認識到電子郵件已發送。 –