Trait QueueTrait
Queue Trait
Make assertions on jobs queued through QueueManager.
After adding the trait to your test case, all jobs will be captured instead of being queued, allowing you to make assertions.
Usage:
class MyTest extends TestCase
{
use QueueTrait;
public function testJobQueued(): void
{
QueueManager::push('MyJob', ['data' => 'value']);
$this->assertJobQueued('MyJob');
$this->assertJobQueuedWith('MyJob', ['data' => 'value']);
}
}
Method Summary
-
assertJobCount() public
Assert a specific count of jobs were queued
-
assertJobNotQueued() public
Assert a job was not queued
-
assertJobQueued() public
Assert a job was queued
-
assertJobQueuedTimes() public
Assert a job was queued a specific number of times
-
assertJobQueuedToQueue() public
Assert a job was queued to a specific queue
-
assertJobQueuedWith() public
Assert a job was queued with specific data
-
assertJobQueuedWithDelay() public
Assert a job was queued with delay
-
assertJobQueuedWithPriority() public
Assert a job was queued with priority
-
assertNoJobsQueued() public
Assert no jobs were queued
-
cleanupQueueTrait() public
Cleanup queued jobs
-
getQueuedJobs() public
Get all queued jobs
-
getQueuedJobsByClass() public
Get queued jobs by class
-
getQueuedJobsByConfig() public
Get queued jobs by config name
-
getQueuedJobsByQueue() public
Get queued jobs by queue name
-
setupTestQueueClient() public
Setup test queue client
Method Detail
assertJobCount() ¶ public
assertJobCount(int $count, string $message = ''): void
Assert a specific count of jobs were queued
Parameters
-
int$count Expected job count
-
string$message optional Optional assertion message
Returns
voidassertJobNotQueued() ¶ public
assertJobNotQueued(string $jobClass, string $message = ''): void
Assert a job was not queued
Parameters
-
string$jobClass Job class name
-
string$message optional Optional assertion message
Returns
voidassertJobQueued() ¶ public
assertJobQueued(string $jobClass, string $message = ''): void
Assert a job was queued
Parameters
-
string$jobClass Job class name
-
string$message optional Optional assertion message
Returns
voidassertJobQueuedTimes() ¶ public
assertJobQueuedTimes(string $jobClass, int $times, string $message = ''): void
Assert a job was queued a specific number of times
Parameters
-
string$jobClass Job class name
-
int$times Expected number of times
-
string$message optional Optional assertion message
Returns
voidassertJobQueuedToQueue() ¶ public
assertJobQueuedToQueue(string $queue, string $jobClass, string $message = ''): void
Assert a job was queued to a specific queue
Parameters
-
string$queue Queue name
-
string$jobClass Job class name
-
string$message optional Optional assertion message
Returns
voidassertJobQueuedWith() ¶ public
assertJobQueuedWith(string $jobClass, array<string, mixed> $data, string $message = ''): void
Assert a job was queued with specific data
Parameters
-
string$jobClass Job class name
-
array<string, mixed>$data Expected data
-
string$message optional Optional assertion message
Returns
voidassertJobQueuedWithDelay() ¶ public
assertJobQueuedWithDelay(string $jobClass, int $delay, string $message = ''): void
Assert a job was queued with delay
Parameters
-
string$jobClass Job class name
-
int$delay Expected delay in seconds
-
string$message optional Optional assertion message
Returns
voidassertJobQueuedWithPriority() ¶ public
assertJobQueuedWithPriority(string $jobClass, string|int $priority, string $message = ''): void
Assert a job was queued with priority
Parameters
-
string$jobClass Job class name
-
string|int$priority Expected priority
-
string$message optional Optional assertion message
Returns
voidassertNoJobsQueued() ¶ public
assertNoJobsQueued(string $message = ''): void
Assert no jobs were queued
Parameters
-
string$message optional Optional assertion message
Returns
voidcleanupQueueTrait() ¶ public
cleanupQueueTrait(): void
Cleanup queued jobs
Clears all captured jobs after each test.
Returns
voidgetQueuedJobs() ¶ public
getQueuedJobs(): array<array<string, mixed>>
Get all queued jobs
Returns
array<array<string, mixed>>getQueuedJobsByClass() ¶ public
getQueuedJobsByClass(string $jobClass): array<array<string, mixed>>
Get queued jobs by class
Parameters
-
string$jobClass Job class name
Returns
array<array<string, mixed>>getQueuedJobsByConfig() ¶ public
getQueuedJobsByConfig(string $config): array<array<string, mixed>>
Get queued jobs by config name
Parameters
-
string$config Config name
Returns
array<array<string, mixed>>getQueuedJobsByQueue() ¶ public
getQueuedJobsByQueue(string $queue): array<array<string, mixed>>
Get queued jobs by queue name
Parameters
-
string$queue Queue name
Returns
array<array<string, mixed>>setupTestQueueClient() ¶ public
setupTestQueueClient(): void
Setup test queue client
Replaces all queue configs with test transport to capture jobs instead of queuing them.
Returns
void