- Can I use enqueue/null in Laravel for local development without a real message broker?
- Yes, enqueue/null replaces your Laravel queue connection with a null transport, discarding all messages instantly. Configure it in `config/enqueue.php` by setting the DSN to `null://` or injecting `NullTransportFactory` directly. This is ideal for local testing where you don’t need persistence.
- How do I configure enqueue/null in Laravel to work with php-enqueue/laravel-ext?
- Update your `config/enqueue.php` to use the null DSN: `'dsn' => env('QUEUE_CONNECTION', 'null://')`. If using dependency injection, replace `TransportFactory` with `NullTransportFactory` in your service provider. The package integrates seamlessly with Laravel’s queue system via the Enqueue extension.
- Will enqueue/null work with Laravel’s built-in queue system (e.g., database or sync drivers)?
- No, enqueue/null is designed for the Enqueue library only. If you’re using Laravel’s native queue drivers, you’ll need a different mock solution like `laravel-zero-queue` or `mockery` for testing. Ensure your app uses `php-enqueue/laravel-ext` for compatibility.
- Is enqueue/null safe for production environments?
- Absolutely not. The null transport silently discards all messages, making it unsafe for production. Always validate your environment (e.g., check `APP_ENV !== 'production'`) or use a feature flag to prevent accidental deployment. Consider runtime checks in your deployment pipeline.
- How can I test message consumers with enqueue/null in Laravel?
- Use enqueue/null for unit tests by mocking the transport in your test cases. For integration tests, verify consumer logic by asserting no messages are processed (since they’re discarded). Pair it with PHPUnit or Pest to validate edge cases like retries or dead-letter queues in isolation.
- Does enqueue/null support delayed messages or retry logic?
- No, enqueue/null discards all messages immediately, including delayed or retried ones. If your app relies on these features, use a real broker (e.g., Redis or RabbitMQ) for integration tests. Document this limitation in your test suite to avoid subtle bugs.
- What Laravel versions and PHP versions does enqueue/null support?
- enqueue/null requires **PHP 8.1+** (due to Enqueue v9.x+ dependency) and works with **Laravel 9.x+**. For older Laravel versions, use Enqueue v8.x and ensure compatibility with `php-enqueue/laravel-ext`. Always check the Enqueue library’s version matrix for exact requirements.
- How do I switch from enqueue/null back to a real broker (e.g., Redis) in Laravel?
- Update your `.env` or `config/enqueue.php` to point to your real broker’s DSN (e.g., `redis://localhost`). No data migration is needed since enqueue/null doesn’t persist messages. Use environment-specific configurations or feature flags to toggle between transports dynamically.
- Are there alternatives to enqueue/null for mocking Laravel queues?
- For Laravel’s native queues, consider `mockery` or `laravel-zero-queue`. If you’re using Enqueue, alternatives like `enqueue/amqp-ext` (for RabbitMQ) or `enqueue/redis-ext` provide real brokers for testing. However, enqueue/null is the only lightweight mock transport for Enqueue’s abstraction layer.
- How can I verify enqueue/null isn’t accidentally used in production?
- Add a runtime check in your `AppServiceProvider` or a deployment gate (e.g., in CI/CD) to throw an exception if `NullTransportFactory` is detected in production. Use Laravel’s `config('queue.default')` to enforce broker-specific connections or log warnings during queue operations.