diff --git a/src/TimingCollector.php b/src/TimingCollector.php index a6e4987..a1a58c5 100644 --- a/src/TimingCollector.php +++ b/src/TimingCollector.php @@ -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, @@ -58,9 +59,6 @@ public function start(string $name): void 'times' => 0, ]; } - } else { - $this->timing[$name]['start'] = $time; - $this->totalTiming[$name]['start'] = $time; } } diff --git a/test/StopwatchTest.php b/test/StopwatchTest.php index b708496..2309200 100644 --- a/test/StopwatchTest.php +++ b/test/StopwatchTest.php @@ -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();