- How do I install this package for Laravel projects?
- Run `composer require --dev ergebnis/phpunit-slow-test-detector` in your Laravel project. It integrates seamlessly with Laravel’s default PHPUnit setup and requires no additional Laravel-specific configuration.
- Will this work with Laravel’s built-in PHPUnit configuration?
- Yes, it works out-of-the-box with Laravel’s default `phpunit.xml` configuration. No changes to Laravel’s test setup are needed beyond installing the package and configuring the slow-test threshold.
- What Laravel versions and PHPUnit setups does this support?
- This package supports PHPUnit 6.5–13.x, which covers most Laravel projects. Laravel 10+ (PHP 8.1+) and earlier versions (PHP 7.4+) are supported as long as your PHPUnit version is within the supported range.
- How do I configure the maximum duration for slow tests?
- Add `<phpunit>` configuration to your `phpunit.xml` file: `<phpunit ...><phpunit-slow-test-detector maximum-duration="1000" />...</phpunit>`. The value is in milliseconds (e.g., `1000` = 1 second).
- Can I use this in CI/CD pipelines for Laravel?
- Absolutely. Add it to your CI workflow (e.g., GitHub Actions) alongside `php artisan test`. The console output will highlight slow tests, and you can extend it with custom scripts to fail builds or notify teams.
- Does this work with PestPHP or other testing frameworks?
- No, this package is designed for PHPUnit only. If you use PestPHP, it already includes built-in test timing metrics, so this package isn’t needed.
- How do I interpret the ranked list of slow tests?
- The output lists tests sorted by duration (slowest first) with their execution time in milliseconds. Focus on the top entries to identify performance bottlenecks in your Laravel test suite.
- Will this slow down my Laravel test suite?
- No, the package adds negligible overhead. It only runs after tests complete and doesn’t interfere with test execution speed. It’s purely a reporting tool.
- Can I export slow test data for monitoring or alerts?
- Currently, output is console-based only. For advanced use cases, you’d need to parse the console output or integrate it with custom scripts to send alerts (e.g., Slack) or log data to a database.
- What if my Laravel tests have varying performance needs (e.g., unit vs. integration tests)?
- Use separate `phpunit.xml` configurations for different test suites and set different `maximum-duration` values. For example, enforce stricter thresholds for unit tests and lenient ones for integration tests.