Skip to content

Commit

Permalink
Failsafe for unknown event (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
malarzm committed Oct 12, 2022
1 parent ac23597 commit 95aa4cb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/EventManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function getListeners($event = null)
return $this->getAllListeners();
}

return $this->listeners[$event];
return $this->listeners[$event] ?? [];
}

/**
Expand Down
5 changes: 5 additions & 0 deletions tests/EventManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ public function testNoDispatchingForUnregisteredEvent(): void
self::assertNull($reflection->getValue(null));
}

public function testEmptyListenersListForUnregisteredEvent(): void
{
self::assertSame([], $this->_eventManager->getListeners('unknown'));
}

/* Listener methods */

public function preFoo(EventArgs $e): void
Expand Down

0 comments on commit 95aa4cb

Please sign in to comment.