PHPackages                             daycry/phpunit-extension-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. [Testing &amp; Quality](/categories/testing)
4. /
5. daycry/phpunit-extension-vcr

ActiveLibrary[Testing &amp; Quality](/categories/testing)

daycry/phpunit-extension-vcr
============================

A library that allows you to easily use the PHP-VCR library in your PHPUnit tests.

v1.1.1(10mo ago)02.3k↓41.7%[1 issues](https://github.com/daycry/phpunit-extension-vcr/issues)6MITPHPPHP ^8.2

Since Oct 18Pushed 10mo ago1 watchersCompare

[ Source](https://github.com/daycry/phpunit-extension-vcr)[ Packagist](https://packagist.org/packages/daycry/phpunit-extension-vcr)[ Docs](https://github.com/daycry/phpunit-extension-vcr)[ RSS](/packages/daycry-phpunit-extension-vcr/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (7)Versions (5)Used By (6)

[![CI Tests](https://github.com/daycry/phpunit-extension-vcr/actions/workflows/phpunit.yml/badge.svg?branch=master)](https://github.com/daycry/phpunit-extension-vcr/actions/workflows/phpunit.yml)[![Coverage Status](https://camo.githubusercontent.com/4b81c5a11aa78d1fdf58b01588a9607b9e6047ca6d99b459dde2f3f5abc53b76/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6461796372792f706870756e69742d657874656e73696f6e2d7663722f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/daycry/phpunit-extension-vcr?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/3784e7e87fc0b5a284ab9e75e6f3b6551d894a4e18713e42d91938317548630a/68747470733a2f2f706f7365722e707567782e6f72672f6461796372792f706870756e69742d657874656e73696f6e2d7663722f762f737461626c65)](https://packagist.org/packages/daycry/phpunit-extension-vcr)[![Total Downloads](https://camo.githubusercontent.com/6b4c3886e77289ae9ac08ad6ac95f6b5150d7f3575820c129237bf13a3e63e88/68747470733a2f2f706f7365722e707567782e6f72672f6461796372792f706870756e69742d657874656e73696f6e2d7663722f646f776e6c6f616473)](https://packagist.org/packages/daycry/phpunit-extension-vcr)[![License](https://camo.githubusercontent.com/904ed58c9b4a94c162a5a25677fcc5a20975b8ab982138183b422ec1b6880663/68747470733a2f2f706f7365722e707567782e6f72672f6461796372792f706870756e69742d657874656e73696f6e2d7663722f6c6963656e7365)](https://packagist.org/packages/daycry/phpunit-extension-vcr)

PHP-VCR Extension for PHPUnit
=============================

[](#php-vcr-extension-for-phpunit)

A modern library that provides seamless integration between [PHP-VCR](https://github.com/php-vcr/php-vcr) and PHPUnit, enabling you to record and replay HTTP interactions in your tests using PHP 8+ attributes.

Table of Contents
-----------------

[](#table-of-contents)

- [Why Use This Extension?](#why-use-this-extension)
- [Requirements](#requirements)
- [Installation](#installation)
- [Configuration](#configuration)
- [Usage](#usage)
- [Features](#features)
- [Advanced Usage](#advanced-usage)
- [Testing Strategies](#testing-strategies)
- [Performance Tips](#performance-tips)
- [Troubleshooting](#troubleshooting)
- [Development](#development)
- [License](#license)
- [Acknowledgments](#acknowledgments)
- [Changelog](#changelog)

Why Use This Extension?
-----------------------

[](#why-use-this-extension)

- 🎯 **Zero Configuration**: Works out of the box with sensible defaults
- 🏷️ **Modern PHP 8+ Attributes**: Clean, declarative syntax using `#[UseCassette]`
- 🔄 **Automatic State Management**: Handles VCR lifecycle automatically
- 🎭 **Mixed Test Support**: Seamlessly mix tests with and without HTTP recording
- ⚡ **Performance**: Tests run faster by avoiding real HTTP requests
- 🛡️ **Reliability**: Consistent test results independent of external services

Requirements
------------

[](#requirements)

- **PHP**: 8.2 or higher
- **PHPUnit**: 10.0 or higher
- **php-vcr/php-vcr**: ^1.7

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

[](#installation)

Install via Composer:

```
composer require --dev daycry/phpunit-extension-vcr
```

Configuration
-------------

[](#configuration)

Add the extension to your `phpunit.xml` or `phpunit.xml.dist` file:

```

```

### Configuration Parameters

[](#configuration-parameters)

All parameters are optional and will use sensible defaults:

ParameterDefaultDescription`cassettesPath``tests/fixtures`Directory to store cassette files (relative to project root)`storage``yaml`Storage format (`yaml` for human-readable, `json` for smaller files)`mode``new_episodes`Recording mode ([see PHP-VCR docs](https://php-vcr.github.io/documentation/configuration/#record-modes))`libraryHooks``stream_wrapper`Hooks to enable ([see PHP-VCR docs](https://php-vcr.github.io/documentation/configuration/#library-hooks))`requestMatchers``method, url`Request matching strategy ([see PHP-VCR docs](https://php-vcr.github.io/documentation/configuration/#request-matching))`whitelistedPaths`(empty)Paths to allow real HTTP requests (comma-separated)`blacklistedPaths`(empty)Paths to block from recording (comma-separated)#### Recording Modes

[](#recording-modes)

- **`none`**: Only playback existing cassettes, never record new ones
- **`once`**: Record new episodes only if the cassette file doesn't exist
- **`new_episodes`**: Record new requests, replay existing ones (recommended for development)
- **`all`**: Always re-record all requests, overwriting the entire cassette

#### Library Hooks

[](#library-hooks)

Multiple hooks can be enabled by separating them with commas:

```

```

- **`stream_wrapper`**: Intercepts `file_get_contents()`, `fopen()`, etc.
- **`curl`**: Intercepts cURL functions
- **`soap`**: Intercepts SOAP client requests

Usage
-----

[](#usage)

The extension provides the `#[UseCassette]` attribute that can be applied to test classes or individual test methods.

### Basic Usage

[](#basic-usage)

#### Recording HTTP requests for all tests in a class:

[](#recording-http-requests-for-all-tests-in-a-class)

```
