From e46690d5b9d7164a6d061cab1e8d46141b9f49df Mon Sep 17 00:00:00 2001 From: Alex Niedre Date: Wed, 18 Dec 2024 15:16:32 +0100 Subject: [PATCH] bug #54854 [Stopwatch] undefined key error when trying to fetch a missing section --- Stopwatch.php | 2 +- Tests/StopwatchTest.php | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Stopwatch.php b/Stopwatch.php index 50ac657..8961507 100644 --- a/Stopwatch.php +++ b/Stopwatch.php @@ -140,7 +140,7 @@ public function getEvent(string $name): StopwatchEvent */ public function getSectionEvents(string $id): array { - return $this->sections[$id]->getEvents() ?? []; + return isset($this->sections[$id]) ? $this->sections[$id]->getEvents() : []; } /** diff --git a/Tests/StopwatchTest.php b/Tests/StopwatchTest.php index f1e2270..f9b532e 100644 --- a/Tests/StopwatchTest.php +++ b/Tests/StopwatchTest.php @@ -187,4 +187,9 @@ public function testReset() $this->assertEquals(new Stopwatch(), $stopwatch); } + + public function testShouldReturnEmptyArrayWhenSectionMissing() + { + $this->assertSame([], (new Stopwatch())->getSectionEvents('missing')); + } }