From c12fbf05e79f38125d36d3c20a13b23508c9c845 Mon Sep 17 00:00:00 2001 From: michalsn Date: Wed, 16 Jul 2025 19:11:30 +0200 Subject: [PATCH 1/3] test: set fixed time for time-dependent tests --- tests/Authentication/HasAccessTokensTest.php | 2 ++ tests/Authentication/HasHmacTokensTest.php | 2 ++ 2 files changed, 4 insertions(+) diff --git a/tests/Authentication/HasAccessTokensTest.php b/tests/Authentication/HasAccessTokensTest.php index d864860c0..910f0b99d 100644 --- a/tests/Authentication/HasAccessTokensTest.php +++ b/tests/Authentication/HasAccessTokensTest.php @@ -205,6 +205,8 @@ public function testIsTokenExpired(): void */ public function testTokenTimeToExpired(): void { + Time::setTestNow('2025-07-16 12:00:00'); + $tokenExpiration = Time::now()->addYears(1); $token = $this->user->generateAccessToken('foo', ['foo.bar'], $tokenExpiration); diff --git a/tests/Authentication/HasHmacTokensTest.php b/tests/Authentication/HasHmacTokensTest.php index 33909c1de..83a4fb813 100644 --- a/tests/Authentication/HasHmacTokensTest.php +++ b/tests/Authentication/HasHmacTokensTest.php @@ -214,6 +214,8 @@ public function testIsHmacTokenExpired(): void */ public function testHmacTokenTimeToExpired(): void { + Time::setTestNow('2025-07-16 12:00:00'); + $tokenExpiration = Time::now(); $tokenExpiration = $tokenExpiration->addYears(1); From 3849f9c6887f309c4f6d43390ec9e8088ebcb5ba Mon Sep 17 00:00:00 2001 From: michalsn Date: Wed, 16 Jul 2025 19:24:36 +0200 Subject: [PATCH 2/3] test: reset current time --- tests/Authentication/HasAccessTokensTest.php | 2 ++ tests/Authentication/HasHmacTokensTest.php | 2 ++ 2 files changed, 4 insertions(+) diff --git a/tests/Authentication/HasAccessTokensTest.php b/tests/Authentication/HasAccessTokensTest.php index 910f0b99d..fb1547306 100644 --- a/tests/Authentication/HasAccessTokensTest.php +++ b/tests/Authentication/HasAccessTokensTest.php @@ -213,6 +213,8 @@ public function testTokenTimeToExpired(): void $this->user->setAccessToken($token); $this->assertSame('in 1 year', $this->user->currentAccessToken()->expires->humanize()); + + Time::setTestNow(); } /** diff --git a/tests/Authentication/HasHmacTokensTest.php b/tests/Authentication/HasHmacTokensTest.php index 83a4fb813..e05715c76 100644 --- a/tests/Authentication/HasHmacTokensTest.php +++ b/tests/Authentication/HasHmacTokensTest.php @@ -222,6 +222,8 @@ public function testHmacTokenTimeToExpired(): void $token = $this->user->generateHmacToken('foo', ['foo.bar'], $tokenExpiration); $this->assertSame('in 1 year', $token->expires->humanize()); + + Time::setTestNow(); } /** From 121e6da5cc7dcd470947da0bd5e87aa39b86938d Mon Sep 17 00:00:00 2001 From: michalsn Date: Wed, 16 Jul 2025 19:26:09 +0200 Subject: [PATCH 3/3] test: reset time properly --- tests/Authentication/HasAccessTokensTest.php | 10 ++++++++-- tests/Authentication/HasHmacTokensTest.php | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/tests/Authentication/HasAccessTokensTest.php b/tests/Authentication/HasAccessTokensTest.php index fb1547306..0ca609f70 100644 --- a/tests/Authentication/HasAccessTokensTest.php +++ b/tests/Authentication/HasAccessTokensTest.php @@ -35,6 +35,14 @@ protected function setUp(): void $this->db->table($this->tables['identities'])->truncate(); } + protected function tearDown(): void + { + parent::tearDown(); + + // Reset the current time. + Time::setTestNow(); + } + public function testGenerateToken(): void { $token = $this->user->generateAccessToken('foo'); @@ -213,8 +221,6 @@ public function testTokenTimeToExpired(): void $this->user->setAccessToken($token); $this->assertSame('in 1 year', $this->user->currentAccessToken()->expires->humanize()); - - Time::setTestNow(); } /** diff --git a/tests/Authentication/HasHmacTokensTest.php b/tests/Authentication/HasHmacTokensTest.php index e05715c76..b7a64ff24 100644 --- a/tests/Authentication/HasHmacTokensTest.php +++ b/tests/Authentication/HasHmacTokensTest.php @@ -35,6 +35,14 @@ protected function setUp(): void $this->db->table($this->tables['identities'])->truncate(); } + protected function tearDown(): void + { + parent::tearDown(); + + // Reset the current time. + Time::setTestNow(); + } + public function testGenerateHmacToken(): void { $token = $this->user->generateHmacToken('foo'); @@ -222,8 +230,6 @@ public function testHmacTokenTimeToExpired(): void $token = $this->user->generateHmacToken('foo', ['foo.bar'], $tokenExpiration); $this->assertSame('in 1 year', $token->expires->humanize()); - - Time::setTestNow(); } /**