liuggio/fastest
Run tests in parallel with a simple CLI wrapper. Fastest executes any command (PHPUnit, Behat, etc.) across available CPU cores, randomizes test order, supports piping test lists or phpunit.xml, adds verbosity flags, and helps functional tests use one DB per process.
ENV_TEST_CHANNEL_READABLE) is a game-changer for Laravel apps using Doctrine/Symfony, eliminating race conditions in functional tests.require-dev installation with no global state modifications (unlike paratest).FastestEnvironment::setFromRequest() in app_dev.php) for browser-based tests (e.g., Dusk, Pest with browser drivers).| Risk Area | Mitigation Strategy |
|---|---|
| Database Connection Leaks | Use Doctrine adapters to ensure per-process DB cleanup; monitor ENV_TEST_CHANNEL_READABLE usage. |
| Test Isolation Failures | Validate randomization with --preserve-order for debugging; use -b for pre-test setup. |
| Browser Test Conflicts | Implement FastestEnvironment::setFromRequest() early in the request lifecycle (e.g., middleware). |
| Coverage Merging | Require phpcov/phpunit-merger for accurate coverage reports; document workflow. |
| Legacy PHPUnit | Test with Laravel’s default PHPUnit version (v9+) to avoid deprecated API issues. |
fastest’s per-process DB isolation is critical.--preserve-order.nproc.)fastest supports any CLI command, but Laravel-specific tooling (e.g., Pest) may need wrapper scripts.-vvv for verbose output.)Feature tests, API tests with database interactions).| Phase | Action | Laravel-Specific Notes |
|---|---|---|
| Assessment | Run a subset of tests in parallel to validate isolation (e.g., `find tests/Feature -name "*Test.php" | fastest "phpunit {}"`). |
| Database Setup | Configure Doctrine adapters in config/database.php (see SQLite/Doctrine examples). |
For SQLite, replace __DBNAME__ in the path. |
| CI/CD Pilot | Test in a non-production CI environment with fastest -x phpunit.xml -p 4 "phpunit". |
Monitor resource usage (e.g., nproc --all for core count). |
| Full Rollout | Update phpunit.xml to include parallel execution in CI workflows. |
Example: phpunit --testdox-html=report.html → fastest -x phpunit.xml "phpunit --testdox-html=report_{n}.html". |
| Component | Compatibility Notes |
|---|---|
| PHPUnit | Tested with PHPUnit v9+ (Laravel’s default). No breaking changes expected. |
| Doctrine | Adapters for DBAL and MongoDB; no ORM-specific changes required. |
| Symfony Kernel | Requires FastestEnvironment::setFromRequest() in app_dev.php for browser tests. |
| Behat | Extension supports --list-features/--list-scenarios for parallel scenario execution. |
| Pest | Use wrapper scripts (e.g., fastest "pest {}"), but Pest’s built-in parallelism may conflict. |
| Dusk | Critical: Set ENV_TEST_CHANNEL_READABLE via cookies/headers (see browser test section). |
FastestEnvironment::setFromRequest() to app_dev.php (for browser tests).before commands (e.g., -b "php artisan migrate:fresh --env=testing_{p}") for test data.-x phpunit.xml for structured test suites or find tests/ -name "*Test.php" for file-based.phpcov merge.-vvv to isolate process-specific issues.--before commands).--preserve-order).ENV_TEST_CHANNEL_READABLE values in test logs.FastestEnvironment::setFromRequest() is called early.-p to limit processes if tests OOM (e.g., -p 2).fastest workflow, including:
README.md section for new devs (e.g., "How to Run Tests in Parallel").fastest in multiple CI jobs (e.g., split test suites by feature).-p $(nproc) for multi-core machines.-p if tests OOM.fastest (e.g., 30m → 7m in the package’s example).| Failure Scenario | Detection Method | Mitigation Strategy |
|---|---|---|
| Database Connection Leaks | Tests hang or timeout. | Use --before to reset databases; monitor ENV_TEST_CHANNEL_READABLE. |
| Test Isolation Violations | Flaky tests pass/fail randomly. | Run with --preserve-order to debug; add sleep() between tests if needed. |
| Browser Test Conflicts | Dusk/Behat tests fail with "wrong DB". | Verify FastestEnvironment::setFromRequest() is called; check cookies/headers. |
| Resource Exhaustion |
How can I help you explore Laravel packages today?