Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

http-vcr — record and replay HTTP requests in PHP tests

http-vcr records real HTTP interactions the first time your tests run, and replays them on every run after that — so the test suite for “the code that talks to Shopify/Stripe/Zendesk” is fast, deterministic, and doesn’t need network access or API credentials in CI.

It works by decorating a PSR-18 HTTP client (Psr\Http\Client\ClientInterface). Anything that already speaks PSR-18 — Guzzle 7+, Symfony’s Psr18Client, php-http’s clients — works with zero configuration. Recording and replay happen inside the VcrClient instance you construct, so there is no process-wide state to install or reset between tests.

$vcr = new VcrClient($realClient, cassette: 'shopify/get-product');

$response = $vcr->sendRequest($request);
// first run: real request happens, response is recorded to tests/Cassettes/shopify/get-product.json
// every run after: no network call, the recorded response is replayed

That first run records without any extra setup on a developer machine, and refuses to record on CI — see Record Modes for how that’s decided and how to override it in either direction.

Where to go next