Level 70
@ismail_bourbie Yes, you can do that.
Try this:
/** @test */
public function session_is_regenerated_after_authentication()
{
$user = User::factory()->create([
'password' => bcrypt($password = 'i-love-laravel'),
]);
// Start a session
Session::start();
// Save the current session ID
$oldSessionId = Session::getId();
$response = $this->post('/login', [
'email' => $user->email,
'password' => $password,
]);
// Assert they're authenticated
$response->assertRedirect('/profile');
$this->assertAuthenticatedAs($user);
// Check that the session ID has changed
$this->assertNotEquals($oldSessionId, Session::getId());
}
1 like