Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
This branch is 603 commits behind php-vcr:master.

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


Build Status Dependency Status Coverage Status

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.

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
    • SoapClient by adding \VCR\VCR\turnOn(); in your tests/boostrap.php
    • curl(), either using runkit extension and runkit.internal_override=1 in your php.ini or by adding \VCR\VCR\turnOn(); in your tests/boostrap.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 (except SoapClient if not configured).
  • 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.
  • Todo: Recorded requests and responses can easily be inspected and edited.
  • Todo: Automatically filters confidential or private information like passwords, auth tokens and emails.
  • Todo: Automatically re-records cassettes on a configurable regular interval to keep them fresh and current.
  • Todo: Has a good documentation ;-)

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.


Add php-vcr to your composer.json.

  "php-vcr/php-vcr": "dev-master"
composer install


PHP-VCR depends on:

  • PHP 5.3+
  • Curl extension
  • HTTP library Guzzle
  • symfony/yaml
  • beberlei/assert
  • (optional) runkit extension with runkit.internal_override=1 in php.ini if you want to intercept curl

Composer installs all dependencies except extensions like curl or runkit.

Run tests

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

composer install --dev
phpunit ./tests


  • 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 (c) 2013 Adrian Philipp. Released under the terms of the MIT license. See LICENSE for details.


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







No packages published


  • PHP 100.0%