Integrates PHPUnit with PHP-VCR.

v4.0.0 2023-07-14 06:10 UTC


Integrates PHPUnit with PHP-VCR using annotations.


Use @vcr cassette_name on your tests to turn VCR automatically on and off.

Build Status

Usage example

use PHPUnit\Framework\TestCase;

class VCRTest extends TestCase
     * @vcr unittest_annotation_test
    public function testInterceptsWithAnnotations()
        // Content of tests/fixtures/unittest_annotation_test: "This is a annotation test dummy".
        $result = file_get_contents('');
        $this->assertEquals('This is a annotation test dummy.', $result, 'Call was not intercepted (using annotations).');


  1. Install using composer:
composer require --dev php-vcr/phpunit-testlistener-vcr
  1. Add listener to your phpunit.xml:
    <bootstrap class="VCR\PHPUnit\TestListener\VCRTestListener" />

Prior to PHPUnit 10

    <listener class="VCR\PHPUnit\TestListener\VCRTestListener" file="vendor/php-vcr/phpunit-testlistener-vcr/src/VCRTestListener.php" />


PHPUnit-Testlistener-VCR depends on:

  • PHP 8.1+
  • PHP 7.1+ (use <4.0)
  • PHP 7.0+ (use <3.0)
  • PHPUnit 10+
  • PHPUnit <10 (use <4.0)
  • php-vcr/php-vcr

Run tests

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

composer install


The changelog is manage at PHPUnit testlistener for PHP-VCR releases page.


Copyright (c) 2013-2018 Adrian Philipp. Released under the terms of the MIT license. See LICENSE for details. Contributors