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 Testlistener Vcr Laravel Package

php-vcr/phpunit-testlistener-vcr

PHPUnit TestListener integrating PHP-VCR via @vcr annotations. Automatically turns VCR on/off per test and records/replays HTTP interactions using named cassettes. Install with Composer and register the listener in phpunit.xml.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Use Case Alignment (Unchanged, but clarified with PHP 8.1+ focus)

    • Confirmed alignment with Laravel 9+/10+ (PHP 8.1+) for deterministic HTTP testing.
    • No breaking changes to core use cases (record/replay for API-heavy apps).
    • PHP 8.0 support dropped: Explicitly aligns with Laravel’s modern stack (PHP 8.1+).
  • Laravel Synergy (Updated for PHP 8.1+)

    • Native integration with Laravel’s Http client and HttpTests remains seamless.
    • PHP 8.1 features (e.g., union types, attributes) may enable cleaner annotations (e.g., #[\VCR\Test]).
    • PestPHP compatibility: Still limited but may improve with PHPUnit 10’s attribute support.
  • Anti-Patterns (Reinforced)

    • Storage bloat and environment drift risks persist; no changes to mitigate these.

Integration Feasibility

  • Dependencies (Updated for PHP 8.1+)

    • PHP 8.0 dropped: Now strictly Laravel 9+/10+ (PHP 8.1+).
    • PHP-VCR core (v3.3.0+) required; ensure php-vcr/php-vcr is pinned to ^3.3.
    • No Laravel-specific breaking changes, but test with:
      composer require php-vcr/phpunit-testlistener-vcr:^3.3 php-vcr/php-vcr:^3.3
      
  • Testing Framework (Clarified)

    • PHPUnit 9.5+ (Laravel’s default) fully supported.
    • PestPHP: Still experimental; may require custom adapters for attributes (PHP 8.1+).

Technical Risk

Risk Area Severity Mitigation Strategy Update for 3.3.0
PHP 8.0+ Only High Drop support for Laravel 8.x (PHP 7.4/8.0). Action Required: Audit CI/CD for PHP 8.0.
Cassette Management High Use vcr_mode: once + CI gating. No change.
Middleware Conflicts Medium Exclude via ignoreMiddleware. No change.
Parallel Test Failures Low Unique cassette paths per test class. No change.
Laravel-Specific Quirks Low Test with Http::fake() fallback. No change.

Key Questions (Updated)

  1. API Stability (Unchanged)
  2. CI/CD Workflow (Unchanged)
  3. Team Adoption (Updated)
    • New: Will developers need training on PHP 8.1+ features (e.g., attributes for annotations)?
  4. Fallback Strategy (Unchanged)
  5. Performance (Unchanged)
  6. Laravel Ecosystem (Updated)
    • New: Are there conflicts with Laravel 10’s new testing helpers (e.g., assertJson() improvements)?
  7. PHP 8.0+ Migration (Added)
    • How will the team phase out PHP 8.0 support in CI/CD (e.g., Laravel 8.x projects)?

Integration Approach

Stack Fit (Updated for PHP 8.1+)

  • Laravel Compatibility:

    • Laravel 10+: Full support; leverage PHP 8.1’s attributes for cleaner test annotations:
      #[VCR('my_test')]
      public function test_api_call(): void { ... }
      
    • Laravel 9.x: Works but may miss attribute-based features.
    • Service Container: Bind VCR\VCR interface to Laravel’s HttpClient for DI:
      $this->app->bind(VCR::class, function () {
          return VCR::initStorage('tests/_vcr_cassettes');
      });
      
  • Tooling Synergy (Updated)

    • PHP 8.1+ Features: Use union types in custom VCR configurations:
      VCR::configure([
          'filter' => ['hosts' => ['api.example.com' | 'staging.api.example.com']],
      ]);
      
    • GitHub Actions: Update matrix to drop PHP 8.0:
      strategy:
        matrix:
          php: ['8.1', '8.2', '8.3']  # Remove 8.0
      

Migration Path (Updated for PHP 8.1+)

  1. Phase 0: PHP 8.1+ Upgrade (New)

    • Update composer.json:
      "require": {
          "php": "^8.1",
          "php-vcr/phpunit-testlistener-vcr": "^3.3",
          "php-vcr/php-vcr": "^3.3"
      }
      
    • Run composer update and test with Laravel’s PHP 8.1 baseline.
  2. Phase 1: Pilot Phase (Unchanged)

    • Start with Laravel 10+ projects to leverage attribute support.
  3. Configuration (Updated for Attributes)

    • PHPUnit XML (unchanged):
      <listeners>
          <listener class="VCR\TestListener\VCRListener"/>
      </listeners>
      
    • Attribute-Based Tests (New):
      use VCR\Test;
      
      #[Test\VCR('users/create')]
      public function test_user_creation(): void { ... }
      
  4. CI/CD Integration (Updated)

    • PHP 8.0 Removal:
      - name: Set up PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: '8.1'  # Remove 8.0
      

Compatibility (Updated)

  • Laravel Versions:

    • Supported: Laravel 9+ (PHP 8.1+). Laravel 8.x not supported in 3.3.0.
    • Lumen: Requires manual PHPUnit setup; no Laravel-specific helpers.
  • PHPUnit Versions:

    • Supported: PHPUnit 9.5+ (Laravel’s default). PHPUnit 10 may introduce attribute conflicts; monitor PHP-VCR issues.
  • HTTP Clients:

    • Primary: Guzzle (Laravel’s Http client).
    • Secondary: Symfony’s Client (if used).
    • Unsupported: Custom PSR-18 clients without VCR integration.

Sequencing (Updated)

  1. Phase 0: Upgrade to PHP 8.1+ and Laravel 9+/10+.
  2. Phase 1: Record cassettes for stable APIs using attribute annotations.
  3. Phase 2: Migrate legacy tests from @vcr to #[\VCR\Test].
  4. Phase 3: Enforce cassette reviews in PRs (CI checks).
  5. Phase 4: Explore dynamic cassette naming (e.g., include Laravel version).

Operational Impact

Maintenance (Updated for PHP 8.1+)

  • Cassette Updates:

    • PHP 8.1+ Features: Use attributes for selective recording:
      #[VCR('dynamic', mode: 'once')]  // Records once, then replays
      public function test_dynamic_api(): void { ... }
      
    • Process: Automate updates with GitHub Actions:
      - name: Update Cassettes
        run: phpunit --vcr-mode=once --filter="DynamicTest"
        if: github.ref == 'refs/heads/main'
      
  • Storage:

    • Size: No change, but PHP 8.1’s typed properties can help manage cassette metadata.
    • Cleanup: Use phpunit --vcr-cleanup or a custom Artisan command:
      // app/Console/Commands/CleanVCR.php
      public function handle() {
          $cassettes = File::allFiles(storage_path('tests/_vcr_cassettes'));
          // Delete cassettes for deleted tests...
      }
      
  • Configuration Drift:

    • Risk: Cassettes tied to Laravel 10’s auth middleware (e.g., EnsureFrontendRequestsAreStateful).
    • Mitigation: Use environment-specific cassette paths:
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.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor