Skip to content

Commit b208682

Browse files
committed
Ensure queue property is nullable
1 parent e1af08a commit b208682

File tree

5 files changed

+74
-2
lines changed

5 files changed

+74
-2
lines changed

src/Illuminate/Queue/Events/JobQueued.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class JobQueued
88
* Create a new event instance.
99
*
1010
* @param string $connectionName The connection name.
11-
* @param string $queue The queue name.
11+
* @param string|null $queue The queue name.
1212
* @param string|int|null $id The job ID.
1313
* @param \Closure|string|object $job The job instance.
1414
* @param string $payload The job payload.

src/Illuminate/Queue/Events/JobQueueing.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class JobQueueing
88
* Create a new event instance.
99
*
1010
* @param string $connectionName The connection name.
11-
* @param string $queue The queue name.
11+
* @param string|null $queue The queue name.
1212
* @param \Closure|string|object $job The job instance.
1313
* @param string $payload The job payload.
1414
* @param int|null $delay The number of seconds the job was delayed.

tests/Integration/Queue/JobDispatchingTest.php

+35
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
use Illuminate\Contracts\Queue\ShouldBeUnique;
88
use Illuminate\Contracts\Queue\ShouldQueue;
99
use Illuminate\Foundation\Bus\Dispatchable;
10+
use Illuminate\Queue\Events\JobQueued;
11+
use Illuminate\Queue\Events\JobQueueing;
1012
use Illuminate\Queue\InteractsWithQueue;
13+
use Illuminate\Support\Facades\Config;
1114
use Orchestra\Testbench\Attributes\WithMigration;
1215

1316
#[WithMigration]
@@ -135,6 +138,33 @@ public function testUniqueJobLockIsReleasedForJobDispatchedAfterResponse()
135138
$this->assertFalse(UniqueJob::$ran);
136139
}
137140

141+
public function testQueueMayBeNullForJobQueueingAndJobQueuedEvent()
142+
{
143+
Config::set('queue.default', 'database');
144+
$events = [];
145+
$this->app['events']->listen(function (JobQueueing $e) use (&$events) {
146+
$events[] = $e;
147+
});
148+
$this->app['events']->listen(function (JobQueued $e) use (&$events) {
149+
$events[] = $e;
150+
});
151+
152+
MyTestDispatchableJob::dispatch();
153+
dispatch(function () {
154+
//
155+
});
156+
157+
$this->assertCount(4, $events);
158+
$this->assertInstanceOf(JobQueueing::class, $events[0]);
159+
$this->assertNull($events[0]->queue);
160+
$this->assertInstanceOf(JobQueued::class, $events[1]);
161+
$this->assertNull($events[1]->queue);
162+
$this->assertInstanceOf(JobQueueing::class, $events[2]);
163+
$this->assertNull($events[2]->queue);
164+
$this->assertInstanceOf(JobQueued::class, $events[3]);
165+
$this->assertNull($events[3]->queue);
166+
}
167+
138168
/**
139169
* Helpers.
140170
*/
@@ -178,3 +208,8 @@ public function uniqueId()
178208
return self::$value;
179209
}
180210
}
211+
212+
class MyTestDispatchableJob implements ShouldQueue
213+
{
214+
use Dispatchable;
215+
}

types/Queue/Events/JobQueued.php

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
use Illuminate\Queue\Events\JobQueued;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
$instance = new JobQueued(
8+
connectionName: 'connection',
9+
queue: null,
10+
id: 'id',
11+
job: fn () => null,
12+
payload: '{}',
13+
delay: null,
14+
);
15+
16+
/**
17+
* @see testQueueMayBeNullForJobQueueingAndJobQueuedEvent
18+
*/
19+
assertType('string|null', $instance->queue);

types/Queue/Events/JobQueueing.php

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
use Illuminate\Queue\Events\JobQueueing;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
$instance = new JobQueueing(
8+
connectionName: 'connection',
9+
queue: null,
10+
job: fn () => null,
11+
payload: '{}',
12+
delay: null,
13+
);
14+
15+
/**
16+
* @see testQueueMayBeNullForJobQueueingAndJobQueuedEvent
17+
*/
18+
assertType('string|null', $instance->queue);

0 commit comments

Comments
 (0)