I have this code
public function it_can_change_password()
{
DB::beginTransaction();
$payloadForUser = [
"name" => "Name",
"first_name" => $this->faker->firstName,
"last_name" => $this->faker->lastName,
"email" => $this->faker->unique()->safeEmail,
"role_id" => $this->faker->numberBetween(1, 5),
"branch_id" => 1,
"password" => bcrypt("password")
];
$user = User::create($payloadForUser);
$credentials = [
'email' => $user->email,
'password' => 'password',
'token_name' => 'admin',
'api_client' => true,
];
$loginResponse = $this->postJson('api/login', $credentials);
$loginResponse->assertStatus(200);
$data = $loginResponse->getData();
$this->token = $data->token;
$password = $this->faker->password;
$payload = [
'current_password' => "password", # Todo-139
'new_password' => $password,
'new_password_confirmation' => $password,
];
$response = $this->postJson('api/user/change/password', $payload, ['Authorization' => 'Bearer ' . $this->token]);
$response->assertOk();
$response = $this->postJson('api/logout', [], ['Authorization' => 'Bearer ' . $this->token]);
$response->assertServerError();
# Login using old password
$credentials = [
'email' => $user->email,
'password' => 'password',
'token_name' => 'admin',
'api_client' => true,
];
$loginResponse = $this->postJson('api/login', $credentials);
$response->assertServerError();
# Login using new password
$credentials = [
'email' => $user->email,
'password' => $password,
'token_name' => 'admin',
'api_client' => true,
];
$loginResponse = $this->postJson('api/login', $credentials);
$loginResponse->assertStatus(200);
DB::rollBack();
}
But I encountered error below when running php artisan test --filter=it_can_change_password
BadMethodCallException: Method Illuminate\Auth\RequestGuard::attempt does not exist. in /vendor/laravel/framework/src/Illuminate/Macroable/Traits/Macroable.php:113
on the last
$loginResponse = $this->postJson('api/login', $credentials);
$loginResponse->assertStatus(200);
Has anyone know how to mitigate this issue?