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

Plugin Mock Laravel Package

guzzle/plugin-mock

guzzle/plugin-mock provides a mock plugin for Guzzle, letting you queue predefined responses and simulate HTTP requests during testing. Useful for isolating API clients, reproducing edge cases, and running fast, reliable unit tests without real network calls.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Use Case Alignment: This package is a Guzzle 3 mocking plugin, designed for testing HTTP clients in isolation. It fits well in architectures where:
    • HTTP clients (e.g., API integrations, web services) require deterministic testing (e.g., unit/integration tests).
    • Mocking external dependencies is critical (e.g., avoiding real API calls in CI/CD).
    • Legacy systems or projects still using Guzzle 3 (not Guzzle 6/7) are in use.
  • Laravel Compatibility: Laravel’s HTTP client (since v7+) defaults to Guzzle 6/7, making this package incompatible without significant refactoring. However, it could be leveraged in:
    • Legacy Laravel 5.x projects still using Guzzle 3.
    • Custom HTTP clients explicitly configured with Guzzle 3.
    • Testing layers where Guzzle 3 is intentionally isolated (e.g., legacy service containers).

Integration Feasibility

  • Dependencies:
    • Requires Guzzle 3.x (not auto-installed; must be manually included via Composer).
    • No Laravel-specific integrations (e.g., no HttpClient facade support).
  • Implementation Complexity:
    • Low for Guzzle 3 users: Drop-in replacement for real HTTP calls in tests.
    • High for Laravel 7+/Guzzle 6/7: Requires either:
      • Downgrading Guzzle (risky, breaks Laravel’s HTTP client).
      • Wrapping Guzzle 3 in a custom adapter (e.g., via PSR-18 interfaces).
  • Testing Scope:
    • Ideal for unit tests of services/classes directly using Guzzle 3.
    • Not suitable for Laravel’s built-in HTTP tests (e.g., Http::fake() uses Guzzle 6/7 mocks).

Technical Risk

  • Deprecation Risk: Guzzle 3 is end-of-life (released in 2014). No active maintenance; may break with PHP 8.x or modern Composer.
  • Isolation Risk: Mixing Guzzle 3 with Laravel’s Guzzle 6/7 could cause:
    • Dependency conflicts (e.g., guzzlehttp/guzzle version clashes).
    • Inconsistent behavior if both versions are loaded.
  • Testing Gaps:
    • No support for Laravel’s HTTP test helpers (e.g., Http::fake()).
    • Limited mocking capabilities compared to modern tools (e.g., vcr for recording, pest/phpunit mock objects).

Key Questions

  1. Why Guzzle 3?
    • Is this for a legacy Laravel 5.x project, or is there a specific need to avoid Guzzle 6/7?
    • Could modern alternatives (e.g., guzzlehttp/psr7, mockery, or pest mocks) achieve the same goal with lower risk?
  2. Integration Strategy
    • How will this coexist with Laravel’s default Guzzle 6/7? (e.g., via Composer replace or custom aliases?)
    • Are there plans to migrate to Guzzle 6/7, or is this a temporary solution?
  3. Testing Coverage
    • What percentage of HTTP calls use Guzzle 3? Is this package critical for CI/CD?
    • Are there alternatives (e.g., vcr for HTTP recording) that could reduce reliance on mocking?
  4. Long-Term Viability
    • What’s the exit strategy if Guzzle 3 breaks in future PHP/Laravel versions?
    • Is there budget/time to maintain a custom wrapper or adapter?

Integration Approach

Stack Fit

  • Target Environments:
    • Primary: Laravel 5.x projects using Guzzle 3.
    • Secondary: Custom Laravel services explicitly opting into Guzzle 3 (e.g., for backward compatibility).
  • Compatibility Matrix:
    Component Compatible? Notes
    Laravel 5.x ✅ Yes Native Guzzle 3 support.
    Laravel 6+/7+/8+ ❌ No Conflicts with default Guzzle 6/7.
    PHP 7.4+ ⚠️ Partial May require guzzlehttp/stream polyfills.
    PHP 8.x ❌ No Guzzle 3 lacks PHP 8 support.
    Composer ✅ Yes Installable via require (but risky).

