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 Bridge Laravel Package

symfony/phpunit-bridge

Symfony PHPUnit Bridge adds utilities around PHPUnit, with a focus on managing and asserting deprecation notices for smoother upgrades. It helps track, filter, and report deprecations during test runs, making CI output cleaner and migrations safer.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Seamless Laravel Integration: The package is designed for PHPUnit, which Laravel already uses as its default testing framework. It integrates natively with Laravel’s test suite (via phpunit.xml or phpunit.php configuration) without requiring architectural changes.
  • Symfony Compatibility: While Laravel is not Symfony, the bridge is widely used in Symfony projects and has no Laravel-specific dependencies. It leverages PHPUnit’s core features, making it a drop-in solution for Laravel’s existing test infrastructure.
  • Deprecation Management: The primary value—automated deprecation tracking—aligns perfectly with Laravel’s long-term roadmap (e.g., PHP 8.4+ support, Symfony dependency upgrades). It bridges the gap between PHPUnit’s deprecation warnings and Laravel’s test assertions.
  • Modular Design: The package is lightweight (no monolithic dependencies) and focuses solely on PHPUnit utilities, reducing bloat in the test stack.

Integration Feasibility

  • Zero Laravel-Specific Overhead: The bridge works out-of-the-box with Laravel’s default phpunit setup. No custom bootstrapping or service provider modifications are required.
  • Configuration Flexibility: Supports both annotation-based (@group) and attribute-based (#[Group]) PHPUnit configurations, ensuring compatibility with Laravel’s evolving test syntax (PHPUnit 9.x+).
  • CI/CD Readiness: Designed for automated deprecation checks, it integrates cleanly with Laravel Forge, GitHub Actions, or CircleCI via PHPUnit’s exit codes (e.g., failing builds on deprecation warnings).
  • Backward Compatibility: Works with PHPUnit 8.x–10.x, covering Laravel’s supported PHPUnit versions (Laravel 9+ uses PHPUnit 9+).

Technical Risk

Risk Mitigation Strategy Severity
PHPUnit Version Conflicts Test locally with Laravel’s PHPUnit version (e.g., phpunit/phpunit:^9.5) before CI integration. Low
Deprecation Overload Start with opt-in deprecation checks (e.g., ExpectUserDeprecationMessageTrait) before enforcing strict mode. Medium
Test Suite Slowdown Benchmark impact on test execution time; cache deprecation checks if performance is critical. Low
Custom Test Listeners Audit existing listeners for conflicts with the bridge’s TestCase patching. Medium
PHP 8.4+ Compatibility Verify ClockMock/DnsMock features work with Laravel’s PHP version (e.g., PHP 8.2+). Low

Key Questions for the Team

  1. Deprecation Strategy:
    • Should deprecation warnings fail builds by default, or start as warnings with an opt-in enforcement phase?
  2. CI/CD Integration:
    • How should deprecation failures be surfaced (e.g., GitHub Actions annotations, Slack alerts)?
  3. Test Coverage Scope:
    • Should deprecation checks apply to all tests or only critical paths (e.g., feature tests)?
  4. PHPUnit Version:
    • Is the team using PHPUnit 9.x or 10.x? The bridge’s ClockMock/DnsMock features require PHPUnit 10+.
  5. Legacy Code Impact:
    • Are there existing deprecation suppressions (e.g., @expectedDeprecation) that need migration?
  6. Performance Baseline:
    • What’s the acceptable test suite slowdown for deprecation checks? (Benchmark with phpunit --debug.)
  7. Symfony Component Usage:
    • Does the project use Symfony components (e.g., HTTP Client, Mailer) that could benefit from ClockMock/DnsMock?

Integration Approach

Stack Fit

  • Laravel Native: The bridge requires no Laravel-specific changes—it works with Laravel’s default:
    • phpunit.xml configuration.
    • tests/TestCase base class.
    • Artisan phpunit command.
  • PHPUnit Compatibility:
    • PHPUnit 9.x: Use v7.x of the bridge (e.g., symfony/phpunit-bridge:^7.4).
    • PHPUnit 10.x: Use v8.x (e.g., symfony/phpunit-bridge:^8.0) for ClockMock/DnsMock.
  • Symfony Synergy:
    • If using Symfony components (e.g., symfony/http-client), the bridge’s ClockMock can mock time-dependent logic in tests.
    • Laravel’s Http facade (which uses Symfony’s HttpClient) can leverage these mocks for testing.

Migration Path

  1. Add Dependency:
    composer require --dev symfony/phpunit-bridge "^7.4"  # For PHPUnit 9.x
    # OR
    composer require --dev symfony/phpunit-bridge "^8.0"  # For PHPUnit 10.x
    
  2. Configure PHPUnit: Update phpunit.xml to enable deprecation checks:
    <phpunit>
        <extensions>
            <extension class="Symfony\Bridge\PhpUnit\DeprecationErrorListener"/>
        </extensions>
    </phpunit>
    
  3. Opt-In Deprecation Testing: Use ExpectUserDeprecationMessageTrait in critical tests:
    use Symfony\Bridge\PhpUnit\ExpectUserDeprecationMessageTrait;
    
    class DeprecationTest extends TestCase
    {
        use ExpectUserDeprecationMessageTrait;
    
        public function testDeprecatedFeature()
        {
            $this->expectUserDeprecationMessage('Deprecated feature used');
    
            // Test code that triggers deprecation.
        }
    }
    
  4. CI/CD Enforcement: Configure PHPUnit to fail on deprecations in .github/workflows/tests.yml:
    - name: Run tests
      run: php artisan test -- --fail-on-deprecation
    
  5. Gradual Rollout:
    • Phase 1: Add dependency and run tests locally to identify existing deprecations.
    • Phase 2: Fix critical deprecations in CI (fail builds).
    • Phase 3: Enforce ExpectUserDeprecationMessageTrait for new tests.

Compatibility

Component Compatibility Notes
Laravel 9/10 ✅ Full compatibility (PHPUnit 9.x/10.x) Use ^7.4 or ^8.0 of the bridge.
PestPHP ⚠️ Partial (PHPUnit under the hood) May require custom setup.
Custom Test Listeners ⚠️ Potential conflicts with TestCase patching Audit existing listeners.
PHP 8.2+ ✅ Supported (PHP 8.4+ for ClockMock features) Check Laravel’s PHP version support.
Symfony Components ✅ Enhanced (e.g., ClockMock for HTTP Client tests) Beneficial if using Symfony packages.

Sequencing

  1. Audit Existing Tests: Run php artisan test -- --debug to identify current deprecation warnings.
  2. Update Dependencies: Ensure PHPUnit and Symfony bridge versions align (e.g., PHPUnit 10.x → bridge ^8.0).
  3. Configure CI/CD: Add deprecation checks to the test matrix before enforcing failures.
  4. Developer Training: Train teams on ExpectUserDeprecationMessageTrait and @expectedDeprecation.
  5. Monitor Impact: Track test suite performance and false positives in the first 2 weeks.

Operational Impact

Maintenance

  • Low Overhead:
    • The bridge is maintained by Symfony, with updates aligned to PHPUnit releases.
    • Laravel teams benefit from Symfony’s testing expertise without maintenance burden.
  • Dependency Updates:
    • Update the bridge in sync with PHPUnit major versions (e.g., upgrade to ^8.0 when moving to PHPUnit 10).
    • Monitor Symfony’s UPGRADE.md for breaking changes.
  • Deprecation Lifecycle:
    • Use the bridge to sunset deprecated Laravel/Symfony features systematically (e.g., Illuminate\Support\Facades\Route::controller()).

Support

  • Troubleshooting:
    • Common issues (e.g., TestCase patching failures) are documented in Symfony’s docs.
    • Laravel’s community can leverage Symfony’s issue tracker
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport
twbs/bootstrap4