测试警报邮件TDD Laravel 7x

时间:2020-09-12 10:56:39

标签: laravel model-view-controller automated-tests phpunit tdd

以下我在 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

0 个答案:

没有答案