A Guzzle plugin for automatic mock response/fixture creation and retrieval.

v3.8.2 2014-03-13 04:39 UTC


Latest Stable Version Code Coverage Scrutinizer Code Quality Build Status

A Guzzle plugin for automatic mock response/fixture creation and retrieval.

From the Guzzle Documentation:

Mock responses can be used to test if requests are being generated correctly and responses and handled correctly by your client.

But creating these mock responses/fixtures can be tedious, if you need many of them.

This Guzzle Fixture Plugin allows you to create the fixtures with your unit tests. The first time you execute your tests, real requests will be made to the remote endpoints and the results will be stored to a defined directory.

The second time you execute your test suite, the contents of the previously generated fixture files will be taken, without the need for remote connections.

You can then commit the fixtures to your repository and ensure that no remote connection is needed to run your tests.

The versioning of this plugin is geared to the versioning of the main Guzzle project; thus ~3.8 fits Guzzle ~3.8.


The recommended way to install the Guzzle Fixture Plugin is with Composer. Composer is a dependency management tool for PHP that allows you to declare the dependencies your project needs and installs them into your project.

# Install Composer
curl -sS | php

# Add guzzle-plugin-fixture as a dependency
php composer.phar require jeromegamez/guzzle-plugin-fixture:~3.8

After installing, you need to require Composer's autoloader:

require 'vendor/autoload.php';

You can find out more on how to install Composer, configure autoloading, and other best-practices for defining dependencies at


use Guzzle\Http\Client;
use Guzzle\Plugin\Fixture\FixturePlugin;

$fixturePlugin = new FixturePlugin('_fixtures');

$client = new Client();

// The following request will perform a real request and store the response to
// the fixtures dir

// The following request will get the response from the previously created
// fixture file and not perform a real request