Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

BernardoBF4's avatar

Testing session expiration date

I am trying to test if a user gets logged out after 2 hours logged in. There are two problem with this: 1) I can't test it properly becuase I don't actually know how to do this. I thought taht by using the time travel I'd be able to do this, but apparently not (test bellow); and 2) when I check the cookie that keeps the session of my user, it is using UTC and not UCT-3 (Brazil/São Paulo) and have not been able to find how to change this.

Can someone help, please.

/** @test */
  public function a_user_get_logged_out_after_two_hours()
  {
    $this->withoutExceptionHandling();

    $user = User::factory()->withPassword(Str::random(10))->create();
    
    auth()->login($user);
    $this->travel(120)->minutes();
  }
0 likes
2 replies
AngelinCalu's avatar

in config/app.php you should have a key named timezone which will allow you to update your timezone settings. It indeed defaults to UTC.

The default session settings can be updated in config/session.php under lifetime key.

Adding a SESSION_LIFETIME key-value pair to your .env file would overwrite that setting.

1 like

Please or to participate in this conversation.