Я хотел бы проверить случай, когда пользователь отмечен как неактивный в БД, вот метод в LoginController
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = '/';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware(['guest'])->except('logout'); //, 'checkup'
}
/**
* The user has been authenticated.
*
* @param \Illuminate\Http\Request $request
* @param mixed $user
* @return mixed
*/
protected function authenticated(Request $request, $user)
{
if ($user->roles->count() === 0 ) {
$this->guard()->logout();
flash('There is no role specified please contact the system Administrator!')->error();
return back()->withErrors(['There is no role specified']);
}
}
/**
* @param Request $request
* @return array
*/
protected function credentials(Request $request)
{
$credentials = $request->only($this->username(), 'password');
$credentials['status'] = "A";
return $credentials;
}
}
, поэтому я создаю поддельного пользователя и использую следующий тест, чтобы покрытьcase
$this->faker = Faker::create();
$password = $this->faker->password;
$user = factory(User::class)->create([
'username' => $this->faker->username,
'firstname' => $this->faker->firstName,
'lastname' => $this->faker->lastName,
'status'=> 'I',
'password' => bcrypt($password),
'email' => $this->faker->email
]);
$response = $this->call('POST', '/login', [
'email' => $user->email,
'password' =>$password,
'_token' => csrf_token()
]);
$response->assertRedirect('/login');
но пользователь каждый раз входит в систему.
тестирование одного и того же случая с сумраком laravel, пройдет нормально
public function testNotActiveUserLogin()
{
$faker = Faker\Factory::create();
$password = $faker->password;
$user = factory(User::class)->create([
'username' => $faker->username,
'firstname' => $faker->firstName,
'lastname' => $faker->lastName,
'status' => 'I',
'password' => bcrypt($password),
'email' => $faker->email
]);
$this->browse(function (Browser $browser) use ($user, $password) {
$browser->visit('/')
->type('email', $user->email)
->type('password', $password)
->press('Sign In')
->assertPathIs('/login');
});
}
Что я пропускаю вэто дело?