从 5.7 版开始 Laravel 建议使用 array
测试期间邮件驱动程序:
不幸的是,the documentation对这个驱动程序一无所知。根据 the source code ,驱动程序将所有消息存储在内存中而不实际发送它们。如何在单元测试期间获取存储的“发送”消息(以检查它们)?
最佳答案
调用 app()->make('swift.transport')->driver()->messages()
.返回值是Swift_Mime_SimpleMessage
的集合对象。
一个完整的 PHPUnit 测试示例:
public function testEmail()
{
Mail::to('user@example.com')->send(new MyMail);
$emails = app()->make('swift.transport')->driver()->messages();
$this->assertCount(1, $emails);
$this->assertEquals(['user@example.com'], array_keys($emails[0]->getTo()));
}
关于php - 如何获取使用 `array` 邮件驱动程序发送的消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52176937/