Migration Path

  1. For Laravel 5.x Projects:

    • Step 1: Install via Composer:
      composer require guzzle/plugin-mock:dev-main guzzlehttp/guzzle:^3.9
      
    • Step 2: Replace real HTTP calls with mocks in tests:
      $mock = new \Guzzle\Plugin\Mock\MockPlugin();
      $client = new \GuzzleHttp\Client(['plugins' => [$mock]]);
      $mock->addResponse(new \GuzzleHttp\Psr7\Response(200, [], 'Mocked!'));
      
    • Step 3: Update phpunit.xml to load Guzzle 3 autoloader.
  2. For Laravel 6+/7+/8+ Projects:

    • Option A (High Risk): Downgrade Guzzle via Composer:
      "require": {
        "guzzlehttp/guzzle": "3.9",
        "guzzle/plugin-mock": "dev-main"
      },
      "replace": {
        "guzzlehttp/guzzle": "6.5"
      }
      
      Risk: Breaks Laravel’s HTTP client; may require patching core files.
    • Option B (Recommended): Isolate Guzzle 3 in a custom service:
      // app/Services/LegacyGuzzleClient.php
      use GuzzleHttp\Client as Guzzle3Client;
      use Guzzle\Plugin\Mock\MockPlugin;
      
      class LegacyGuzzleClient {
          public function __construct() {
              $this->client = new Guzzle3Client(['plugins' => [new MockPlugin()]]);
          }
      }
      
    • Option C: Migrate to modern mocking (e.g., Http::fake() or vcr).

Compatibility

  • Guzzle 3 vs. 6/7:
    • Breaking Changes: Guzzle 6/7 uses PSR-7; Guzzle 3 uses its own interfaces. Mock responses must align with Guzzle 3’s GuzzleHttp\Message\Response.
    • Laravel HTTP Client: Incompatible. Avoid using Http::client() with this package.
  • PHP Version: Tested only on PHP <7.4. May fail on PHP 8.x due to:
    • Deprecated functions (e.g., create_function).
    • Missing type hints in Guzzle 3.

Sequencing

  1. Phase 1: Pilot in a single test suite (e.g., legacy API service).
  2. Phase 2: Gradually replace real HTTP calls with mocks in CI.
  3. Phase 3: Evaluate migration to Guzzle 6/7 or modern alternatives.
  4. Phase 4: Deprecate Guzzle 3 if no longer needed.

Operational Impact

Maintenance

  • Short-Term:
    • Low Effort: Mocking logic is contained in tests.
    • High Risk: Guzzle 3 dependencies may break with PHP updates.
  • Long-Term:
    • Technical Debt: Maintaining two Guzzle versions (3 and 6/7) increases complexity.
    • Security: Guzzle 3 lacks security patches (e.g., CVE fixes in Guzzle 6/7).
  • Dependencies:
    • Requires manual updates to guzzle/plugin-mock (no releases; relies on subtree splits).

Support

  • Debugging:
    • Mock failures may be harder to debug due to Guzzle 3’s outdated error handling.
    • No Laravel-specific support (e.g., Http::fake() helpers).
  • Community:
    • No active maintainers; issues may go unanswered.
    • Limited Stack Overflow/Laravel community knowledge of Guzzle 3.

Scaling

  • Test Performance:
    • Mocks are lightweight, but Guzzle 3’s overhead may be higher than modern alternatives.
  • Team Onboarding:
    • Developers unfamiliar with Guzzle 3 may struggle with:
      • Mock response formatting.
      • Guzzle 3’s non-PSR-7 interfaces.
  • Infrastructure:
    • No impact on production (tests only), but CI/CD pipelines must support Guzzle 3.

Failure Modes

Scenario Impact Mitigation
Guzzle 3 breaks in PHP 8.x Tests fail, no production impact Pin PHP version or migrate.
Dependency conflicts (Guzzle
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.
terminal42/code-quality-tools
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