Download the PHP package ikwattro/guzzle-stereo without Composer

On this page you can find all versions of the php package ikwattro/guzzle-stereo. 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 guzzle-stereo

Guzzle Stereo

Record and Replay HTTP Responses easily.

Build Status

Requirements

Installation

Require the composer package :

NB: If you're using the Symfony Framework, you can take a look at the GuzzleStereoBundle from @estahn.

Basics

Recorder

A recorder is the main object that knows everything about tapes and how to store them afterwards.

Tapes

A tape will record Response objects. It has a name and can have filters. A filter can tell for example that only Responses with a 200 status code will be recorded in that tape.

Defining tapes and filters is done through a yaml file definition :

This tape will record only success responses.

Filters

A filter is a rule telling if the Response object should be included or not. There is a set of built-in filters available with the library or you can create your own and register them.

NB: If you feel that your filter can be generic enough, do not hesitate to open a PullRequest

Store directory

In order to be replayed later (see the Replay section below), all tapes will then be dumped in json files to disk. You need to provide a writable directory.

Player

A player is able to replay dumped json files as Response objects. A nice use case is to replay them with a Mock Handler in your test suites.

Usage

Recording

Instantiate the recorder by providing a writable store directory and the location of your tapes definitions file :

Next, when creating your Guzzle client, you need to make him aware of the recorder. An easy way to do this is by using a Middleware available with the library :

You can now make http requests with the Client as you would usually do, for e.g. here we'll call the Github events API 10 times :

Finally, you'll need to tell the recorder to dump the tapes to the disk :

A file named record_ + {tape_name} will be created in the provided store directory containing the responses passing the filters :

Replaying

In order to replay the recorded tapes, you can use the Player. The player is in fact creating a Mock Handler and will return you a GuzzleHttp\Client instance created with the MockHandler containing the responses from the tape file.


Filters reference

StatusCode

Include the Response only if it has the corresponding status code.

Non Empty Body

Include the Response only if the body is not empty.

Has Header

Include the Response only if she contains a header with the specified key.

Creating your own filters

Creating a filter is really easy. You need to create a filter class implementing Ikwattro\GuzzleStereo\Filter\FilterInterface and declaring the two methods :

The getName static function is responsible for defining the name of the filters in your tapes.

The isIncluded function will contain the logic determining if the received Response should be included or not in the Tape.

The following example filter will receive a response from the Github events api, and will record it only if the body contains an event done by the Github users you will pass as arguments when associating your filter to a tape.

You can now add your custom filter in your configuration and use it in your tapes :

Your tape will now contain only Responses that included in their actors one of the provided actors.

Extra configuration setting :

Your Responses objects can contain a specific header as a marker by setting the following configuration flag :

which will add a X-Guzzle-Stereo header with a true value.

TODO


Tests

phpspec and phpunit are used for the tests:

License

The library is issued under the MIT license, please refer to the LICENSE file provided with the package.

Contribute

Feel free to contribute or report issues on Github.

Author

Christophe Willemsen

Twitter: @ikwattro

Github: @ikwattro


All versions of guzzle-stereo with dependencies

PHP Build Version
Package Version
Requires php Version >=5.6
guzzlehttp/guzzle Version ^6.0
symfony/yaml Version ^2.7 || ^3.1
symfony/finder Version ^2.7 || ^3.1
symfony/config Version ^2.7 || ^3.1
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 ikwattro/guzzle-stereo contains the following files

Loading the files please wait ....