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 ); + } +}