【发布时间】:2021-07-30 18:28:04
【问题描述】:
我正在使用 laravel 8 和 Laravel Sail。
我正在尝试测试一封正在从工作中发送但未发送的电子邮件,无论我做什么。这是我的代码
Bus::fake();
Mail::fake();
TheProductDoesNotExists::dispatch($this->channel, $document['product'], $document['name']);
Event::assertDispatched(TheProductDoesNotExists::class);
Mail::assertSent(ProductMissing::class);
我得到了
The expected [App\Mail\ProductMissing] mailable was not sent.
Failed asserting that false is true.
在作业中,我什至在句柄方法中有一个记录器,但没有记录任何内容
public function handle()
{
logger('from the job');
$alertTo = 'test@test';
Mail::to($alertTo)->send(
new ProductMissing($this->product, $this->orderName)
);
}
什么都没有。任何帮助将非常感激!谢谢
【问题讨论】:
-
您的问题是您混淆了事物,如果您伪造
Event总线,那么您将不会执行该事件...您在那里混合了 2 个测试,一个测试事件被分派,其他测试断言邮件已发送。
标签: php laravel testing phpunit