Download the PHP package daycry/phpunit-extension-vcr without Composer

On this page you can find all versions of the php package daycry/phpunit-extension-vcr. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package phpunit-extension-vcr

CI Tests Coverage Status Latest Stable Version Total Downloads License

PHP-VCR Extension for PHPUnit

A modern library that provides seamless integration between PHP-VCR and PHPUnit, enabling you to record and replay HTTP interactions in your tests using PHP 8+ attributes.

Table of Contents

Why Use This Extension?

Requirements

Installation

Install via Composer:

Configuration

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

Configuration Parameters

All parameters are optional and will use sensible defaults:

Parameter Default Description
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)
libraryHooks stream_wrapper Hooks to enable (see PHP-VCR docs)
requestMatchers method, url Request matching strategy (see PHP-VCR docs)
whitelistedPaths (empty) Paths to allow real HTTP requests (comma-separated)
blacklistedPaths (empty) Paths to block from recording (comma-separated)

Recording Modes

Library Hooks

Multiple hooks can be enabled by separating them with commas:

Usage

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

Basic Usage

Recording HTTP requests for all tests in a class:

Recording HTTP requests for specific test methods:

Method-level cassettes override class-level cassettes:

Working with Different HTTP Clients

The extension works with any HTTP client that uses PHP's HTTP stream context:

Features

Advanced Usage

Working with Data Providers

The extension works seamlessly with PHPUnit data providers:

Understanding VCR Modes

The mode parameter controls how VCR handles HTTP requests:

Cassette File Structure

Cassettes are stored as YAML (default) or JSON files containing HTTP request/response pairs:

Custom Request Matching

You can customize how requests are matched to cassette entries:

Testing Strategies

1. API Integration Tests

Use VCR for testing external API integrations:

2. Service Layer Tests

Record interactions with external services:

3. Webhook Testing

Test webhook handlers by recording webhook payloads:

Performance Tips

  1. Use specific request matchers: Only match what you need to avoid false matches
  2. Group related tests: Use class-level cassettes for related API calls
  3. Clean up cassettes: Remove outdated cassettes regularly
  4. Use none mode in CI: Ensure tests only use existing cassettes in production

Troubleshooting

Common Issues

Cassette Not Found

Solution: Check that the cassette file exists and the request matches exactly. Consider using fewer request matchers.

Permission Errors

Solution: Ensure the cassettes directory is writable:

Tests Failing in CI

Solution: Set VCR mode to none in CI to ensure only existing cassettes are used:

Outdated Cassettes

Solution: Delete cassette files and re-run tests with new_episodes mode:

Debug Mode

Enable VCR debug output by setting the VCR_DEBUG environment variable:

Development

Running Tests

Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/my-feature
  3. Make your changes and add tests
  4. Run the test suite: composer test
  5. Submit a pull request

Please ensure:

Code Quality Tools

This project uses several quality tools:

License

This project is licensed under the MIT License. See the LICENSE file for details.

Acknowledgments

Changelog

v2.0.0

v1.0.0

For detailed changes, see RELEASES.


All versions of phpunit-extension-vcr with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
php-vcr/php-vcr Version ^1.7
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package daycry/phpunit-extension-vcr contains the following files

Loading the files please wait ...