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.
HttpClient facade support).Http::fake() uses Guzzle 6/7 mocks).guzzlehttp/guzzle version clashes).Http::fake()).vcr for recording, pest/phpunit mock objects).guzzlehttp/psr7, mockery, or pest mocks) achieve the same goal with lower risk?replace or custom aliases?)vcr for HTTP recording) that could reduce reliance on mocking?| 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). |
For Laravel 5.x Projects:
composer require guzzle/plugin-mock:dev-main guzzlehttp/guzzle:^3.9
$mock = new \Guzzle\Plugin\Mock\MockPlugin();
$client = new \GuzzleHttp\Client(['plugins' => [$mock]]);
$mock->addResponse(new \GuzzleHttp\Psr7\Response(200, [], 'Mocked!'));
phpunit.xml to load Guzzle 3 autoloader.For Laravel 6+/7+/8+ Projects:
"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.// 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()]]);
}
}
Http::fake() or vcr).GuzzleHttp\Message\Response.Http::client() with this package.create_function).guzzle/plugin-mock (no releases; relies on subtree splits).Http::fake() helpers).| Scenario | Impact | Mitigation |
|---|---|---|
| Guzzle 3 breaks in PHP 8.x | Tests fail, no production impact | Pin PHP version or migrate. |
| Dependency conflicts (Guzzle |
How can I help you explore Laravel packages today?