Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Can';在laravel中测试身份验证时无法获取用户_Laravel_Authentication_Automated Tests_Phpunit - Fatal编程技术网

Can';在laravel中测试身份验证时无法获取用户

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(

我正在为一个遗留的laravel项目5.8.38编写自动测试。 我有这个测试方法

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这并没有解决我的问题,但似乎是一个真正有用的补充,谢谢。