- How do I test Laravel queue workers that use php-enqueue instead of Laravel’s native queue system?
- Use `ConnectionMock` from `enqueue/test` to replace the real Enqueue connection in your tests. For Laravel workers, inject the mocked connection into your queue service or worker class. This lets you simulate message delivery, failures, or retries without hitting an external broker. Ensure you’re using `php-enqueue/laravel` for Laravel integration.
- Can I use this package to test Laravel’s ShouldQueue jobs with Enqueue?
- This package focuses on testing the Enqueue connection layer, not Laravel’s job classes directly. For job-level tests, combine it with Laravel’s `Queue::fake()` or manually mock job dispatching. The package excels at testing queue consumers, producers, and connection behavior, not the job payloads themselves.
- What Laravel versions does enqueue/test support, and do I need php-enqueue/laravel?
- The package itself has no Laravel dependencies, but it works best with Laravel 8+ when paired with `php-enqueue/laravel`. For Laravel <8, you may need to manually bridge Enqueue’s interfaces with Laravel’s queue system. Always check compatibility with your Enqueue version, as the package hasn’t been updated since 2018.
- How do I mock a Redis queue connection for testing with enqueue/test?
- Replace your Redis connection with `ConnectionMock` in tests. For example, if using `RedisConnection`, inject the mock into your `Connection` class. The mock simulates queue operations like `send()`, `receive()`, and `ack()` without requiring a real Redis server. This is useful for isolated unit tests of queue logic.
- Is enqueue/test still maintained? Should I use it for new projects?
- The package hasn’t seen updates since 2018, which raises concerns about compatibility with modern PHP (8.0+) or newer Enqueue versions (v10+). If maintenance is critical, consider alternatives like `laravel/queue-testing` or manual mocking with PHPUnit. For legacy projects using older Enqueue versions, it may still work with minor adjustments.
- Can I test message retries or dead-letter queues with enqueue/test?
- Yes, `ConnectionMock` allows you to simulate retry logic by configuring the mock to throw exceptions or return specific responses. For dead-letter queues, you can mock the connection to route messages to a test dead-letter queue or assert failures. This is useful for testing error-handling paths in your queue consumers.
- How does enqueue/test compare to Laravel’s Queue::fake() for testing?
- While `Queue::fake()` is simpler for testing Laravel’s job classes (e.g., `ShouldQueue`), `enqueue/test` provides deeper control over the Enqueue connection layer, including message routing, connection pooling, and broker-specific behaviors. Use `Queue::fake()` for job-level assertions and `enqueue/test` for testing the queue infrastructure itself.
- Will this package work with Pest or other test frameworks besides PHPUnit?
- The package is designed for PHPUnit and doesn’t include built-in support for Pest or other frameworks. However, you can still use its mocks in Pest tests by manually instantiating `ConnectionMock` and integrating it into your test setup. Pest’s syntax would wrap around the same mocking logic.
- How do I test a Laravel queue worker that uses both Enqueue and database queues?
- For hybrid setups, use `enqueue/test` to mock the Enqueue connection and Laravel’s `Queue::fake()` to mock database queues. Test the worker’s logic separately for each queue type, ensuring your assertions cover both paths. This layered approach avoids external dependencies while validating all queue interactions.
- Are there any known issues with enqueue/test in production environments?
- This package is purely for testing and has no runtime impact in production. However, if you’re using it to generate test data or mocks in a staging environment, ensure your test suite doesn’t accidentally deploy mock configurations. Always validate that your production queue setup uses real connections, not mocked ones.