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.
maximum-duration, maximum-count) and output behavior (stderr), which is critical for CI/CD pipelines and large test suites.phpunit.xml, which may not align with Laravel’s convention-over-configuration philosophy (e.g., phpunit.xml.dist).phpunit/phpunit package), making this a drop-in solution.composer is unavailable (e.g., Docker containers).php artisan test) to ensure no edge cases (e.g., parallel tests, custom listeners).microtime() in tests) or external tools like phpunit-speed-tester.maximum-duration (default: 500ms) aligns with our CI/CD SLAs? (e.g., 1s for unit tests, 5s for integration tests).phpunit/phpunit in composer.json).php artisan test --stop-on-failure).composer require --dev ergebnis/phpunit-slow-test-detector
Update phpunit.xml with the extension configuration (see README for version-specific syntax).extensionsDirectory in phpunit.xml.maximum-duration=500), then adjust based on CI/CD feedback.php artisan test (which uses phpunit.xml) picks up the extension.TestCase and custom listeners.--parallel flag if using PHPUnit 9.x+.refreshDatabase() in Laravel).::warning).maximum-duration by 10% weekly).phpunit.xml snippets for different Laravel/PHPUnit versions.maximum-duration based on test suite evolution.ergebnis/phpunit-slow-test-detector (e.g., PHPUnit 14.x support).CONTRIBUTING.md.phpunit.xml configuration.bootstrap path in phpunit.xml).--debug to inspect extension loading.maximum-duration dynamically (e.g., higher for integration tests).--parallel flag (tested in v9.x+).| Failure Mode | Impact | Mitigation |
|---|---|---|
| Extension not loaded | No slow test detection | Verify phpunit.xml configuration. |
| Incorrect thresholds | False positives/negatives | Benchmark and adjust thresholds empirically. |
| CI pipeline parsing errors | Slow tests go unaddressed | Use robust parsing (e.g., regex on stderr). |
| PHPUnit version incompatibility | Extension fails to load | Pin PHPUnit version in composer.json. |
| High false-positive rate | Developer frustration | Whitelist known slow tests temporarily. |
- name: Run PHPUnit with slow test detection
run: php artisan test
- name: Parse slow tests
run: |
SLOW_TESTS=$(php artisan test 2>&1 | grep -E "Duration.*Test")
if [ -n "$SLOW_TESTS" ]; then
echo "$S
How can I help you explore Laravel packages today?