Can';在laravel中测试身份验证时无法获取用户
我正在为一个遗留的laravel项目5.8.38编写自动测试。 我有这个测试方法Can';在laravel中测试身份验证时无法获取用户,laravel,authentication,automated-tests,phpunit,Laravel,Authentication,Automated Tests,Phpunit,我正在为一个遗留的laravel项目5.8.38编写自动测试。 我有这个测试方法 public function testUserReceivesAnEmailWithAPasswordResetLink() { Notification::fake(); $user = factory(User::class)->create([ 'email' => 'john@example.com', ]); $this->post(
public function testUserReceivesAnEmailWithAPasswordResetLink()
{
Notification::fake();
$user = factory(User::class)->create([
'email' => 'john@example.com',
]);
$this->post($this->passwordEmailPostRoute(), [
'email' => 'john@example.com',
]);
$this->assertNull($token = DB::table('password_resets')->first());
Notification::assertSentTo($user, ResetPassword::class, function ($notification, $channels) use ($token) {
return Hash::check($notification->token, $token->token) === true;
});
}
这总是失败,因为无法检索用户。passwordEmailPostRoute()
方法转到src/illighte/Auth/Passwords/PasswordBroker.php sendResetLink()
方法,最终在src/illighte/Auth/EloquentUserProvider.php
的retrieveByCredentials()
方法中结束。
这总是返回null
我试图转储数据和查询,但一切都失败了。任何想法都值得赞赏。这似乎是我为自己造成的一个非常具体的问题。
“我的用户工厂”为变形连接字段生成了错误的值,从而阻止了有效用户对象的返回。我不得不更改工厂,现在问题已经解决。尝试使用:$this->actingAs($user,'api');在$this之前->post@OMR这并没有解决我的问题,但似乎是一个真正有用的补充,谢谢。