--- layout: default title: PHP-VCR | Record HTTP interactions while testing ---
...and replay them during future test runs for fast, deterministic and accurate tests.
Disclaimer: Doing this in PHP is not as easy as in programming languages which support monkey patching – this project is not yet fully tested, so please use at your own risk!
Instead of manually mocking API calls for your tests, record HTTP requests and replay them later.
If you run hundreds of tests, you don't want to hit a real API all the time. This slows down your test suite quite a bit. The faster your tests are, the faster you can iterate over code changes.
Can you run integration tests on your notebook? Testing against live APIs require those APIs to be online all the time, and you have to be online as well. Free yourself from those dependencies.
One reason for manual mocking is, to get the exact same response every time your app makes a request. Not coding all those mocks for API responses speeds up your development process.
This is a fork of the fabulous VCR for ruby library.
Easy to use and extendable.
Automatically records and replays HTTP(s) interactions with minimal setup. No modifications to your production code necessary.
Supports common http functions and extensions like streamWrapper (fopen(), fread(), file_get_contents()), SoapClient and cUrl.
Disables all HTTP requests that you don't explicitly allow (except if configured).
Easily configure request matching or add custom request matchers. Store HTTP interactions on disk in YAML or JSON.
Supports PHPUnit. Recorded requests and responses can easily be inspected and edited.
Automatically filters confidential or private information like emails, tokens and passwords.
Still WIP but there is a little documentation.
Simple installation using composer. Turn on PHP-VCR in your test bootstrap file.
More information