From a030562071fb6d47386cff5ad49dfac2d0e0ce1b Mon Sep 17 00:00:00 2001 From: Yasen Pramatarov Date: Tue, 20 Jan 2026 23:38:49 +0200 Subject: [PATCH] Fixes tests --- tests/Feature/Middleware/RateLimitMiddlewareTest.php | 11 ++++++++++- tests/Unit/Classes/RateLimiterTest.php | 11 ++++++++++- tests/Unit/Classes/UserRegisterTest.php | 10 +++++++++- tests/Unit/Classes/UserTest.php | 10 +++++++++- 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/tests/Feature/Middleware/RateLimitMiddlewareTest.php b/tests/Feature/Middleware/RateLimitMiddlewareTest.php index d2deca8..fb06cea 100644 --- a/tests/Feature/Middleware/RateLimitMiddlewareTest.php +++ b/tests/Feature/Middleware/RateLimitMiddlewareTest.php @@ -1,11 +1,13 @@ $password ]); + // Set up App::db() for RateLimiter + App::set('db', $this->db->getConnection()); + // Create rate limiter instance - $this->rateLimiter = new RateLimiter($this->db); + $this->rateLimiter = new RateLimiter(); // Drop tables if they exist $this->db->getConnection()->exec("DROP TABLE IF EXISTS security_rate_auth"); @@ -119,6 +124,10 @@ class RateLimitMiddlewareTest extends TestCase $this->db->getConnection()->exec("TRUNCATE TABLE security_ip_whitelist"); $this->db->getConnection()->exec("TRUNCATE TABLE security_rate_auth"); $this->db->getConnection()->exec("TRUNCATE TABLE log"); + + // Clean up App state + App::reset('db'); + parent::tearDown(); } diff --git a/tests/Unit/Classes/RateLimiterTest.php b/tests/Unit/Classes/RateLimiterTest.php index df5994d..f2f1263 100644 --- a/tests/Unit/Classes/RateLimiterTest.php +++ b/tests/Unit/Classes/RateLimiterTest.php @@ -1,10 +1,12 @@ $password ]); + // Set up App::db() for RateLimiter + App::set('db', $this->db->getConnection()); + // The RateLimiter constructor will create all necessary tables - $this->rateLimiter = new RateLimiter($this->db); + $this->rateLimiter = new RateLimiter(); } protected function tearDown(): void @@ -40,6 +45,10 @@ class RateLimiterTest extends TestCase $this->db->getConnection()->exec("DROP TABLE IF EXISTS {$this->rateLimiter->pagesRatelimitTable}"); $this->db->getConnection()->exec("DROP TABLE IF EXISTS {$this->rateLimiter->blacklistTable}"); $this->db->getConnection()->exec("DROP TABLE IF EXISTS {$this->rateLimiter->whitelistTable}"); + + // Clean up App state + App::reset('db'); + parent::tearDown(); } diff --git a/tests/Unit/Classes/UserRegisterTest.php b/tests/Unit/Classes/UserRegisterTest.php index f27726b..3f1db59 100644 --- a/tests/Unit/Classes/UserRegisterTest.php +++ b/tests/Unit/Classes/UserRegisterTest.php @@ -1,11 +1,13 @@ $password ]); + // Set up App::db() for Register class to use + App::set('db', $this->db->getConnection()); + // Create user table with MariaDB syntax $this->db->getConnection()->exec(" CREATE TABLE IF NOT EXISTS user ( @@ -78,12 +83,15 @@ class UserRegisterTest extends TestCase ) "); - $this->register = new Register($this->db); + $this->register = new Register(); $this->user = new User($this->db); } protected function tearDown(): void { + // Clean up App state + App::reset('db'); + // Drop tables in correct order $this->db->getConnection()->exec("DROP TABLE IF EXISTS user_2fa"); $this->db->getConnection()->exec("DROP TABLE IF EXISTS security_rate_auth"); diff --git a/tests/Unit/Classes/UserTest.php b/tests/Unit/Classes/UserTest.php index 53fe6a6..ef74f2b 100644 --- a/tests/Unit/Classes/UserTest.php +++ b/tests/Unit/Classes/UserTest.php @@ -1,11 +1,13 @@ $password ]); + // Set up App::db() for Register class to use + App::set('db', $this->db->getConnection()); + // Create user table with MariaDB syntax $this->db->getConnection()->exec(" CREATE TABLE IF NOT EXISTS user ( @@ -79,11 +84,14 @@ class UserTest extends TestCase "); $this->user = new User($this->db); - $this->register = new Register($this->db); + $this->register = new Register(); } protected function tearDown(): void { + // Clean up App state + App::reset('db'); + // Drop tables in correct order $this->db->getConnection()->exec("DROP TABLE IF EXISTS user_2fa"); $this->db->getConnection()->exec("DROP TABLE IF EXISTS security_rate_auth");