From f8118315e700099f1def33e46fb8b1daa7b9da8f Mon Sep 17 00:00:00 2001 From: Yasen Pramatarov Date: Sat, 12 Apr 2025 16:48:53 +0300 Subject: [PATCH] Fixes session tests --- app/includes/session_middleware.php | 6 +++--- tests/Feature/Middleware/SessionMiddlewareTest.php | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app/includes/session_middleware.php b/app/includes/session_middleware.php index c5d52a5..339484a 100644 --- a/app/includes/session_middleware.php +++ b/app/includes/session_middleware.php @@ -60,10 +60,10 @@ function applySessionMiddleware($config, $app_root) { * Helper function to clean up session data and redirect */ function cleanupSession($config, $app_root, $isTest) { - if (!$isTest) { - // Clear session data - $_SESSION = array(); + // Always clear session data + $_SESSION = array(); + if (!$isTest) { if (session_status() === PHP_SESSION_ACTIVE) { session_unset(); session_destroy(); diff --git a/tests/Feature/Middleware/SessionMiddlewareTest.php b/tests/Feature/Middleware/SessionMiddlewareTest.php index cf472eb..ce22a00 100644 --- a/tests/Feature/Middleware/SessionMiddlewareTest.php +++ b/tests/Feature/Middleware/SessionMiddlewareTest.php @@ -8,6 +8,7 @@ class SessionMiddlewareTest extends TestCase { protected $config; protected $app_root; + protected const SESSION_TIMEOUT = 7200; // 2 hours in seconds protected function setUp(): void { @@ -52,7 +53,7 @@ class SessionMiddlewareTest extends TestCase public function testSessionTimeout() { - $_SESSION['LAST_ACTIVITY'] = time() - 1500; // 25 minutes ago + $_SESSION['LAST_ACTIVITY'] = time() - (self::SESSION_TIMEOUT + 60); // 2 hours + 1 minute ago $result = applySessionMiddleware($this->config, $this->app_root); @@ -76,7 +77,7 @@ class SessionMiddlewareTest extends TestCase public function testRememberMe() { $_SESSION['REMEMBER_ME'] = true; - $_SESSION['LAST_ACTIVITY'] = time() - 86500; // More than 24 hours ago + $_SESSION['LAST_ACTIVITY'] = time() - (self::SESSION_TIMEOUT + 60); // More than 2 hours ago $result = applySessionMiddleware($this->config, $this->app_root); @@ -95,7 +96,7 @@ class SessionMiddlewareTest extends TestCase public function testSessionHeaders() { - $_SESSION['LAST_ACTIVITY'] = time() - 1500; // 25 minutes ago + $_SESSION['LAST_ACTIVITY'] = time() - (self::SESSION_TIMEOUT + 60); // 2 hours + 1 minute ago $result = applySessionMiddleware($this->config, $this->app_root);