PHPackages                             smile/httplug-record-and-replay-plugin - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. smile/httplug-record-and-replay-plugin

ActiveLibrary[HTTP &amp; Networking](/categories/http)

smile/httplug-record-and-replay-plugin
======================================

Taping plugin for HTTPlug

02[1 PRs](https://github.com/Smile-SA/httplug-record-and-replay-plugin/pulls)PHP

Since Feb 4Pushed 7y ago5 watchersCompare

[ Source](https://github.com/Smile-SA/httplug-record-and-replay-plugin)[ Packagist](https://packagist.org/packages/smile/httplug-record-and-replay-plugin)[ RSS](/packages/smile-httplug-record-and-replay-plugin/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

Record And Replay Plugin for HTTPlug
====================================

[](#record-and-replay-plugin-for-httplug)

[![Latest Version](https://camo.githubusercontent.com/8cf2f15489e624b01f056ac513f5da4af31f71fc8ab2cf34214e7e107c9e26ea/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f736d696c652f687474706c75672d7265636f72642d616e642d7265706c61792d706c7567696e2e7376673f7374796c653d666c61742d737175617265)](https://github.com/Smile-SA/httplug-record-and-replay-plugin/releases)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Build Status](https://camo.githubusercontent.com/73ba5fb35a80f8cca0dafabb056ca40761e1226d9904b5fa65db899ceb99a1d2/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f536d696c652d53412f687474706c75672d7265636f72642d616e642d7265706c61792d706c7567696e2f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/Smile-SA/httplug-record-and-replay-plugin)[![Code Coverage](https://camo.githubusercontent.com/264be3108d6220769e08f06d06b84231849cde0486b7f4683765f71726fd8ec3/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f536d696c652d53412f687474706c75672d7265636f72642d616e642d7265706c61792d706c7567696e2f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/Smile-SA/httplug-record-and-replay-plugin)[![Quality Score](https://camo.githubusercontent.com/b92e397d7ae817b45f08e0f466293a7ec25ab6da8f0de34fb2df013a71a76805/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f536d696c652d53412f687474706c75672d7265636f72642d616e642d7265706c61792d706c7567696e2f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/Smile-SA/httplug-record-and-replay-plugin)

**Achieve isolated test-suites and predictable HTTP communications.**

Install
-------

[](#install)

Via Composer

```
$ composer require --prefer-stable smile/httplug-record-and-replay-plugin
```

Usage
-----

[](#usage)

### Vanilla PHP

[](#vanilla-php)

Run the following lines with the environment variable `HTTPLUG_RECORDING=1` :

```
/** @var Http\Client\HttpClient $client */
$client = new Client();

/**
 * You have to provide concrete instances for the following parameters :
 * @var Psr\SimpleCache\CacheInterface $cachePool
 * @var Http\Client\Common\Plugin\Cache\Generator\CacheKeyGenerator $cacheKeyGenerator
 * @var Psr\Http\Message\StreamInterface\StreamFactory $streamFactory
 */
$plugin = new RecordAndReplayPlugin(
    $cachePool,
    $cacheKeyGenerator,
    $streamFactory,
    getenv('HTTPLUG_RECORDING')
);

/** @var Http\Client\Common\PluginClient $client */
$client = new PluginClient($client, [$plugin]);

$request = Psr17FactoryDiscovery::findRequestFactory()->createRequest('GET', 'https://api.somewhere/some_endpoint');
$client->sendRequest($request);
```

If you then run this lines again, but with `HTTPLUG_RECORDING=0`, the plugin will replay the recorded communications without actually calling the remote service.

### HTTPlug Bundle for Symfony

[](#httplug-bundle-for-symfony)

Declare the plugin (and its wanted *PSR-16* storage) :

```
# config/services.yaml
services:
    _defaults:
        autowire: true
        public: false

    Smile\HTTPlugRecordAndReplayPlugin\RecordAndReplayPlugin:
        arguments:
            $cachePool: '@app.simple_cache.httplug_records'
            $isRecording: true

    app.simple_cache.httplug_records:
        class: Symfony\Component\Cache\Simple\FilesystemCache
        arguments:
            $directory: '%kernel.project_dir%/tests/httplug_records'
```

Plug it to your client(s) :

```
# config/packages/test/httplug.yaml
httplug:
    clients:
        default:
            plugins:
                - 'Smile\HTTPlugRecordAndReplayPlugin\RecordAndReplayPlugin'
```

You can now run your test-suite and you should see the `tests/httplug_records` folder being filled with cache files representing your records.

Once the test-suite is green, you can remove the `$isRecording` line from your service definition and commit all the records along with the updated configuration and *composer* files.

Later on, when adding other behaviors based on third-party requests, you can switch back to the *record* mode (by putting back the `$isRecording: true` in the plugin service definition) and run only the new tests in order to avoid rewriting all your records.

#### Autowiring troubleshooting

[](#autowiring-troubleshooting)

Depending on the dependencies versions used on your application, you may have to declare some additional services :

```
# config/services.yaml
services:
    _defaults:
        autowire: true
        public: false

    # PSR-17 and PSR-18 autowiring compat
    Psr\Http\Client\ClientInterface: '@Http\Client\HttpClient'
    Psr\Http\Message\RequestFactoryInterface: '@Http\Factory\Guzzle\RequestFactory'
    Http\Factory\Guzzle\RequestFactory: ~

    # HTTPlug record/replay plugin & records storage
    Http\Client\Common\Plugin\Cache\Generator\CacheKeyGenerator:
        class: Http\Client\Common\Plugin\Cache\Generator\SimpleGenerator
```

Contributing and testing
------------------------

[](#contributing-and-testing)

```
$ composer update --prefer-lowest
$ ./vendor/bin/phpunit
```

**Please maintain the test-suite : if you add a feature, prove the new behavior; if you fix a bug, ensure the non-regression.**

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/c158652d318dfb93e48bdda8c3c514ed91b7c0ae7e848e33c99bf8efd852c9d6?d=identicon)[smile-sa](/maintainers/smile-sa)

![](https://www.gravatar.com/avatar/f0622214a43b7f88d89ac5285f4cec686a001ef3fc0cfc8e505d48f636ba43f6?d=identicon)[adrienlucas](/maintainers/adrienlucas)

---

Top Contributors

[![adrienlucas](https://avatars.githubusercontent.com/u/210622?v=4)](https://github.com/adrienlucas "adrienlucas (6 commits)")

### Embed Badge

![Health badge](/badges/smile-httplug-record-and-replay-plugin/health.svg)

```
[![Health](https://phpackages.com/badges/smile-httplug-record-and-replay-plugin/health.svg)](https://phpackages.com/packages/smile-httplug-record-and-replay-plugin)
```

###  Alternatives

[friendsofsymfony/rest-bundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony

2.8k73.3M318](/packages/friendsofsymfony-rest-bundle)[php-http/discovery

Finds and installs PSR-7, PSR-17, PSR-18 and HTTPlug implementations

1.3k309.5M1.2k](/packages/php-http-discovery)[nyholm/psr7

A fast PHP7 implementation of PSR-7

1.3k235.4M2.4k](/packages/nyholm-psr7)[pusher/pusher-php-server

Library for interacting with the Pusher REST API

1.5k94.8M292](/packages/pusher-pusher-php-server)[spatie/crawler

Crawl all internal links found on a website

2.8k16.3M52](/packages/spatie-crawler)[react/http

Event-driven, streaming HTTP client and server implementation for ReactPHP

78126.4M414](/packages/react-http)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
