mirror of
https://github.com/php-flasher/php-flasher.git
synced 2026-03-31 15:07:47 +01:00
fix: make OctaneListener invokable for Laravel event dispatcher
Laravel's event dispatcher expects listener classes to be invokable (have __invoke method) when registered as a class name string. The OctaneListener was using a handle() method which caused the listener to never be invoked, resulting in notification state leaking between Octane requests. Renamed handle() to __invoke() to fix the issue.
This commit is contained in:
@@ -9,7 +9,7 @@ use Laravel\Octane\Events\RequestReceived;
|
||||
|
||||
final readonly class OctaneListener
|
||||
{
|
||||
public function handle(RequestReceived $event): void
|
||||
public function __invoke(RequestReceived $event): void
|
||||
{
|
||||
/** @var NotificationLoggerListener $listener */
|
||||
$listener = $event->sandbox->make('flasher.notification_logger_listener');
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Flasher\Tests\Laravel\EventListener;
|
||||
|
||||
use Flasher\Laravel\EventListener\OctaneListener;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class OctaneListenerTest extends TestCase
|
||||
{
|
||||
public function testListenerIsInvokable(): void
|
||||
{
|
||||
$listener = new OctaneListener();
|
||||
|
||||
// Verify the listener is invokable (has __invoke method)
|
||||
// This is crucial for Laravel's event dispatcher to call it correctly
|
||||
$this->assertTrue(is_callable($listener));
|
||||
}
|
||||
|
||||
public function testListenerHasInvokeMethod(): void
|
||||
{
|
||||
// Verify the __invoke method exists and has the correct signature
|
||||
$reflection = new \ReflectionClass(OctaneListener::class);
|
||||
|
||||
$this->assertTrue($reflection->hasMethod('__invoke'));
|
||||
|
||||
$method = $reflection->getMethod('__invoke');
|
||||
$this->assertTrue($method->isPublic());
|
||||
|
||||
$parameters = $method->getParameters();
|
||||
$this->assertCount(1, $parameters);
|
||||
$this->assertSame('event', $parameters[0]->getName());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user