Skip to content

Commit

Permalink
bug #54854 [Stopwatch] undefined key error when trying to fetch a mis…
Browse files Browse the repository at this point in the history
…sing section
  • Loading branch information
Alex Niedre committed Dec 18, 2024
1 parent 696f418 commit e46690d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Stopwatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() : [];
}

/**
Expand Down
5 changes: 5 additions & 0 deletions Tests/StopwatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,9 @@ public function testReset()

$this->assertEquals(new Stopwatch(), $stopwatch);
}

public function testShouldReturnEmptyArrayWhenSectionMissing()
{
$this->assertSame([], (new Stopwatch())->getSectionEvents('missing'));
}
}

0 comments on commit e46690d

Please sign in to comment.