Skip to content

Commit

Permalink
changed restart timing behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
ogmueller committed Mar 18, 2024
1 parent 1b2a94a commit 771dcf4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/TimingCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function start(string $name): void
{
$time = (float)$this->clock->now()->format('U.u');

// only start timing if it was not started yet
if (!isset($this->timing[$name])) {
$this->timing[$name] = [
'start' => $time,
Expand All @@ -58,9 +59,6 @@ public function start(string $name): void
'times' => 0,
];
}
} else {
$this->timing[$name]['start'] = $time;
$this->totalTiming[$name]['start'] = $time;
}
}

Expand Down
3 changes: 3 additions & 0 deletions test/StopwatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public function testStart(): void
self::assertEquals($totalTiming, $timing);
}

/**
* It is expected that the start time is not updated if the stopwatch is started twice without stopping it
*/
public function testUnstoppedRestart(): void
{
$name = self::faker()->word();
Expand Down

0 comments on commit 771dcf4

Please sign in to comment.