diff --git a/src/Illuminate/Foundation/Events/DiscoverEvents.php b/src/Illuminate/Foundation/Events/DiscoverEvents.php index 36fb23e2151e..497a8afa0912 100644 --- a/src/Illuminate/Foundation/Events/DiscoverEvents.php +++ b/src/Illuminate/Foundation/Events/DiscoverEvents.php @@ -42,6 +42,10 @@ protected static function getListenerEvents($listeners, $basePath) static::classFromFile($listener, $basePath) ); + if (! $listener->isInstantiable()) { + continue; + } + foreach ($listener->getMethods(ReflectionMethod::IS_PUBLIC) as $method) { if (! Str::is('handle*', $method->name) || ! isset($method->getParameters()[0])) { diff --git a/tests/Integration/Foundation/DiscoverEventsTest.php b/tests/Integration/Foundation/DiscoverEventsTest.php index 3cd1b247745d..7dbaae1d4c2f 100644 --- a/tests/Integration/Foundation/DiscoverEventsTest.php +++ b/tests/Integration/Foundation/DiscoverEventsTest.php @@ -7,12 +7,16 @@ use Illuminate\Tests\Integration\Foundation\Fixtures\EventDiscovery\Events\EventOne; use Illuminate\Tests\Integration\Foundation\Fixtures\EventDiscovery\Events\EventTwo; use Illuminate\Tests\Integration\Foundation\Fixtures\EventDiscovery\Listeners\Listener; +use Illuminate\Tests\Integration\Foundation\Fixtures\EventDiscovery\Listeners\AbstractListener; +use Illuminate\Tests\Integration\Foundation\Fixtures\EventDiscovery\Listeners\ListenerInterface; class DiscoverEventsTest extends TestCase { public function test_events_can_be_discovered() { class_alias(Listener::class, 'Tests\Integration\Foundation\Fixtures\EventDiscovery\Listeners\Listener'); + class_alias(AbstractListener::class, 'Tests\Integration\Foundation\Fixtures\EventDiscovery\Listeners\AbstractListener'); + class_alias(ListenerInterface::class, 'Tests\Integration\Foundation\Fixtures\EventDiscovery\Listeners\ListenerInterface'); $events = DiscoverEvents::within(__DIR__.'/Fixtures/EventDiscovery/Listeners', getcwd()); diff --git a/tests/Integration/Foundation/Fixtures/EventDiscovery/Listeners/AbstractListener.php b/tests/Integration/Foundation/Fixtures/EventDiscovery/Listeners/AbstractListener.php new file mode 100644 index 000000000000..dc147a24f2c5 --- /dev/null +++ b/tests/Integration/Foundation/Fixtures/EventDiscovery/Listeners/AbstractListener.php @@ -0,0 +1,10 @@ +