Fixes session tests

main
Yasen Pramatarov 2025-04-12 16:48:53 +03:00
parent d28d69d350
commit f8118315e7
2 changed files with 7 additions and 6 deletions

View File

@ -60,10 +60,10 @@ function applySessionMiddleware($config, $app_root) {
* Helper function to clean up session data and redirect * Helper function to clean up session data and redirect
*/ */
function cleanupSession($config, $app_root, $isTest) { function cleanupSession($config, $app_root, $isTest) {
if (!$isTest) { // Always clear session data
// Clear session data
$_SESSION = array(); $_SESSION = array();
if (!$isTest) {
if (session_status() === PHP_SESSION_ACTIVE) { if (session_status() === PHP_SESSION_ACTIVE) {
session_unset(); session_unset();
session_destroy(); session_destroy();

View File

@ -8,6 +8,7 @@ class SessionMiddlewareTest extends TestCase
{ {
protected $config; protected $config;
protected $app_root; protected $app_root;
protected const SESSION_TIMEOUT = 7200; // 2 hours in seconds
protected function setUp(): void protected function setUp(): void
{ {
@ -52,7 +53,7 @@ class SessionMiddlewareTest extends TestCase
public function testSessionTimeout() 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); $result = applySessionMiddleware($this->config, $this->app_root);
@ -76,7 +77,7 @@ class SessionMiddlewareTest extends TestCase
public function testRememberMe() public function testRememberMe()
{ {
$_SESSION['REMEMBER_ME'] = true; $_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); $result = applySessionMiddleware($this->config, $this->app_root);
@ -95,7 +96,7 @@ class SessionMiddlewareTest extends TestCase
public function testSessionHeaders() 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); $result = applySessionMiddleware($this->config, $this->app_root);