gpt4 book ai didi

Laravel 5.6 测试Notification::assertSentTo() 未找到

转载 作者:行者123 更新时间:2023-12-02 02:56:50 26 4
gpt4 key购买 nike

几天以来,我一直在努力让Notification::assertSentTo()方法在Laravel 5.6应用程序中重置密码电子邮件的功能测试中发挥作用,但仍然收到以下代码的持续失败:

namespace Tests\Feature;

use Tests\TestCase;
use Illuminate\Auth\Notifications\ResetPassword;
use Illuminate\Support\Facades\Notification;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;

class UserPasswordResetTest extends TestCase
{
public function test_submit_password_reset_request()
{
$user = factory("App\User")->create();

$this->followingRedirects()
->from(route('password.request'))
->post(route('password.email'), [ "email" => $user->email ]);

Notification::assertSentTo($user, ResetPassword::class);
}

}

我尝试了几种想法,包括直接在使用列表中使用 Illuminate\Support\Testing\Fakes\NotificationFake 。在任何尝试中,测试都会失败

Error: Call to undefined method Illuminate\Notifications\Channels\MailChannel::assertSentTo()

期待任何有助于测试成功的提示。问候并保重!

最佳答案

您似乎缺少一个Notification::fake();为了使用正确的假通知驱动程序。

Notification::fake();

$this->followingRedirects()
...

关于Laravel 5.6 测试Notification::assertSentTo() 未找到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60921797/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com