조건이있는 로그인 테스트에 문제가있는 것 같습니다. 내 로그인 처리기는 이메일과 비밀번호가 유효 함을 확인하고 확인중인 사용자를 확인합니다. 다음 테스트 케이스 통과 :Auth :: 시도에서 일치하는 처리기가없는 Laravel unittest가 실패했습니다.
public function test_redirect_to_login_if_login_fails()
{
// enable filters to test login
Route::enableFilters();
// some fake credentials to use
$credentials = [
'email'=>'[email protected]',
'password'=>'badpassword',
'confirmed'=>1
];
// mock the Auth class
Auth::shouldReceive('attempt')
->once()
->with($credentials)
->andReturn(false);
// call the login post with the credentials
$this->call('POST','login',$credentials);
// assert that we are redirected back to the entry page
$this->assertRedirectedToRoute('entry');
}
public function test_redirect_if_login_success()
{
// enable filtere to test login
Route::enableFilters();
// some fake credentials to use
$credentials = [
'email'=>'[email protected]',
'password'=>'Pa55w0rd',
'confirmed'=>1
];
// mock the Auth class
Auth::shouldReceive('attempt')
->once()
->with($credentials)
->andReturn(true);
// call the login post with the proper credentials
$response = $this->call('POST','login',$credentials);
// assert the response is good
$this->assertTrue($response->isRedirection());
}
이 사람은 그러나, 나에게 오류를 제공 - 그것은 위의 첫 번째 테스트 케이스 매우 유사하지만 :
public function test_redirect_if_user_is_not_confirmed()
{
// enable filters to test login
Route::enableFilters();
// some fake credentials to use
$credentials = [
'email'=>'[email protected]',
'password'=>'badpassword',
'confirmed'=>0
];
// mock the Auth class
Auth::shouldReceive('attempt')
->once()
->with($credentials)
->andReturn(false);
// call the login post with the credentials
$this->call('POST','login',$credentials);
// assert that we are redirected back to the entry page
$this->assertRedirectedToRoute('entry');
}
오류 :
Mockery\Exception\NoMatchingExpecationException: No matching handler found for Mockery_0_Illumnate_Auth_AuthManager::attempt(array('email'=>'[email protected]','password'=>'badpassword','confirmed'=>1,)). Either the method was unexpected or its arguments matched no expected argument list for this method.
내 컨트롤러 방법 :
public function store()
{
if (Auth::attempt(array("email"=>Input::get('email'),"password"=>Input::get('password'),'confirmed'=>1)))
{
return Redirect::intended('home');
}
return Redirect::route("entry")->with("danger",Lang::get('orientation.invalid'))->withInput();
}
감사합니다. 'confirmed '는 입력 필드가 아닙니다. 정상적인 흐름은 사용자가 등록하고 이메일을 받으면 내 사용자 테이블에서 'confirm' 열을 0에서 1로 설정합니다. [Laravel docs] (http://laravel.com/docs/4.2/security#authenticating-users) (조건을 가진 사용자 인증 참조)에서 얻은 나의 이해는 확인 된 상태와 같은 다른 요구 사항을 설정해야하는 경우 , 이것은 그것이 어떻게 행해지는지입니다. 이것이 올바른 방법이 아니라면 적절한 방법을 알고 있습니까? – gin93r