Skip to content

Queue Plugin TestSuite Feature #179

@skie

Description

@skie

Problem

Queue plugin lacks a TestSuite for testing queued jobs without connecting to a real queue backend. Developers need a way to:

  • Assert that jobs were queued
  • Inspect queued job data
  • Test queue-related code in isolation
  • Verify job options (delay, expires, priority, queue name, config)

Solution

Implement a TestSuite that captures queued jobs during tests, similar to how TestEmailTransport captures emails. The solution should:

  • Intercept jobs at the transport layer without modifying QueueManager
  • Provide assertion methods for common test scenarios
  • Support multiple queue configs and queue names
  • Capture all job metadata for comprehensive testing

Design

Core Components

  1. Custom Enqueue Transport (test:)

    • Intercepts messages at the transport layer
    • Captures job data without sending to real queue
    • Works with existing SimpleClient architecture
  2. TestQueueClient

    • Main utility class for accessing captured jobs
    • Provides replaceAllClients() method to enable test mode
    • Static methods for querying captured jobs by various criteria
  3. QueueTrait

    • Test trait for easy integration
    • Automatic setup/teardown via #[Before] and #[After] attributes
    • Assertion methods using PHPUnit constraints

Usage Pattern

use Cake\Queue\TestSuite\QueueTrait;

class MyTest extends TestCase
{
    use QueueTrait;

    public function testJobQueued(): void
    {
        QueueManager::push('MyJob', ['data' => 'value']);
        $this->assertJobQueued('MyJob');
        $this->assertJobQueuedWith('MyJob', ['data' => 'value']);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions