我试图对我的身份验证路线进行测试。对于密码重置路线,我试图在其中伪造 laravel 的通知模块并根据文档进行断言。 这是我的测试文件
public function testUserReceivesAnEmailWithAPasswordResetLink()
{
$this->withoutExceptionHandling();
Notification::fake();
$user = factory(User::class)->make();
$response = $this->post($this->passwordEmailPostRoute(), [
'email' => $user->email,
]);
$this->assertNotNull($token = DB::table('password_resets')->where('email', $user->email));
Notification::assertSentTo($user, PasswordReset::class);
}
当我运行此程序时,我收到
notification was not sent
错误。
我的用户模型是这样的:
use Notifiable, HasApiTokens, SoftDeletes, Uuidable, Switchable, ResourceMapper;
public function role()
{
return $this->belongsTo('App\Models\Role');
}
public function company()
{
return $this->belongsTo('App\Models\Company');
}
public function AauthAccessToken()
{
return $this->hasMany('App\Models\OauthAccessToken');
}
public function isRole($role)
{
return $this->role->uuid == $role;
}
public function sendPasswordResetNotification($token)
{
$this->notify(new PasswordReset($token));
}
public function resource()
{
return $this->morphTo();
}
我不知道到底是什么问题。
由于您要在
sendPasswordResetNotification
模型中覆盖 User
,请确保 User.php
和 test
文件使用相同的 PasswordReset
类。