brianium/paratest
ParaTest runs PHPUnit tests in parallel with near zero setup. Use vendor/bin/paratest to split by TestCase or individual tests, speed up CI, and combine code coverage into one report. Provides TEST_TOKEN/UNIQUE_TEST_TOKEN for per-process isolation.
TEST_TOKEN environment variable enables isolated test databases per process.flock-based coordination).phpunit.xml, custom test classes) with minimal changes.App::singleton()) may conflict with Laravel’s service container. Mitigation: Move shared logic to non-test classes or use dependency injection.TEST_TOKEN-based DB isolation (as documented).vendor/bin/paratest.paratest_for_phpstorm) for seamless debugging.phpunit --coverage workflows).| Risk Area | Severity | Mitigation |
|---|---|---|
| PHPUnit Version Mismatch | High | Pin PHPUnit to a compatible version (e.g., ^13.1) or upgrade Laravel’s PHPUnit. |
| Static State Conflicts | Medium | Refactor tests to avoid static variables; use TEST_TOKEN for isolation. |
| Database Transaction Issues | Medium | Use TEST_TOKEN-based DB names or disable transactions in parallel tests. |
| Coverage Reporting Errors | Low | Test coverage merging with --coverage flag in CI. |
| CI Pipeline Complexity | Low | Start with --max-processes=4 to validate stability before scaling. |
TEST_TOKEN)?phpunit CLI commands (e.g., ./vendor/bin/phpunit → ./vendor/bin/paratest).RefreshDatabase, MigrateFresh).phpunit --coverage via PCOV/xDebug.paratest_for_phpstorm.Phase 1: Validation (Low Risk)
composer require --dev brianium/paratest
./vendor/bin/paratest --max-processes=2 tests/Unit/
Phase 2: Configuration (Medium Risk)
phpunit.xml to include ParaTest-specific flags if needed (e.g., coverage merging).TEST_TOKEN-based database isolation for integration tests:
// In TestCase::setUp()
$dbName = getenv('TEST_TOKEN') ? "testdb_{$token}" : 'testdb';
paratest instead of phpunit.Phase 3: Full Rollout (High Risk)
--max-processes (e.g., 4 → 8) in CI.XDEBUG_MODE=coverage ./vendor/bin/paratest --coverage
| Laravel Component | Compatibility | Notes |
|---|---|---|
| PHPUnit Tests | High | Zero-config for most cases; static state may require refactoring. |
| Database (Migrations/Seed) | Medium | Use TEST_TOKEN for isolation or disable transactions in parallel tests. |
| Service Container | Low | Avoid static App::* calls; use DI instead. |
| Queues/Jobs | Medium | May need TEST_TOKEN-based queue prefixes to avoid collisions. |
| File Storage | High | ParaTest handles file-based state per process. |
| API Testing (Pest/HTTP) | High | Works with Laravel’s HTTP tests out of the box. |
TEST_TOKEN for database isolation.--max-processes=2 first.Process component; updates may require testing.phpunit to paratest.--verbose and subprocess isolation for debugging.--no-parallel).TEST_TOKEN patterns and avoid static state.--max-processes: Control memory/CPU usage (default: auto-detect).--shard-test-distribution: Choose random, round-robin, or default.| Failure Scenario | Impact | Recovery |
|---|---|---|
| Test process crashes silently | Partial test results | ParaTest detects and fails the run; check logs for subprocess errors. |
| Database connection leaks | CI pipeline hangs | Use TEST_TOKEN isolation or |
How can I help you explore Laravel packages today?