ergebnis/phpunit-slow-test-detector
PHPUnit extension (Composer package and PHAR) that detects and reports slow tests during test runs. Configure a global maximum duration; when tests exceed it, the extension lists them with timings to help you spot and fix performance regressions.
Pros:
maximum-duration, maximum-count), aligning with team-specific CI/CD constraints.Cons:
composer require --dev ergebnis/phpunit-slow-test-detector) and minimal XML configuration.phpunit.xml (or equivalent) to enable the extension, but this is a one-time setup.stderr for slow tests).phpunit commands to capture stderr.composer.json for phpunit/phpunit).phpunit command usage (e.g., ./vendor/bin/phpunit).composer require --dev ergebnis/phpunit-slow-test-detector
phpunit.xml (or phpunit.dist.xml) with the extension and desired thresholds:
<extensions>
<bootstrap class="Ergebnis\PHPUnit\SlowTestDetector\Extension"/>
</extensions>
<php>
<server name="PHPUNIT_SLOW_TEST_DETECTOR_MAXIMUM_DURATION" value="1000"/> <!-- 1s threshold -->
<server name="PHPUNIT_SLOW_TEST_DETECTOR_MAXIMUM_COUNT" value="5"/>
</php>
stderr if needed (e.g., GitHub Actions):
- run: ./vendor/bin/phpunit --colors=never 2>&1 | tee phpunit.log
phpunit.log for slow tests (e.g., using grep or a script).stderr.phpunit.xml configuration and PHPUnit version.maximum-duration or exclude known slow tests via annotations (if supported).-v to confirm extension is loaded.stderr for errors during test execution.--group slow) to isolate problematic areas.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| PHPUnit version incompatibility | Extension fails to load | Pin PHPUnit version in composer.json |
Misconfigured phpunit.xml |
No slow-test output | Validate XML syntax and extension class name |
CI pipeline ignores stderr |
Slow tests go undetected | Update pipeline to capture stderr |
| Threshold too aggressive | False positives flood logs | Adjust maximum-duration or maximum-count |
| Test suite flakiness | Slow tests mask intermittent failures | Combine with other tools (e.g., phpunit --repeat) |
phpunit.xml configurations.--tag slow-test-detection) before enforcing.How can I help you explore Laravel packages today?