| 
									
										
										
										
											2025-02-18 14:36:31 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | require_once __DIR__ . '/vendor/autoload.php'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class TestCase extends PHPUnit\Framework\TestCase | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     protected function setUp(): void | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         parent::setUp(); | 
					
						
							| 
									
										
										
										
											2025-02-19 13:31:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-18 14:36:31 +00:00
										 |  |  |         // Set up test environment
 | 
					
						
							|  |  |  |         $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; | 
					
						
							|  |  |  |         $_SERVER['HTTP_USER_AGENT'] = 'PHPUnit Test Browser'; | 
					
						
							| 
									
										
										
										
											2025-02-19 13:31:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-03 19:43:47 +00:00
										 |  |  |         // Include common app files (if there are any, we don't have for now)
 | 
					
						
							|  |  |  |         //require_once dirname(__DIR__, 2) . '/app/includes/config.php';
 | 
					
						
							| 
									
										
										
										
											2025-02-19 13:31:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-18 14:36:31 +00:00
										 |  |  |         // Clean up any existing session
 | 
					
						
							|  |  |  |         if (session_status() === PHP_SESSION_ACTIVE) { | 
					
						
							|  |  |  |             session_destroy(); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-02-19 13:31:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-18 14:36:31 +00:00
										 |  |  |         // Reset session data
 | 
					
						
							|  |  |  |         $_SESSION = []; | 
					
						
							| 
									
										
										
										
											2025-02-19 13:31:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-18 14:36:31 +00:00
										 |  |  |         // Only start session if headers haven't been sent
 | 
					
						
							|  |  |  |         if (!headers_sent() && session_status() === PHP_SESSION_NONE) { | 
					
						
							|  |  |  |             session_start(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     protected function tearDown(): void | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // Clean up session after each test
 | 
					
						
							|  |  |  |         if (session_status() === PHP_SESSION_ACTIVE) { | 
					
						
							|  |  |  |             $_SESSION = []; | 
					
						
							|  |  |  |             session_destroy(); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-02-19 13:31:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-18 14:36:31 +00:00
										 |  |  |         parent::tearDown(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Helper method to start a new session if needed | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     protected function ensureSession(): void | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if (session_status() === PHP_SESSION_NONE && !headers_sent()) { | 
					
						
							|  |  |  |             session_start(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     protected function captureHeaders(): array | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $headers = []; | 
					
						
							|  |  |  |         $callback = function($header) use (&$headers) { | 
					
						
							|  |  |  |             $headers[] = $header; | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Mock header function
 | 
					
						
							|  |  |  |         if (!function_exists('header')) { | 
					
						
							|  |  |  |             eval('function header($header) use ($callback) { $callback($header); }'); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $headers; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |