Skip to content
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

Ensure queue property is nullable #55058

Merged
merged 1 commit into from
Mar 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/Illuminate/Queue/Events/JobQueued.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class JobQueued
* Create a new event instance.
*
* @param string $connectionName The connection name.
* @param string $queue The queue name.
* @param string|null $queue The queue name.
* @param string|int|null $id The job ID.
* @param \Closure|string|object $job The job instance.
* @param string $payload The job payload.
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Queue/Events/JobQueueing.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class JobQueueing
* Create a new event instance.
*
* @param string $connectionName The connection name.
* @param string $queue The queue name.
* @param string|null $queue The queue name.
* @param \Closure|string|object $job The job instance.
* @param string $payload The job payload.
* @param int|null $delay The number of seconds the job was delayed.
Expand Down
35 changes: 35 additions & 0 deletions tests/Integration/Queue/JobDispatchingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\Events\JobQueued;
use Illuminate\Queue\Events\JobQueueing;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Config;
use Orchestra\Testbench\Attributes\WithMigration;

#[WithMigration]
Expand Down Expand Up @@ -135,6 +138,33 @@ public function testUniqueJobLockIsReleasedForJobDispatchedAfterResponse()
$this->assertFalse(UniqueJob::$ran);
}

public function testQueueMayBeNullForJobQueueingAndJobQueuedEvent()
{
Config::set('queue.default', 'database');
$events = [];
$this->app['events']->listen(function (JobQueueing $e) use (&$events) {
$events[] = $e;
});
$this->app['events']->listen(function (JobQueued $e) use (&$events) {
$events[] = $e;
});

MyTestDispatchableJob::dispatch();
dispatch(function () {
//
});

$this->assertCount(4, $events);
$this->assertInstanceOf(JobQueueing::class, $events[0]);
$this->assertNull($events[0]->queue);
$this->assertInstanceOf(JobQueued::class, $events[1]);
$this->assertNull($events[1]->queue);
$this->assertInstanceOf(JobQueueing::class, $events[2]);
$this->assertNull($events[2]->queue);
$this->assertInstanceOf(JobQueued::class, $events[3]);
$this->assertNull($events[3]->queue);
}

/**
* Helpers.
*/
Expand Down Expand Up @@ -178,3 +208,8 @@ public function uniqueId()
return self::$value;
}
}

class MyTestDispatchableJob implements ShouldQueue
{
use Dispatchable;
}
19 changes: 19 additions & 0 deletions types/Queue/Events/JobQueued.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

use Illuminate\Queue\Events\JobQueued;

use function PHPStan\Testing\assertType;

$instance = new JobQueued(
connectionName: 'connection',
queue: null,
id: 'id',
job: fn () => null,
payload: '{}',
delay: null,
);

/**
* @see testQueueMayBeNullForJobQueueingAndJobQueuedEvent
*/
assertType('string|null', $instance->queue);
18 changes: 18 additions & 0 deletions types/Queue/Events/JobQueueing.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

use Illuminate\Queue\Events\JobQueueing;

use function PHPStan\Testing\assertType;

$instance = new JobQueueing(
connectionName: 'connection',
queue: null,
job: fn () => null,
payload: '{}',
delay: null,
);

/**
* @see testQueueMayBeNullForJobQueueingAndJobQueuedEvent
*/
assertType('string|null', $instance->queue);
Loading