Skip to content

Commit

Permalink
fix(Testing): Fix assert listener when closure listener is registered
Browse files Browse the repository at this point in the history
  • Loading branch information
pionl committed Nov 11, 2023
1 parent fde2ea1 commit 942323d
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/Testing/Concerns/AssertEventListeners.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,20 @@ public function assertEventListeners(
* The goal is to prevent other listeners from being called, so we will remove all listeners for the event and
* validate if the desired listeners were registered. Then we will re-register the listener we want and call the
* event again to validate the results.
*
* @var Dispatcher $events
*/
$events = $app->make(Dispatcher::class);
$currentListenersMap = array_flip($events->getRawListeners()[$event::class] ?? []);
assert($events instanceof Dispatcher);

$rawListeners = $events->getRawListeners()[$event::class] ?? [];

// Closures are not support, we cant use array_flip
$currentListenersMap = [];
foreach ($rawListeners as $listener) {
if (is_string($listener)) {
$currentListenersMap[$listener] = true;
}
}

$events->forget($event::class);

foreach ($contractMap as $contract => $assert) {
Expand Down

0 comments on commit 942323d

Please sign in to comment.