8000 [12.x] Queue event listeners with enum values by wgriffioen · Pull Request #55656 · laravel/framework · GitHub
[go: up one dir, main page]

Skip to content

[12.x] Queue event listeners with enum values #55656

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 7, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Queue event listeners with enum values
  • Loading branch information
wgriffioen committed May 6, 2025
commit fed0bff106f4b5937ef880fee24a35083ec4913b
5 changes: 3 additions & 2 deletions src/Illuminate/Events/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Illuminate\Support\Traits\Macroable;
use Illuminate\Support\Traits\ReflectsClosures;
use ReflectionClass;
use function Illuminate\Support\enum_value;

class Dispatcher implements DispatcherContract
{
Expand Down Expand Up @@ -631,8 +632,8 @@ protected function queueHandler($class, $method, $arguments)
: $listener->delay ?? null;

is_null($delay)
? $connection->pushOn($queue, $job)
: $connection->laterOn($queue, $delay, $job);
? $connection->pushOn(enum_value($queue), $job)
: $connection->laterOn(enum_value($queue), $delay, $job);
}

/**
Expand Down
31 changes: 31 additions & 0 deletions tests/Events/QueuedEventsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Illuminate\Events\Dispatcher;
use Illuminate\Queue\QueueManager;
use Illuminate\Support\Testing\Fakes\QueueFake;
use Illuminate\Tests\Integration\Console\Events\ExampleQueueListener;
use Mockery as m;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -199,6 +200,23 @@ public function testQueuePropagateMiddleware()
&& $job->middleware[0]->b === 'bar';
});
}

public function testDispatchesOnQueueDefinedWithEnum()
{
$d = new Dispatcher;
$queue = m::mock(Queue::class);

$fakeQueue = new QueueFake(new Container);

$d->setQueueResolver(function () use ($fakeQueue) {
return $fakeQueue;
});

$d->listen('some.event', TestDispatcherViaQueueSupportsEnum::class.'@handle');
$d->dispatch('some.event', ['foo', 'bar']);

$fakeQueue->assertPushedOn('enumerated-queue', CallQueuedListener::class);
}
}

class TestDispatcherQueuedHandler implements ShouldQueue
Expand Down Expand Up @@ -367,3 +385,16 @@ public function withDelay($event)
return 20;
}
}

enum TestQueueType: string
{
case EnumeratedQueue = 'enumerated-queue';
}

class TestDispatcherViaQueueSupportsEnum implements ShouldQueue
{
public function viaQueue()
{
return TestQueueType::EnumeratedQueue;
}
}
0