- How do I install this package for my Laravel project?
- Run `composer require --dev ergebnis/phpunit-slow-test-detector` in your Laravel project’s root directory. The package integrates as a PHPUnit extension and requires no Laravel-specific setup beyond standard PHPUnit configuration.
- Which Laravel versions and PHPUnit setups does this support?
- This package works with Laravel’s default PHPUnit setup (versions 6.5–13.x) and integrates seamlessly with Laravel’s `phpunit.xml` or `phpunit.php` configurations. It’s compatible with Laravel 8+ and PHP 8.0+.
- Can I use this with PestPHP or other testing frameworks?
- No, this package is designed exclusively for PHPUnit. If you use PestPHP or another framework, you’ll need a different solution, though PestPHP has its own performance tools like `--min-time`.
- How do I configure the maximum test duration threshold?
- Add the extension to your `phpunit.xml` under `<extensions>` and set the threshold via a PHP server variable. Example: `<server name="PHPUNIT_SLOW_TEST_DETECTOR_MAXIMUM_DURATION" value="2000" />` for a 2-second limit.
- Will this break my CI/CD pipeline if slow tests are detected?
- No, the package only reports slow tests by default. To enforce failures, use PHPUnit’s `--strict` flag or parse the output in your CI script (e.g., GitHub Actions) to fail builds if slow tests exceed a threshold.
- Does this work with Laravel’s parallel test execution?
- Yes, the package is compatible with PHPUnit’s parallelization features. It will report slow tests across all parallel workers without conflicts.
- How do I exclude certain tests from slow-test detection?
- Currently, the package applies global thresholds to all tests. To exclude specific tests, refactor them into separate suites or use PHPUnit’s `@group` annotations to isolate them, then run those suites separately with adjusted thresholds.
- Can I integrate this with Laravel Forge or other hosting platforms?
- Yes, the package outputs standard PHPUnit-compatible results. You can parse its output in Forge’s deployment scripts or CI/CD pipelines to enforce slow-test policies, just like you would with any PHPUnit extension.
- What’s the best starting threshold for Laravel projects?
- Start with conservative values like `1000` (1 second) for unit tests and `5000` (5 seconds) for integration tests. Adjust based on your team’s performance baselines and CI/CD constraints.
- Are there alternatives for detecting slow tests in Laravel?
- Yes, alternatives include PHPUnit’s built-in `--min-time` flag, PestPHP’s `--min-time` option, or custom scripts using PHPUnit’s event listeners. However, this package provides a dedicated, configurable solution with ranked reporting tailored for CI/CD workflows.