grant_type=client_credentials vs. grant_type=password), enabling nuanced test scenarios.Http facade or GuzzleHttp\Client).Http::fake() alternatives) but lacks native Laravel support (e.g., no Http facade integration).FileResourceLoader reads files on every request).database/factories or a dedicated tests/fixtures directory?Http::fake() or libraries like mockery/vcr instead?guzzlehttp/promises backport).tests/TestCase.php or a dedicated HttpTestCase:
protected function getFakeServerClient(array $mappings, string $fixturesPath): Client {
$config = new ArrayConfiguration("https://api.example.com");
foreach ($mappings as $method => $data) {
$config->addResource($method, $data['url'], $data['fixture'], $data['status']);
}
return new Client([
'handler' => HandlerStack::create([
new FakeServer($config, new FileResourceLoader($fixturesPath))
])
]);
}
tests/fixtures/ with a clear structure (e.g., oauth/token_success.json).copy() or artisan commands to generate boilerplate fixtures.Middleware::handle()).Http facade, wrap the fake client in a service:
$this->app->singleton('fake.http.client', fn() => $this->getFakeServerClient($mappings, $fixturesPath));
Http::fake() integration).Http::fake()).createOAuthTokenFixture()).FileResourceLoader with in-memory cache).antwebes/guzzle-fake-server to a specific commit due to lack of releases.Http::fake() is more maintained but lacks conditional logic.vcr (for recording/replaying) or mockery (for mock objects) may be better long-term.--parallel).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Fixture file missing/misnamed | Tests fail silently or with cryptic errors. | Use assertFileExists() checks in setUp(). |
| Guzzle event listener not triggered | No responses returned (appears as network timeout). | Verify addSubscriber() is called. |
| Conditional mapping mismatch | Wrong response returned (e.g., success instead of error). | Add assertions for request params. |
| Guzzle v3.7 incompatibility | Runtime errors in production-like environments. | Isolate in tests/ only; use polyfills. |
| File permission issues | Loader fails to read fixtures. | Ensure tests/fixtures/ is writable. |
addPostResource with params).Http client.php artisan make:fixture oauth/token_success --status=200
How can I help you explore Laravel packages today?