Download the PHP package lezhnev74/psr-recording-middleware without Composer

On this page you can find all versions of the php package lezhnev74/psr-recording-middleware. 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 psr-recording-middleware

PSR-compatible Recording Middleware

tests codecov PHPStan

A recording middleware for any PSR-7 HTTP client that records every request and response passing through it, and can switch to replay mode to serve the recorded responses back - turning real HTTP traffic into a predictable fixture for integration tests.

It is built on PSR-7 (messages), PSR-17 (message factories) and PSR-3 (logging), so it stays implementation-agnostic: it works with any PSR-7 implementation, none of which is a hard dependency. Guzzle is the primary test target, not a runtime dependency.

Requirements

Installation

Usage

Configure a run, open a named session, and attach it to your client - via the Guzzle-style handler middleware or the PSR-18 decorator:

Full working examples live in the tests: tests/KnownHostRecordReplayTest.php (end-to-end record/replay with a real Guzzle client), tests/HandlerMiddlewareTest.php and tests/RecordingClientTest.php.

PHPUnit integration

Drive the mode from an env var, keep the fixture store in a committed directory, and give each test its own session. Tests then need no record/replay branching - run once with HTTP_RECORD=1 against the real network, commit tests/fixtures/http/, and every ordinary run replays offline. In your base TestCase:

Attach the session to the client your code under test uses (handler stack or RecordingClient, as above). For integration tests, do it at the DI seam, e.g. in Laravel: $this->app->extend(ClientInterface::class, fn ($inner) => new RecordingClient($inner, $this->httpSession())).

To re-prove a single test still works against the live network without re-recording the whole suite, flip only that test's session: $this->httpSession()->setMode(Mode::Record).

Masking volatile fields

Replay matches requests byte-for-byte, so any field that changes between runs (rotating tokens, a default User-Agent embedding PHP/Guzzle versions) breaks committed fixtures - and secrets must not land in git. Mask them: masking applies identically when recording and when matching, so a masked field is stored as ***, never mismatches, and never leaks.

The full runnable pattern - env-driven mode, session per test, masking proven against changed tokens and User-Agent - is tests/PhpUnitIntegrationExampleTest.php.

Committing recordings to git

Recordings capture raw request/response bytes, including binary bodies. Tell git to treat the store as binary so it never normalizes line endings or mangles a payload, and to keep the noisy diffs out of code review. Add a .gitattributes next to your fixture store:

binary implies -text -diff, so recordings are stored verbatim and shown as Binary files differ rather than a line-by-line diff.

Local development

All QA tooling runs inside a PHP 8.5 Docker container (with Xdebug) via the dev wrapper script - no PHP is needed on the host. Each command tunnels to the matching Composer script inside the container, so ./dev <script> is just composer <script> run in Docker.

Anything unrecognized is passed to composer, so ./dev require <pkg>, ./dev stan, ./dev rector etc. all work. Use ./dev php ... for a raw PHP call, ./dev sh for a shell, and ./dev compose ... for raw docker compose.

Contributing

A few conventions, kept light:

License

MIT - see LICENSE.


All versions of psr-recording-middleware with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
lezhnev74/psr-logging-masking-middleware Version ^1.1
php-http/discovery Version ^1.19
psr/http-client Version ^1.0
psr/http-factory Version ^1.0
psr/http-message Version ^1.1 || ^2.0
psr/log Version ^2.0 || ^3.0
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 lezhnev74/psr-recording-middleware contains the following files

Loading the files please wait ...