Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Phpunit Select Config Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Purpose Alignment: This package solves a niche but critical problem in multi-versioned PHP/Laravel projects where PHPUnit configuration formats differ across versions (e.g., PHPUnit 8 vs. 10). It aligns with Laravel’s testing ecosystem by enabling dynamic test configuration selection without modifying core test logic. Ideal for:
    • Monorepos (e.g., Laravel + legacy plugins).
    • CI/CD pipelines requiring version-specific test suites.
    • Feature-flagged testing (e.g., @group or versioned configs).
  • Laravel Synergy: Laravel’s php artisan test and TestCase bootstrapping can leverage this package to abstract config selection, reducing manual intervention in CI/CD scripts. However, it does not replace Laravel’s built-in test helpers (e.g., refreshDatabase()) but can complement them by managing config files.
  • Opportunity Cost: If the project uses static configs or PHPUnit’s native --configuration, this package adds minimal value. The 44.59 "opportunity" score suggests high potential for projects with complex test environments.

Integration Feasibility

  • Low-Friction Integration:
    • Composer Install: Zero runtime dependencies (dev-only).
    • CLI Wrapper: Replaces phpunit calls with phpunit-select-config, enabling gradual adoption.
    • Artisan Integration: Can be wrapped in a custom command (e.g., php artisan test:versioned) for Laravel-native workflows.
  • Key Challenges:
    • Laravel TestCase Overrides: May conflict with Laravel’s TestCase bootstrapping (e.g., service providers, app bindings). Requires testing.
    • Config File Naming: Enforcing conventions (e.g., phpunit.9.xml, phpunit.10.xml) adds discipline but reduces flexibility.
    • Debugging Complexity: Stack traces may obscure the package’s role if config selection fails.

Technical Risk

Risk Severity Mitigation
Unmaintained Package High Fork and maintain; or replace with a custom script (e.g., Bash/PHP wrapper).
Laravel TestCase Conflicts Medium Test with TestCase overrides; document limitations.
CI Pipeline Breaks Medium Implement fallback to default phpunit.xml in CI.
Performance Overhead Low Benchmark in CI; negligible for most use cases.
Version Lock-In Low Pin PHPUnit version in composer.json to avoid breakage.

Key Questions

  1. Does the project need dynamic configs, or is a static phpunit.xml with includes sufficient?
    • If static works, this package is overkill.
  2. How will this interact with Laravel’s TestCase and service providers?
    • Test with a minimal TestCase to ensure no bootstrapping conflicts.
  3. What’s the fallback if the package fails?
    • Default to phpunit.xml or a custom error handler.
  4. Will this integrate with Laravel’s pest or lighthouse?
    • Pest may not support this natively; Lighthouse could adapt via custom runners.
  5. How will CI/CD handle config selection?
    • Use environment variables (e.g., TEST_CONFIG=phpunit.xml.ci) for flexibility.

Integration Approach

Stack Fit

  • Primary Fit:
    • Laravel + PHPUnit: Native integration via Artisan commands or CI scripts.
    • Monorepos: Ideal for Laravel + plugins/legacy code with versioned tests.
    • CI/CD: Reduces manual config switching in GitHub Actions/Jenkins.
  • Secondary Fit:
    • WordPress/Plugin Projects: Automattic’s origin suggests WordPress compatibility.
    • Multi-Environment Testing: Useful for staging/production-like test configs.
  • Non-Fit:
    • Pest Framework: May require custom adapters (Pest uses phpunit.xml differently).
    • Non-PHPUnit Tests: Incompatible with tools like Codeception or Jest.

Migration Path

  1. Phase 1: Local Validation
    • Install and test the package locally:
      composer require --dev automattic/phpunit-select-config
      ./vendor/bin/phpunit-select-config phpunit.*.xml.dist
      
    • Create versioned configs (e.g., phpunit.9.xml, phpunit.10.xml) and validate selection.
  2. Phase 2: Artisan Integration
    • Add a custom command (e.g., 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();
          }
      }
      
    • Replace php artisan test with php artisan test:versioned in local workflows.
  3. Phase 3: CI/CD Adoption
    • Update CI scripts to use the package:
      # .github/workflows/test.yml
      - run: php artisan test:versioned phpunit.xml.ci
      
    • Use environment variables for flexibility:
      TEST_CONFIG=phpunit.xml.feature-x php artisan test:versioned
      
  4. Phase 4: Laravel Core (Optional)
    • Override Laravel’s TestWorker to use the package’s runner:
      // app/Providers/AppServiceProvider.php
      public function boot() {
          if ($this->app->runningUnitTests()) {
              $config = config('testing.config');
              $runner = new Runner($config);
              $runner->runTests();
          }
      }
      

Compatibility

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, etc.).
Pest Limited support; may require custom pest.php config overrides.
Lighthouse Possible with custom test runners, but untested.

Sequencing

  1. Assess Pain Points:
    • Document current test config management (e.g., manual phpunit --configuration calls).
    • Identify use cases (e.g., "We need PHPUnit 9 for feature X and 10 for feature Y").
  2. Pilot with a Single Config:
    • Start with one versioned config (e.g., phpunit.xml.ci) in CI.
  3. Expand Gradually:
    • Add more configs (e.g., phpunit.xml.feature, phpunit.xml.legacy).
  4. Automate Config Selection:
    • Use .env or CI variables to control configs dynamically.
  5. Monitor and Iterate:
    • Track test failures due to config mismatches.
    • Refine naming conventions (e.g., phpunit.{version}.xml).

Operational Impact

Maintenance

  • Proactive Tasks:
    • Dependency Management:
      • Pin PHPUnit version in composer.json to avoid breakage.
      • Monitor upstream Jetpack repo for updates (or fork).
    • Config Validation:
      • Add a pre-test hook to validate selected configs (e.g., phpunit --dry-run).
    • Documentation:
      • Update README.md with config naming conventions.
      • Add a CONTRIBUTING.md section for test config management.
  • Reactive Tasks:
    • Fallback Mechanism:
      • Implement a default config (e.g., phpunit.xml) if the package fails.
    • Debugging:
      • Log config selection failures to CI artifacts.
      • Add a --debug flag to the Artisan command.

Support

  • Debugging Workflow:
    1. Config Selection Failures:
      • Check if the correct phpunit.{version}.xml exists.
      • Verify PHPUnit version matches the config (e.g., phpunit --version).
    2. Test Failures:
      • Run with --debug to see selected config:
        php artisan test:versioned --debug
        
    3. CI-Specific Issues:
      • Ensure TEST_CONFIG environment variables are set.
  • Team Training:
    • Onboarding:
      • 1-hour workshop on config naming and Artisan command usage.
    • Documentation:
      • Example workflows for local dev vs. CI.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
directorytree/privacy-filter-classifier
directorytree/privacy-filter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes
splash/toolkit
testo/output-teamcity
testo/bridge-symfony
spatie/flare-daemon-runtime