测试警报邮件TDD Laravel 7x

问题描述

以下我在 tests / Feature / emailPollTest.PHP

中编写了以下测试
...
....
Mail::fake();
$ja=["id"=>1,'status'=>'error','log'=>'log test'];
$response = $this->post('/api/store',$data);
$response ->assertStatus(201);
$response->assertJson($ja);
$order = new NotifyPoll($ja);
Mail::assertSent(function (NotifyPoll $mail) use ($order) {
    $count = 0;
    if($mail->itemPoll['id'] === $order->itemPoll['id']) $count++;
    if($mail->itemPoll['status'] === $order->itemPoll['status']) $count++;
    if($mail->itemPoll['log'] === $order->itemPoll['log']) $count++;
    return 3 === $count;
});
Mail::assertSent(NotifyPoll::class,1);

可以将其视为功能测试或单元测试吗?

测试警报邮件是否有效?

我正在测试警报邮件的API如下:

public function store(Request $request)
    {
        $poll = request->all();
        if($poll['status']=='b')
        {
            Mail::to('example@....com')->send(new NotifyPoll($poll));
        }
        return response()->json(Poll::create($poll),201);
    }

启动电子邮件方法是存储,每次调用电子邮件时,它实际上都会启动,但是我只想模拟 s

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)