phpunit laravel中登录验证测试用例的步骤

时间:2016-09-20 08:15:46

标签: phpunit laravel-5.1

laravel 5中登录验证phpunit测试用例的步骤是什么?

$credentials=[
  'email'=>'admin@admin.com',
  'password'=>'admin'
];
$response=$this->call('POST','login',$credentials);
$this->assertTrue($response->isOk());

1 个答案:

答案 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');