PHPackages                             phpjit/php-vcr - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. phpjit/php-vcr

ActiveLibrary

phpjit/php-vcr
==============

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

1.5.2(5y ago)0793MITPHPPHP &gt;=7.2

Since May 15Pushed 4y agoCompare

[ Source](https://github.com/taciclei/php-vcr)[ Packagist](https://packagist.org/packages/phpjit/php-vcr)[ RSS](/packages/phpjit-php-vcr/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (10)Versions (49)Used By (0)

[![PHP-VCR](https://user-images.githubusercontent.com/133832/27151811-0d95c6c4-514c-11e7-834e-eff1eec2ea16.png)](https://user-images.githubusercontent.com/133832/27151811-0d95c6c4-514c-11e7-834e-eff1eec2ea16.png)

[![Build Status](https://github.com/php-vcr/php-vcr/actions/workflows/tests.yml/badge.svg)](https://github.com/php-vcr/php-vcr/actions/workflows/tests.yml)[![Code Coverage](https://camo.githubusercontent.com/75d34d3186f2b096e6ffd0514652760deab7fecb9a4bc679142f63933e767ee6/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7068702d7663722f7068702d7663722f6261646765732f636f7665726167652e706e673f733d31356366313634346338636633376138363865303363666261383039613565323463373866323835)](https://scrutinizer-ci.com/g/php-vcr/php-vcr/)[![Scrutinizer Quality Score](https://camo.githubusercontent.com/6e4cee2a1d2ca04a24a2ccb277446c5b07a436cf4671050c545732f337202daa/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7068702d7663722f7068702d7663722f6261646765732f7175616c6974792d73636f72652e706e673f733d34663633386462636135656235316662396338376131646434356335646639343638376438356264)](https://scrutinizer-ci.com/g/php-vcr/php-vcr/)

This is a port of the [VCR](http://github.com/vcr/vcr) Ruby library to PHP.

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](http://php-vcr.github.io).

Disclaimer: Doing this in PHP is not as easy as in programming languages which support monkey patching (I'm looking at you, Ruby)

Features
--------

[](#features)

- Automatically records and replays your HTTP(s) interactions with minimal setup/configuration code.
- Supports common http functions and extensions
    - everything using [streamWrapper](http://php.net/manual/en/class.streamwrapper.php): fopen(), fread(), file\_get\_contents(), ... without any modification (except `$http_response_header` see #96)
    - [SoapClient](http://www.php.net/manual/en/soapclient.soapclient.php) 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](http://php-vcr.github.io/documentation/configuration/)
- [Request matching](http://php-vcr.github.io/documentation/configuration/) 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
-------------

[](#usage-example)

Using static method calls:

```
class VCRTest extends TestCase
{
    public function testShouldInterceptStreamWrapper()
    {
        // After turning on the VCR will intercept all requests
        \VCR\VCR::turnOn();

        // Record requests and responses in cassette file 'example'
        \VCR\VCR::insertCassette('example');

        // Following request will be recorded once and replayed in future test runs
        $result = file_get_contents('http://example.com');
        $this->assertNotEmpty($result);

        // To stop recording requests, eject the cassette
        \VCR\VCR::eject();

        // Turn off VCR to stop intercepting requests
        \VCR\VCR::turnOff();
    }

    public function testShouldThrowExceptionIfNoCasettePresent()
    {
        $this->setExpectedException(
            'BadMethodCallException',
            "Invalid http request. No cassette inserted. Please make sure to insert "
            . "a cassette in your unit test using VCR::insertCassette('name');"
        );
        \VCR\VCR::turnOn();
        // If there is no cassette inserted, a request throws an exception
        file_get_contents('http://example.com');
    }
}
```

You can use annotations in PHPUnit by using [phpunit-testlistener-vcr](https://github.com/php-vcr/phpunit-testlistener-vcr):

```
class VCRTest extends TestCase
{
    /**
     * @vcr unittest_annotation_test
     */
    public function testInterceptsWithAnnotations()
    {
        // Requests are intercepted and stored into  tests/fixtures/unittest_annotation_test.
        $result = file_get_contents('http://google.com');

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

        // VCR is automatically turned on and off.
    }
}
```

Installation
------------

[](#installation)

Simply run the following command:

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

Dependencies
------------

[](#dependencies)

PHP-VCR depends on:

- PHP 7.2+
- Curl extension
- [symfony/event-dispatcher](https://github.com/symfony/event-dispatcher)
- [symfony/yaml](https://github.com/symfony/yaml)
- [beberlei/assert](https://github.com/beberlei/assert)

Composer installs all dependencies except extensions like curl.

Run tests
---------

[](#run-tests)

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

```
composer install
composer test
```

Changelog
---------

[](#changelog)

**The changelog has moved to the [PHP-VCR releases page](https://github.com/php-vcr/php-vcr/releases).**

[Old changelog entries](docs/old-changelog.md)

Copyright
---------

[](#copyright)

Copyright (c) 2013-2016 Adrian Philipp. Released under the terms of the MIT license. See LICENSE for details. [Contributors](https://github.com/php-vcr/php-vcr/graphs/contributors)

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor1

Top contributor holds 59.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~68 days

Total

43

Last Release

1877d ago

PHP version history (2 changes)1.0.0PHP &gt;=5.3.15

1.5.0alpha0PHP &gt;=7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/5f4ac249c30538bf831ec4147864e6827b3ff37088251071e4e5142d50ecd4e6?d=identicon)[taciclei](/maintainers/taciclei)

---

Top Contributors

[![adri](https://avatars.githubusercontent.com/u/133832?v=4)](https://github.com/adri "adri (424 commits)")[![JeroenVanOort](https://avatars.githubusercontent.com/u/5616838?v=4)](https://github.com/JeroenVanOort "JeroenVanOort (60 commits)")[![moufmouf](https://avatars.githubusercontent.com/u/1290952?v=4)](https://github.com/moufmouf "moufmouf (52 commits)")[![renatomefi](https://avatars.githubusercontent.com/u/823634?v=4)](https://github.com/renatomefi "renatomefi (48 commits)")[![lapistano](https://avatars.githubusercontent.com/u/95115?v=4)](https://github.com/lapistano "lapistano (29 commits)")[![pauladams8](https://avatars.githubusercontent.com/u/37362614?v=4)](https://github.com/pauladams8 "pauladams8 (14 commits)")[![justincy](https://avatars.githubusercontent.com/u/1037458?v=4)](https://github.com/justincy "justincy (11 commits)")[![kornrunner](https://avatars.githubusercontent.com/u/725986?v=4)](https://github.com/kornrunner "kornrunner (10 commits)")[![johnmadrak](https://avatars.githubusercontent.com/u/2885480?v=4)](https://github.com/johnmadrak "johnmadrak (8 commits)")[![aaa2000](https://avatars.githubusercontent.com/u/163941?v=4)](https://github.com/aaa2000 "aaa2000 (7 commits)")[![janvernieuwe](https://avatars.githubusercontent.com/u/7813447?v=4)](https://github.com/janvernieuwe "janvernieuwe (6 commits)")[![MrRio](https://avatars.githubusercontent.com/u/47539?v=4)](https://github.com/MrRio "MrRio (5 commits)")[![dbu](https://avatars.githubusercontent.com/u/76576?v=4)](https://github.com/dbu "dbu (5 commits)")[![alnorth](https://avatars.githubusercontent.com/u/672745?v=4)](https://github.com/alnorth "alnorth (4 commits)")[![endorama](https://avatars.githubusercontent.com/u/526307?v=4)](https://github.com/endorama "endorama (4 commits)")[![yateric](https://avatars.githubusercontent.com/u/1567297?v=4)](https://github.com/yateric "yateric (3 commits)")[![chregu](https://avatars.githubusercontent.com/u/47106?v=4)](https://github.com/chregu "chregu (3 commits)")[![jamiecuthill](https://avatars.githubusercontent.com/u/779188?v=4)](https://github.com/jamiecuthill "jamiecuthill (3 commits)")[![laland](https://avatars.githubusercontent.com/u/1783637?v=4)](https://github.com/laland "laland (3 commits)")[![pvgnd](https://avatars.githubusercontent.com/u/5188832?v=4)](https://github.com/pvgnd "pvgnd (3 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/phpjit-php-vcr/health.svg)

```
[![Health](https://phpackages.com/badges/phpjit-php-vcr/health.svg)](https://phpackages.com/packages/phpjit-php-vcr)
```

###  Alternatives

[behat/behat

Scenario-oriented BDD framework for PHP

4.0k96.8M2.0k](/packages/behat-behat)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M650](/packages/sylius-sylius)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[drupal/core

Drupal is an open source content management platform powering millions of websites and applications.

19462.3M1.3k](/packages/drupal-core)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
