diff --git a/tests/Utils/ExecutionTimeTest.php b/tests/Utils/ExecutionTimeTest.php new file mode 100644 index 00000000..19ed897f --- /dev/null +++ b/tests/Utils/ExecutionTimeTest.php @@ -0,0 +1,47 @@ +assertSame('', ob_get_contents()); + + unset($timer); // ...the report is emitted by __destruct() + + $output = ob_get_contents(); + } finally { + ob_end_clean(); + } + + $this->assertMatchesRegularExpression('/^Executed in [0-9.]+(?:E-?\d+)? seconds$/', $output); + } + + public function testMeasuredIntervalExceedsSleepDuration(): void + { + $sleepMicroseconds = 20000; // 20 ms + + ob_start(); + try { + $timer = new ExecutionTime(); + usleep($sleepMicroseconds); + unset($timer); + $output = ob_get_contents(); + } finally { + ob_end_clean(); + } + + $this->assertSame(1, preg_match('/Executed in ([0-9.]+(?:E-?\d+)?) seconds/', $output, $matches)); + $this->assertGreaterThanOrEqual($sleepMicroseconds / 1_000_000, (float) $matches[1]); + } +}