且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Laravel 使用 phpunit + 多进程测试登录凭据

更新时间:2023-11-10 16:12:16

我也有点卡在 Laravel 5.4 测试跟随重定向案例.

I am also a bit stuck with Laravel 5.4 testing follow redirects case.

作为一种解决方法,您可以检查 $response->assertSessionHasErrors().这样它应该可以工作:

As a workaround, you may check $response->assertSessionHasErrors(). This way it should work:

public function testLoginFalse()
{
    $credential = [
        'email' => 'user@ad.com',
        'password' => 'incorrectpass'
    ];

    $response = $this->post('login',$credential);

    $response->assertSessionHasErrors();
}

另外,您可以在 testLoginTrue() 中检查该会话缺少错误:

Also, in testLoginTrue() you may check, that session missing errors:

$response = $this->post('login',$credential);
$response->assertSessionMissing('errors');

希望这会有所帮助!