Mal*_*lio 2 testing notifications phpunit laravel
几天以来,我一直在努力让 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);
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试了几种想法,包括直接在使用列表中使用 Illuminate\Support\Testing\Fakes\NotificationFake 。在任何尝试中,测试都会失败
Error: Call to undefined method Illuminate\Notifications\Channels\MailChannel::assertSentTo()
Run Code Online (Sandbox Code Playgroud)
期待任何有助于成功测试的提示。问候并保重!
您似乎缺少一个Notification::fake(); 为了使用正确的假通知驱动程序。
Notification::fake();
$this->followingRedirects()
...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1109 次 |
| 最近记录: |