8000 bug #59252 [Stopwatch] bug #54854 undefined key error when trying to… · symfony/symfony@04aa652 · GitHub
[go: up one dir, main page]

Skip to content

Commit 04aa652

Browse files
committed
bug #59252 [Stopwatch] bug #54854 undefined key error when trying to fetch a mis… (Alex Niedre)
This PR was merged into the 7.2 branch. Discussion ---------- [Stopwatch] bug #54854 undefined key error when trying to fetch a mis… | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | yes | New feature? |no | Deprecations? |no | Issues | Fix #54854 | License | MIT A minor bug was introduced in the related referenced issue which caused an unidentified key exception to trigger when referencing a section that was missing. Reproduced here, as an example: https://3v4l.org/OFFLB This MR addresses that and adds a simple test to prevent the same mistake in the future. Commits ------- c3cf577 bug #54854 [Stopwatch] undefined key error when trying to fetch a missing section
2 parents 5280da9 + c3cf577 commit 04aa652

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)
0