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.
automattic/phpunit-select-config) enables dynamic PHPUnit configuration selection based on version tags (e.g., phpunit.xml.dist, phpunit.xml). This is particularly useful in monorepos, multi-versioned projects, or CI/CD pipelines where different test configurations are required for different branches, environments, or feature flags.laravel/framework) is tightly coupled with phpunit.xml files. This package could streamline test suite isolation (e.g., unit vs. feature tests) or versioned test configurations (e.g., PHP 8.0 vs. 8.2 compatibility tests).phpunit.xml.feature only when a flag is enabled.phpunit.xml.staging in staging pipelines.php artisan test to delegate config selection to this package..env (e.g., TEST_CONFIG=phpunit.xml.ci).| Risk Area | Assessment |
|---|---|
| Package Stability | Unmaintained; may break with PHPUnit/Laravel updates. |
| Laravel Integration | Potential conflicts with Laravel’s built-in test helpers (e.g., TestCase). |
| Performance Overhead | Minimal, as it’s a thin wrapper, but CLI overhead may exist in CI. |
| Debugging Complexity | Harder to debug than native PHPUnit if config selection fails. |
phpunit.xml includes)?TestCase bootstrapping (e.g., service providers, app bindings)?phpunit.xml)?phpunit.xml with environments sufficient?pest or lighthouse testing tools (if used)?Phase 1: Proof of Concept
composer require automattic/phpunit-select-config --dev
// app/Console/Commands/RunVersionedTests.php
use Automattic\PHPUnitSelectConfig\Runner;
class RunVersionedTests extends Command {
protected $signature = 'test:versioned {config?}';
public function handle() {
$config = $this->argument('config') ?? config('testing.default_config');
$runner = new Runner($config);
$runner->run();
}
}
php artisan test:versioned phpunit.xml.ci
Phase 2: CI/CD Integration
php artisan test with php artisan test:versioned in CI.# .github/workflows/tests.yml
- run: php artisan test:versioned ${{ env.TEST_CONFIG }}
Phase 3: Laravel Core Integration (Optional)
TestWorker or TestResultProcessor to use the package’s runner.Illuminate\Foundation\Testing\TestCase:
protected function createApplication() {
$config = $this->getTestConfig();
$runner = new Runner($config);
return $runner->createLaravelApplication();
}
| Component | Compatibility Notes |
|---|---|
| Laravel | Works with Laravel 8+ (PHPUnit 9+). Test for regressions in Laravel 10+. |
| PHPUnit | Requires PHPUnit 8.0+. May need polyfills for older versions. |
| CI Tools | Compatible with any CLI-based CI (GitHub Actions, Jenkins, etc.). |
| Pest/Lighthouse | Limited compatibility; may require custom adapters. |
phpunit.xml) if the package fails.README.md and team wiki.php artisan test:versioned --verbose
phpunit.xml.feature)..env.--parallel).phpunit.xml.{env}).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Package unavailable | Tests fail | Fallback to phpunit.xml |
| Invalid config selected | PHPUnit errors | Validate configs pre-execution |
| CI environment misconfiguration | Flaky tests | Default to phpunit.xml.ci |
| Laravel/PHPUnit version conflict | Tests break | Pin versions in composer.json |
How can I help you explore Laravel packages today?