- Can I use this package with Laravel’s default TestCase for async HTTP client testing?
- No, this package extends `AsyncTestCase`, which doesn’t inherit from Laravel’s `TestCase`. You’ll need to create a custom base class like `AsyncLaravelTestCase` that extends both and implements Laravel’s `createApplication()` method. This bridges the gap for async HTTP client tests in Laravel.
- How do I handle timeouts for slow API calls in my Laravel async tests?
- Use the `@TimeOut` attribute to override the default 30-second timeout per test or class. For example, `@#[TimeOut(60)]` sets a 60-second timeout. Configure granular timeouts for external API calls or slow async operations to avoid flaky tests.
- Will this package work with Laravel’s Eloquent or database migrations?
- No, this package is designed for async I/O operations like HTTP clients or queues, not sync database interactions. Eloquent and migrations are synchronous, so you’ll need to mock or avoid them in async tests or use separate sync test suites.
- Does this package support Laravel’s RefreshDatabase or Migrate traits?
- No, it lacks native support for Laravel’s database traits. You’ll need to manually override or mock database operations in async tests, as the package focuses on async I/O and fiber-based execution.
- How do I install this in Laravel without conflicts with ReactPHP or PHPUnit 12?
- Run `composer require wyrihaximus/async-test-utilities`. If conflicts arise with Laravel’s default `symfony/http-client` or PHPUnit 9.x, use Composer overrides or aliases. Update PHPUnit to ^12.5 if needed, but test thoroughly for breaking changes.
- Can I run async tests in parallel with PHPUnit’s `--parallel` flag?
- Parallel execution may cause fiber leaks or race conditions. Test in CI first with a single process, then evaluate if parallelization is safe. The package doesn’t officially support parallel runs, so monitor for memory leaks or flaky tests.
- What’s the best way to test Laravel queues or workers with this package?
- Extend `AsyncTestCase` and use its fiber-based execution to test queue jobs or workers. For example, dispatch a job and `await` its completion. The package’s timeout and callable expectation utilities are perfect for verifying async queue behavior without blocking.
- How do I generate random namespaces or directories for file storage tests?
- Use the built-in helpers like `$this->randomNamespace()` or `$this->randomDirectory()` in your test methods. These generate unique paths for isolated file storage tests, avoiding conflicts between test runs.
- What Laravel versions or async stacks (Swoole/ReactPHP) does this support?
- This package works with Laravel 11+ and async stacks like ReactPHP or Swoole, but requires manual integration. For Swoole, ensure your event loop is compatible with ReactPHP’s fibers. Test thoroughly in your CI to validate stability.
- Are there alternatives for async testing in Laravel without ReactPHP dependencies?
- If ReactPHP is a dealbreaker, consider `spatie/laravel-test-factories` for sync testing or `laravel/pint` for code quality. For async, explore `ampphp/amp` or `swoole/swoole` directly, but they require deeper integration than this package offers.