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.
Installation:
composer require --dev brianium/paratest
Ensure your phpunit version is up-to-date (ParaTest requires the latest PHPUnit).
First Run:
Replace your existing phpunit command with:
vendor/bin/paratest
This defaults to parallelizing tests by TestCase (entire test classes).
Functional-Level Parallelism: For finer-grained parallelism (individual test methods), use:
vendor/bin/paratest --functional
Verify Integration: Run a single test file to confirm:
vendor/bin/paratest tests/Feature/ExampleTest.php
Speed up CI/CD pipelines by reducing test execution time. For example:
# Run all tests in parallel (4 processes)
vendor/bin/paratest --processes=4
CI/CD Pipeline:
Replace phpunit with paratest in your workflow (GitHub Actions, GitLab CI, etc.):
# GitHub Actions example
- name: Run tests in parallel
run: vendor/bin/paratest --processes=auto --coverage-text
Local Development:
--processes=auto to auto-detect CPU cores.XDEBUG_MODE=coverage vendor/bin/paratest --coverage-clover=coverage.clover
Test Sharding: Split tests into chunks for large suites:
# Shard tests into 3 chunks
vendor/bin/paratest --shard=3
Or use custom distributions:
# Round-robin distribution
vendor/bin/paratest --shard-test-distribution=round-robin --shard=4
Database Isolation:
Leverage TEST_TOKEN for unique DB connections:
$dbName = getenv('TEST_TOKEN') ? "testdb_{$token}" : 'testdb';
vendor/bin/paratest --coverage-xml=coverage.xml
vendor/bin/paratest --verbose
Then copy the subprocess command from the output and run it manually../vendor/bin/paratest_for_phpstorm--processes=4 --coverage-clover=coverage.cloverParaTest configuration for parallel runs.Static State Issues:
Coverage Quirks:
php -d pcov.enabled=1 vendor/bin/paratest --passthru-php="'-d' 'pcov.enabled=1'"
--exclude-source-from-xml-coverage to filter paths.Test Dependencies:
TEST_TOKEN for isolation.Subprocess Failures:
--verbose to inspect subprocess commands. Remove --printer flags temporarily to see raw PHPUnit output.PHPUnit Version Lock:
--processes=1 to debug:
vendor/bin/paratest tests/Feature/ExampleTest.php --processes=1
--shard-test-distribution=random.--max-processes to cap CPU usage:
vendor/bin/paratest --max-processes=2
Custom Test Distribution:
Extend sharding logic by implementing a custom TestDistributionStrategy (see source).
Pre/Post-Test Hooks:
Use PHPUnit events (e.g., TestRunner\Started) for setup/teardown. ParaTest respects these events.
Environment Variables:
Override defaults via .env or CI variables:
PARATEST_PROCESSES=4 vendor/bin/paratest
--do-not-fail-on-* Options:
Use to skip failures for specific test types (e.g., --do-not-fail-on-risky).vendor/bin/paratest --testdox-text=report.txt
symfony/* packages are compatible.--processes=auto (defaults to CPU cores). Adjust based on test complexity.--max-memory=512M to limit per-process usage.@group annotations for logical parallelism:
vendor/bin/paratest --groups=unit,integration
How can I help you explore Laravel packages today?