Skip to content

Commit b8dac0c

Browse files
committed
fix(Debug): treat zero time as valid timer start
1 parent 404dcf5 commit b8dac0c

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

‎system/Debug/Timer.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class Timer
4646
public function start(string $name, ?float $time = null)
4747
{
4848
$this->timers[strtolower($name)] = [
49-
'start' => $time === null || $time === 0.0 ? microtime(true) : $time,
49+
'start' => $time ?? microtime(true),
5050
'end' => null,
5151
];
5252

‎tests/system/Debug/TimerTest.php‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,16 @@ public function testElapsedTimeGivesSameResultAsTimersArray(): void
8686
$this->assertSame($expected, $timer->getElapsedTime('test1'));
8787
}
8888

89+
public function testStartWithZeroTime(): void
90+
{
91+
$timer = new Timer();
92+
$timer->start('test1', 0.0);
93+
94+
$timers = $timer->getTimers();
95+
96+
$this->assertSame(0.0, $timers['test1']['start']);
97+
}
98+
8999
public function testThrowsExceptionStoppingNonTimer(): void
90100
{
91101
$this->expectException('RunTimeException');

0 commit comments

Comments
 (0)