Download the PHP package angelov/phpunit-php-vcr without Composer
On this page you can find all versions of the php package angelov/phpunit-php-vcr. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package phpunit-php-vcr
PHP-VCR integration for PHPUnit
A library that allows you to easily use the PHP-VCR library in your PHPUnit tests.
Requirements
- PHP 8.2+
- PHPUnit 10+
Installation
Then, add the extension to your PHPUnit configuration file.
(All parameters are optional.)
Usage
The library provides an UseCassette
attribute that can be declared on test classes or specific test methods. The
attribute accepts a cassette name and optional parameters for advanced functionality like separate cassettes per
data provider case.
When running the tests, the library will automatically turn the recorder on and off, and insert the cassettes when needed.
Examples:
-
When declared on a class, PHP-VCR will intercept the requests in all test methods in that class, and will store the responses in the given cassette.
-
When declared on a test method, only requests in that methods will be intercepted and stored in the given cassette. Note that it can be declared on multiple test methods with different cassettes.
- When declared both on the class and on a specific method, the name from the attribute declared on the method will be
used for that method. In this example, the responses from the requests made in the
example()
method will be stored inexample.yml
and the ones fromrecorded()
inexample_2.yml
.
DataProvider Support
The library supports PHPUnit's DataProvider
functionality with additional options for managing cassettes when using data providers.
Basic DataProvider Usage
When using a data provider with the basic UseCassette
attribute, all test cases from the data provider will share the same cassette file:
Separate Cassettes Per DataProvider Case
For more granular control, you can create separate cassette files for each data provider case using the separateCassettePerCase
parameter:
Named DataProvider Cases
When using named data provider cases, the cassette files will use the case names:
Grouping Cassettes in Directories
To organize separate cassette files in directories, use the groupCaseFilesInDirectory
parameter:
Class-Level DataProvider Support
The dataProvider functionality also works when the UseCassette
attribute is declared at the class level: