php-vcr 0,1 travis-ci Packagist phpunit

Record your test suite's HTTP interactions and replay them during future test runs for fast, deterministic, accurate tests.


Build Status Dependency Status Code Coverage Scrutinizer Quality Score

This is a port of VCR for ruby.

Record your test suite’s HTTP interactions and replay them during future test runs for fast, deterministic, accurate tests. A bit of documentation can be found on the php-vcr website.

Disclaimer: Doing this in PHP is not as easy as in programming languages which support monkey patching (I’m looking at you, Ruby) – this project is not yet fully tested, so please use at your own risk!


  • Automatically records and replays your HTTP(s) interactions with minimal setup/configuration code.
  • Supports common http functions and extensions
    • everyting using streamWrapper: fopen(), fread(), file_get_contents(), … without any modification (except $http_response_header see #96)
    • SoapClient by adding \VCR\VCR\turnOn(); in your tests/bootstrap.php
    • curl(), by adding \VCR\VCR::turnOn(); in your tests/bootstrap.php
  • The same request can receive different responses in different tests – just use different cassettes.
  • Disables all HTTP requests that you don’t explicitly allow by setting the record mode
  • Request matching is configurable based on HTTP method, URI, host, path, body and headers, or you can easily implement a custom request matcher to handle any need.
  • The recorded requests and responses are stored on disk in a serialization format of your choice (currently YAML and JSON are built in, and you can easily implement your own custom serializer)
  • Supports PHPUnit annotations.

Usage example

Using static method calls:

class VCRTest extends \PHPUnit_Framework_TestCase
    public function testShouldInterceptStreamWrapper()
        // After turning on the VCR will intercept all requests

        // Record requests and responses in cassette file 'example'

        // Following request will be recorded once and replayed in future test runs
        $result = file_get_contents('');

        // To stop recording requests, eject the cassette

        // Turn off VCR to stop intercepting requests

    public function testShouldThrowExceptionIfNoCasettePresent()
            "Invalid http request. No cassette inserted. Please make sure to insert "
            . "a cassette in your unit test using VCR::insertCassette('name');"
        // If there is no cassette inserted, a request throws an exception

You can use annotations in PHPUnit by using phpunit-testlistener-vcr:

class VCRTest extends \PHPUnit_Framework_TestCase
     * @vcr unittest_annotation_test
    public function testInterceptsWithAnnotations()
        // Requests are intercepted and stored into  tests/fixtures/unittest_annotation_test.
        $result = file_get_contents('');

        $this->assertEquals('This is a annotation test dummy.', $result, 'Call was not intercepted (using annotations).');

        // VCR is automatically turned on and off.


Simply run the following command:

$ composer require --dev php-vcr/php-vcr


PHP-VCR depends on:

Composer installs all dependencies except extensions like curl.

Run tests

In order to run all tests you need to get development dependencies using composer:

composer install --dev
phpunit ./tests


The changelog has moved to the PHP-VCR releases page.

Old changelog entries:

  • 2014-10-23 Release 1.1.6: #73, #74, #75, improvements for JSON storage and binary requests.
  • 2014-09-11 Release 1.1.5: Fixes #58 #60, #61, #69 updated vendors and new record mode.
  • 2014-04-26 Release 1.1.4: Fixes #50, #52, #53, #54, #56 and better error messages.
  • 2014-04-12 Release 1.1.3: Fixes #48: Allows data to be passed to CURLOPT_POSTFIELDS.
  • 2014-02-27 Release 1.1.2: Fix for storing the request body.
  • 2014-02-27 Release 1.1.1: Fix for non-GET requests with Guzzle.
  • 2014-02-22 Release 1.1.0: Removes curl runkit library hook and additional cleanup.
  • 2014-02-19 Release 1.0.7: Adds query request matcher.
  • 2014-01-12 Release 1.0.6: Updates dependencies.
  • 2013-10-13 Release 1.0.5: Fixed SOAP support, refactorings.
  • 2013-07-22 Release 1.0.4: Updates dependencies.
  • 2013-06-05 Release 1.0.3: Added curl_rewrite (in addition to curl_runkit) to overwrite curl functions.
  • 2013-05-15 Release 1.0.0
  • 2013-05-15 Adds PHPUnit annotations using phpunit-testlistener-vcr
  • 2013-05-14 Easier API (static method calls)
  • 2013-02-22 Added YAML support
  • 2013-02-21 Added custom request matcher
  • 2013-02-21 Added JSON storage which uses less memory
  • 2013-02-21 Added support for binary data
  • 2013-02-20 Added Soap support
  • 2013-02-19 Curl hook fixes, more tests
  • 2013-02-18 First prototype


Copyright © 2013 Adrian Philipp. Released under the terms of the MIT license. See LICENSE for details.

Related Repositories



Record your test suite's HTTP interactions and replay them during future test runs for fast, deterministic, accurate tests. ...



Integrates PHPUnit with PHP-VCR. ...



Integrates php-vcr into Symfony and its web profiler. ...



[DEPRECATED] Examples for using PHP-VCR, check the main repo ...

Top Contributors

adri lapistano justincy johnmadrak aaa2000 dbu MrRio yateric chregu mdarse laland benzittlau jamiehannaford K-Phoen kasperg morrislaptop acorncom notFloran fterrier Anahkiasen s-chizhik stevemiketa troydavisson gsaulmon letrunghieu yethee


package version
dev phpunit/phpunit ^4.8|^5.0
sebastian/version ^1.0.3|^2.0
mikey179/vfsStream ^1.2
lapistano/proxy-object dev-master#d7184a479f502d5a0f96d0bae73566dbb498da8
friendsofphp/php-cs-fixer ^1.12
ext-curl *
beberlei/assert ^2.0
symfony/yaml ~2.1|^3.0
symfony/event-dispatcher ^2.4|^3.0


-   1.2.8 zip tar
-   1.2.7 zip tar
-   1.2.6 zip tar
-   1.2.5 zip tar
-   1.2.4 zip tar
-   1.2.3 zip tar
-   1.2.2 zip tar
-   1.2.1 zip tar
-   1.2 zip tar
-   1.1.8 zip tar
-   1.1.7 zip tar
-   1.1.6 zip tar
-   1.1.5 zip tar
-   1.1.4 zip tar
-   1.1.3 zip tar
-   1.1.2 zip tar
-   1.1.1 zip tar
-   1.1.0 zip tar
-   1.0.7 zip tar
-   1.0.6 zip tar
-   1.0.5 zip tar
-   1.0.4 zip tar
-   1.0.3 zip tar
-   1.0.2 zip tar
-   1.0.1 zip tar
-   1.0.0 zip tar