Кажется, у меня возникла проблема с моим тестом входа в систему с условиями. Мой обработчик входа проверяет правильность адреса электронной почты и пароля, а также подтверждение пользователя. Проходят следующие тестовые случаи:
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: не найден соответствующий обработчик для Mockery_0_Illumnate_Auth_AuthManager::attempt(array('email'=>'[email protected]','password'=>'badpassword','confirmed'=>1,)). Либо метод был неожиданным, либо его аргументы не соответствовали ожидаемому списку аргументов для этого метода.
Мой метод контроллера:
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();
}