From fdf665a84adb18024af3747de447854b66d6404d Mon Sep 17 00:00:00 2001 From: Shail Mehta Date: Mon, 19 Oct 2026 14:38:44 +0530 Subject: [PATCH 1/4] Tests: Add unit tests for `timer_float()` --- tests/phpunit/tests/load/load/timerFloat.php | 59 ++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 tests/phpunit/tests/load/load/timerFloat.php diff --git a/tests/phpunit/tests/load/load/timerFloat.php b/tests/phpunit/tests/load/load/timerFloat.php new file mode 100644 index 0000000000000..05f75ca98b4cc --- /dev/null +++ b/tests/phpunit/tests/load/load/timerFloat.php @@ -0,0 +1,59 @@ +original_request_time_float = $_SERVER['REQUEST_TIME_FLOAT'] ?? null; + } + + public function tear_down() { + if ( null !== $this->original_request_time_float ) { + $_SERVER['REQUEST_TIME_FLOAT'] = $this->original_request_time_float; + } else { + unset( $_SERVER['REQUEST_TIME_FLOAT'] ); + } + + parent::tear_down(); + } + + /** + * @ticket 65819 + */ + public function test_returns_elapsed_seconds_as_float() { + $_SERVER['REQUEST_TIME_FLOAT'] = microtime( true ) - 1.25; + + $result = timer_float(); + + $this->assertIsFloat( $result ); + $this->assertGreaterThanOrEqual( 1.25, $result ); + } + + /** + * @ticket 65819 + */ + public function test_elapsed_time_increases() { + $_SERVER['REQUEST_TIME_FLOAT'] = microtime( true ); + + $first = timer_float(); + usleep( 10000 ); // 10ms. + $second = timer_float(); + + $this->assertGreaterThan( $first, $second ); + } +} From 2438375aae4932396627ff09da479235f2a4c2db Mon Sep 17 00:00:00 2001 From: Shail Mehta Date: Mon, 19 Oct 2026 14:46:49 +0530 Subject: [PATCH 2/4] Add assertion for timerFloat result upper limit Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- tests/phpunit/tests/load/load/timerFloat.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/phpunit/tests/load/load/timerFloat.php b/tests/phpunit/tests/load/load/timerFloat.php index 05f75ca98b4cc..2e684589acc65 100644 --- a/tests/phpunit/tests/load/load/timerFloat.php +++ b/tests/phpunit/tests/load/load/timerFloat.php @@ -42,6 +42,7 @@ public function test_returns_elapsed_seconds_as_float() { $this->assertIsFloat( $result ); $this->assertGreaterThanOrEqual( 1.25, $result ); + $this->assertLessThanOrEqual( microtime( true ) - $_SERVER['REQUEST_TIME_FLOAT'], $result ); } /** From c63b8780ccecb31c1baaa30c54ee3d5f0dcb40d1 Mon Sep 17 00:00:00 2001 From: Shail Mehta Date: Mon, 19 Oct 2026 16:50:43 +0530 Subject: [PATCH 3/4] Create timerFloat.php --- tests/phpunit/tests/load/timerFloat.php | 60 +++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 tests/phpunit/tests/load/timerFloat.php diff --git a/tests/phpunit/tests/load/timerFloat.php b/tests/phpunit/tests/load/timerFloat.php new file mode 100644 index 0000000000000..2e684589acc65 --- /dev/null +++ b/tests/phpunit/tests/load/timerFloat.php @@ -0,0 +1,60 @@ +original_request_time_float = $_SERVER['REQUEST_TIME_FLOAT'] ?? null; + } + + public function tear_down() { + if ( null !== $this->original_request_time_float ) { + $_SERVER['REQUEST_TIME_FLOAT'] = $this->original_request_time_float; + } else { + unset( $_SERVER['REQUEST_TIME_FLOAT'] ); + } + + parent::tear_down(); + } + + /** + * @ticket 65819 + */ + public function test_returns_elapsed_seconds_as_float() { + $_SERVER['REQUEST_TIME_FLOAT'] = microtime( true ) - 1.25; + + $result = timer_float(); + + $this->assertIsFloat( $result ); + $this->assertGreaterThanOrEqual( 1.25, $result ); + $this->assertLessThanOrEqual( microtime( true ) - $_SERVER['REQUEST_TIME_FLOAT'], $result ); + } + + /** + * @ticket 65819 + */ + public function test_elapsed_time_increases() { + $_SERVER['REQUEST_TIME_FLOAT'] = microtime( true ); + + $first = timer_float(); + usleep( 10000 ); // 10ms. + $second = timer_float(); + + $this->assertGreaterThan( $first, $second ); + } +} From c1bea9491c6dcb636cbe33c77b3d337143dfcc29 Mon Sep 17 00:00:00 2001 From: Shail Mehta Date: Mon, 19 Oct 2026 16:50:58 +0530 Subject: [PATCH 4/4] Delete tests/phpunit/tests/load/load directory --- tests/phpunit/tests/load/load/timerFloat.php | 60 -------------------- 1 file changed, 60 deletions(-) delete mode 100644 tests/phpunit/tests/load/load/timerFloat.php diff --git a/tests/phpunit/tests/load/load/timerFloat.php b/tests/phpunit/tests/load/load/timerFloat.php deleted file mode 100644 index 2e684589acc65..0000000000000 --- a/tests/phpunit/tests/load/load/timerFloat.php +++ /dev/null @@ -1,60 +0,0 @@ -original_request_time_float = $_SERVER['REQUEST_TIME_FLOAT'] ?? null; - } - - public function tear_down() { - if ( null !== $this->original_request_time_float ) { - $_SERVER['REQUEST_TIME_FLOAT'] = $this->original_request_time_float; - } else { - unset( $_SERVER['REQUEST_TIME_FLOAT'] ); - } - - parent::tear_down(); - } - - /** - * @ticket 65819 - */ - public function test_returns_elapsed_seconds_as_float() { - $_SERVER['REQUEST_TIME_FLOAT'] = microtime( true ) - 1.25; - - $result = timer_float(); - - $this->assertIsFloat( $result ); - $this->assertGreaterThanOrEqual( 1.25, $result ); - $this->assertLessThanOrEqual( microtime( true ) - $_SERVER['REQUEST_TIME_FLOAT'], $result ); - } - - /** - * @ticket 65819 - */ - public function test_elapsed_time_increases() { - $_SERVER['REQUEST_TIME_FLOAT'] = microtime( true ); - - $first = timer_float(); - usleep( 10000 ); // 10ms. - $second = timer_float(); - - $this->assertGreaterThan( $first, $second ); - } -}