automattic/phpunit-select-config
Small utility for PHPUnit projects that helps select or switch the PHPUnit configuration file to use when running tests. Handy for repos with multiple phpunit.xml variants (e.g., local vs CI) and scripts that need consistent config selection.
phpunit.8.xml (Laravel 8) or phpunit.10.xml (Laravel 10) without hardcoding paths.phpunit.xml.ci vs. phpunit.xml.local).phpunit.xml.feature-x) without polluting the main suite.refreshDatabase()). Best used for config management, not test logic.phpunit.xml includes. The 45.13 "opportunity" score highlights its value for complex, multi-versioned test suites.--dev), zero runtime impact.phpunit calls with phpunit-select-config, enabling gradual adoption.php artisan test:versioned) for Laravel-native workflows.TestCase bootstrapping (e.g., service providers, app bindings). Requires validation testing.phpunit.9.xml), which may clash with existing workflows.phpunit.10.xml).| Risk | Severity | Mitigation Strategy |
|---|---|---|
| Unmaintained Package | High | Fork the repo or replace with a custom Bash/PHP script (e.g., select-phpunit-config). |
| Laravel TestCase Conflicts | Medium | Test with a minimal TestCase and document limitations in the README. |
| CI Pipeline Breaks | Medium | Implement a fallback to phpunit.xml in CI if the package fails. |
| Performance Overhead | Low | Benchmark in CI; negligible for most use cases (sub-100ms overhead). |
| Version Lock-In | Low | Pin PHPUnit version in composer.json to avoid breakage. |
TestCase and service providers?
TestCase that loads providers to ensure no bootstrapping conflicts.phpunit.xml or a custom error handler in CI.pest or lighthouse?
TEST_CONFIG=phpunit.xml.ci) for flexibility.phpunit.xml.staging).phpunit.xml differently).Phase 1: Local Validation
composer require --dev automattic/phpunit-select-config
./vendor/bin/phpunit-select-config phpunit.*.xml.dist
phpunit.9.xml, phpunit.10.xml) and validate selection.php artisan test to ensure no conflicts.Phase 2: Artisan Integration
app/Console/Commands/TestVersioned.php):
use Automattic\PHPUnitSelectConfig\Runner;
class TestVersioned extends Command {
protected $signature = 'test:versioned {config=phpunit.xml}';
public function handle() {
$runner = new Runner($this->argument('config'));
$runner->run();
}
}
app/Console/Kernel.php:
protected $commands = [
Commands\TestVersioned::class,
];
php artisan test with php artisan test:versioned in local workflows.Phase 3: CI/CD Adoption
# .github/workflows/test.yml
- run: php artisan test:versioned phpunit.xml.ci
TEST_CONFIG=phpunit.xml.feature-x php artisan test:versioned
phpunit.xml if the package fails:
if ! ./vendor/bin/phpunit-select-config phpunit.xml.ci; then
phpunit --configuration=phpunit.xml
fi
Phase 4: Laravel Core (Optional)
TestWorker to use the package’s runner (advanced):
// app/Providers/AppServiceProvider.php
public function boot() {
if ($this->app->runningUnitTests()) {
$config = config('testing.config', 'phpunit.xml');
$runner = new Runner($config);
$runner->runTests();
}
}
config/testing.php:
'config' => env('TEST_CONFIG', 'phpunit.xml'),
| Component | Compatibility Notes |
|---|---|
| Laravel | Works with Laravel 8+ (PHPUnit 9+). Test with Laravel 10+ for regressions. |
| PHPUnit | Requires PHPUnit 8.0+. May need polyfills for older versions (e.g., PHPUnit 7). |
| CI Tools | Compatible with any CLI-based CI (GitHub Actions, Jenkins, CircleCI, GitLab CI). |
| Test Frameworks | PHPUnit-only; Pest/Lighthouse may need custom wrappers. |
| Monorepos | Ideal for Laravel + plugins or multi-package repos with versioned tests. |
| Windows/Linux/macOS | Cross-platform; no OS-specific dependencies. |
phpunit calls with phpunit-select-config in scripts.phpunit.9.xml) and usage patterns.How can I help you explore Laravel packages today?