diff --git a/src/Illuminate/Support/Testing/Fakes/EventFake.php b/src/Illuminate/Support/Testing/Fakes/EventFake.php index f1e465515e77..ec795b3f1714 100644 --- a/src/Illuminate/Support/Testing/Fakes/EventFake.php +++ b/src/Illuminate/Support/Testing/Fakes/EventFake.php @@ -94,7 +94,10 @@ public function assertListening($expectedEvent, $expectedListener) if (Str::contains($expectedListener, '@')) { $normalizedListener = Str::parseCallback($expectedListener); } else { - $normalizedListener = [$expectedListener, 'handle']; + $normalizedListener = [ + $expectedListener, + ! method_exists($expectedListener, 'handle') ? '__invoke' : 'handle', + ]; } } } diff --git a/tests/Integration/Events/EventFakeTest.php b/tests/Integration/Events/EventFakeTest.php index 59d70986d5e7..7b7e06a5dda6 100644 --- a/tests/Integration/Events/EventFakeTest.php +++ b/tests/Integration/Events/EventFakeTest.php @@ -147,6 +147,7 @@ public function testAssertListening() 'Illuminate\\Tests\\Integration\\Events\\PostAutoEventSubscriber@handle', PostEventSubscriber::class, [PostEventSubscriber::class, 'foo'], + InvokableEventSubscriber::class, ]); foreach ($listenersOfSameEventInRandomOrder as $listener) { @@ -172,6 +173,7 @@ public function testAssertListening() Event::assertListening(NonImportantEvent::class, Closure::class); Event::assertListening('eloquent.saving: '.Post::class, PostObserver::class.'@saving'); Event::assertListening('eloquent.saving: '.Post::class, [PostObserver::class, 'saving']); + Event::assertListening('event', InvokableEventSubscriber::class); } } @@ -231,3 +233,11 @@ public function saving(Post $post) $post->slug = sprintf('%s-Test', $post->title); } } + +class InvokableEventSubscriber +{ + public function __invoke($event) + { + // + } +}