ergebnis/phpunit-slow-test-detector
Detect slow PHPUnit tests with an extension delivered as a Composer package or PHAR. Configure a global maximum duration and get a report of tests exceeding the threshold after each run—ideal for catching performance regressions in your suite.
Pros:
maximum-duration, maximum-count) allow alignment with CI/CD pipelines (e.g., flagging tests >2s as slow).Cons:
phpunit.xml), which may conflict with Laravel’s phpunit.xml.dist or PestPHP adoption.phpunit.xml modifications and composer require.--min-time flag). Requires evaluation of trade-offs (e.g., PHPUnit’s richer ecosystem vs. Pest’s simplicity).| Risk Area | Severity | Mitigation Strategy |
|---|---|---|
| Config Overrides | Medium | Document phpunit.xml changes in CONTRIBUTING.md. |
| Performance Overhead | Low | Benchmark impact on CI (expected: <5% runtime). |
| PHPUnit Version Drift | Medium | Pin PHPUnit version in composer.json (e.g., ^10.0). |
| PestPHP Adoption | High | Deprecate PHPUnit config if Pest is primary. |
CI/CD Pipeline Impact:
Toolchain Alignment:
Threshold Strategy:
maximum-duration="2000") or environment-specific (e.g., CI vs. local)?Maintenance:
phpunit.xml updates (DevOps, QA, or TPM)?Laravel Compatibility:
phpunit.xml.dist). No framework-level conflicts.--min-time suffices before adopting this tool.grep "slow test").Alternatives Evaluated:
--min-time: Simpler but lacks PHPUnit’s extensibility.phpunit --log-junit).Assessment Phase:
composer.json, CI configs).phpunit --log-junit | jq '.testcases[] | {name, time}').Pilot:
composer require --dev ergebnis/phpunit-slow-test-detector
phpunit.xml with:
<extensions>
<bootstrap class="Ergebnis\PHPUnit\SlowTestDetector\Extension"/>
</extensions>
<parameters>
<parameter name="maximum-duration" value="1000"/> <!-- 1s threshold -->
</parameters>
phpunit --stop-on-failure).Rollout:
README.md).phpunit | grep "slow test" | curl -X POST -d @- SLACK_WEBHOOK).| Component | Compatibility Status | Notes |
|---|---|---|
| Laravel 9/10 | ✅ High | PHPUnit 9.x/10.x supported. |
| PestPHP | ⚠️ Partial | Redundant if using Pest’s timing flags. |
| CI/CD (GitHub Actions) | ✅ High | CLI output parsable via awk/sed. |
| Windows/Linux/macOS | ✅ High | PHPUnit cross-platform. |
phpunit.xml (or create a new config for CI).500ms) and adjust based on CI data.phpunit.xml changes (e.g., Git diffs for thresholds).KNOWN_SLOW_TESTS.md to document intentional slow tests (e.g., integration tests).maximum-duration based on CI trends.TESTING.md section:
"Slow tests are flagged if they exceed 1s. Use
@slowannotations for intentional slow tests (see PHPUnit docs)."
phpunit --configuration phpunit-slow.xml # Uses custom slow-test config
phpunit > slow-tests.log) for debugging.:warning: Slow tests detected in <branch>:
<phpunit-slow-test-detector-output>
hyperfine 'phpunit' 'phpunit --extensions slow-test-detector'
--parallel flag (no conflicts).maximum-duration="avg_duration * 1.5") via custom PHP scripts.| Failure Mode | Impact | Mitigation |
|---|---|---|
| Config Misconfiguration | False positives/negatives | Use phpunit --help to validate syntax. |
| PHPUnit Version Mismatch | Extension fails silently | Pin PHPUnit version in composer.json. |
| CI Timeout | Slow tests block builds | Set maximum-count="5" to limit noise. |
| Alert Fatigue | Ignored notifications | Tier alerts (e.g., Slack @here for >3 slow tests). |
--stop-on-failure=false.flaky.How can I help you explore Laravel packages today?