【问题标题】:Laravel 5.6 testing Notification::assertSentTo() not foundLaravel 5.6 测试 Notification::assertSentTo() 未找到
【发布时间】:2020-07-10 07:19:33
【问题描述】:

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

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()

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

【问题讨论】:

    标签: laravel testing notifications phpunit


    【解决方案1】:

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

    Notification::fake();
    
    $this->followingRedirects()
    ...
    

    【讨论】:

      猜你喜欢
      • 2018-12-16
      • 1970-01-01
      • 2016-03-16
      • 2018-12-09
      • 1970-01-01
      • 2018-08-05
      • 2019-07-18
      • 2017-06-08
      • 1970-01-01
      相关资源
      最近更新 更多