Skip to content

Commit c3cf577

Browse files
author
Alex Niedre
committed
bug symfony#54854 [Stopwatch] undefined key error when trying to fetch a missing section
1 parent 14bff67 commit c3cf577

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/Symfony/Component/Stopwatch/Stopwatch.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public function getEvent(string $name): StopwatchEvent
140140
*/
141141
public function getSectionEvents(string $id): array
142142
{
143-
return $this->sections[$id]->getEvents() ?? [];
143+
return isset($this->sections[$id]) ? $this->sections[$id]->getEvents() : [];
144144
}
145145

146146
/**

src/Symfony/Component/Stopwatch/Tests/StopwatchTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,9 @@ public function testReset()
187187

188188
$this->assertEquals(new Stopwatch(), $stopwatch);
189189
}
190+
191+
public function testShouldReturnEmptyArrayWhenSectionMissing()
192+
{
193+
$this->assertSame([], (new Stopwatch())->getSectionEvents('missing'));
194+
}
190195
}

0 commit comments

Comments
 (0)