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.
Installation Add the package via Composer:
composer require --dev automattic/phpunit-select-config
Ensure autoload-dev is dumped:
composer dump-autoload
Basic Usage Replace your existing PHPUnit command with:
./vendor/bin/phpunit-select-config
The package will automatically detect and prompt you to choose between available phpunit.xml files (e.g., phpunit.xml.dist, phpunit.xml, phpunit.ci.xml).
First Use Case Run tests against a specific environment (e.g., CI vs. local):
./vendor/bin/phpunit-select-config --env ci
The package will prioritize phpunit.ci.xml if it exists.
CI/CD Pipelines Hardcode the environment flag in CI scripts (e.g., GitHub Actions):
- run: ./vendor/bin/phpunit-select-config --env ci
Use phpunit.ci.xml for strict configurations (e.g., no coverage, faster runs).
Local Development
Default to local config (phpunit.xml) unless overridden:
./vendor/bin/phpunit-select-config --env local
Add aliases to composer.json for convenience:
"scripts": {
"test": "phpunit-select-config --env local",
"test:ci": "phpunit-select-config --env ci"
}
Multi-Config Projects
Name files explicitly (e.g., phpunit.feature.xml, phpunit.unit.xml) and use:
./vendor/bin/phpunit-select-config --config feature
--env testing):
./vendor/bin/phpunit-select-config --env testing --filter TestFeature
.phpunit-select-config.php:
return [
'paths' => [
base_path('phpunit.xml'),
base_path('tests/phpunit.ci.xml'),
],
];
Missing Config Files
If no matching phpunit.xml.* exists, the package defaults to phpunit.xml.dist. Add a fallback:
./vendor/bin/phpunit-select-config --fallback
Case Sensitivity
Config file names are case-sensitive on Linux/macOS. Use consistent naming (e.g., phpunit.ci.xml vs. PHPUNIT.CI.XML).
Cached Configs PHPUnit caches configs. Clear cache after changing files:
./vendor/bin/phpunit-select-config --clear-cache
./vendor/bin/phpunit-select-config -vvv
./vendor/bin/phpunit-select-config --dry-run
.phpunit-select-config.php:
return [
'resolver' => function ($env) {
return base_path("phpunit.{$env}.xml");
},
];
./vendor/bin/phpunit-select-config --env ${TEST_ENV}
./vendor/bin/phpunit-select-config --env ci --filter UnitTest
How can I help you explore Laravel packages today?