Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Phpunit Testlistener Vcr Laravel Package

covergenius/phpunit-testlistener-vcr

PHPUnit test listener that records and replays HTTP interactions using a VCR-style approach. Capture real API responses into cassettes during tests, then replay them for fast, deterministic runs without hitting external services.

View on GitHub
Deep Wiki
Context7

PHPUnit TestListener for PHP-VCR

CI Tests License Development Version Monthly Installs

Integrates PHPUnit with PHP-VCR using annotations.

PHP-VCR

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

Usage example


use PHPUnit\Framework\TestCase;
use VCR\PHPUnit\TestListener\Attributes\Vcr;

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('http://google.com');
        $this->assertEquals('This is a annotation test dummy.', $result, 'Call was not intercepted (using annotations).');
    }

    #[Vcr('unittest_annotation_test')]
    public function testInterceptsWithAttributes(): void
    {
        // Content of tests/fixtures/unittest_annotation_test: "This is a annotation test dummy".
        $result = file_get_contents('http://google.com');
        $this->assertEquals('This is a annotation test dummy.', $result, 'Call was not intercepted (using attributes).');
    }
}

Installation

  1. Install using composer:
composer require --dev covergenius/phpunit-testlistener-vcr

For phpunit version 10+

  1. Add listener to your phpunit.xml:
<extensions>
    <bootstrap class="VCR\PHPUnit\TestListener\VCRTestListener" />
</extensions>

For phpunit version 9 and below

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

Dependencies

PHPUnit-Testlistener-VCR depends on the following;

Version 4

  • PHP 8.1+
  • PHPUnit >=10

Version 3

  • PHP 7.1+
  • PHPUnit <10

Run tests

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

composer install
./vendor/bin/phpunit

Changelog

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

Copyright

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

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor