laravel 5中登录验证phpunit测试用例的步骤是什么?
$credentials=[
'email'=>'admin@admin.com',
'password'=>'admin'
];
$response=$this->call('POST','login',$credentials);
$this->assertTrue($response->isOk());
答案 0 :(得分:0)
这只会检查用户是否存在并且能够登录,但是我不明白为什么我们需要这个测试:
$this->assertTrue(Auth::attempt(['email' => $email, 'password' => $password]));
对于单元测试用例,以下测试可能更好。如果登录失败/成功,您需要检查路由的重定向是否正常。我把你的代码写成:
$credentials=[
'email'=>'admin@admin.com',
'password'=>'admin'
];
$this->call('POST','login',$credentials);
$this->assertResponseOk();
//or $this->assertRedirectedToRoute('login.fail');