guzzle/guzzle — pull request #921 by jeromegamez (2014-11-22 02:00:14+00:00)
Title: Add Fixture Subscriber

If you're writing tests for an application that consumes a remote API, it can be quite tedious to craft the mocks for each possible response manually, especially when the responses contain complex data that has to be used for further tests.

The Fixture Subscriber enables you to actually hit your remote API when you execute your tests for the first time (preferably on your local machine), and only then. It will store the responses into files and use those on subsequent test runs and never hit the real API again.

Here is an example of how it works:

```php
use GuzzleHttp\Client;
use GuzzleHttp\Subscriber\Fixture;
use GuzzleHttp\Message\Response;

$client = new Client(['base_url' => 'http://httpstat.us']);
$fixture = new Fixture(__DIR__ . '/_fixtures');
$client->getEmitter()->attach($fixture);

$response = $this->client->get('/200');
```

The first run of this snippet will trigger an actual call to the remote API and store the response string to a file named `c950f693fb16b7d5672de736d6db462e.fixture` in the `_fixtures` directory.

When you run the snippet again, the response will be taken from this file instead of the actual remote endpoint.

When all your tests have run through, you can commit the fixture files to your code base, so that test runs on CI systems (Travis CI, Jenkins, etc.) without hitting the actual remote API.

When the remote API changes, just delete all the fixture files and restart.

### Notes
- The file names are MD5 hashes of the complete request string
- Responses mocked with the Mock Subscriber will not be handled by the Fixture Subscriber, so that you can continue to use manually created mocks without duplicating them on the file system.

I also thought about extending the documentation, too, but without knowing if you would consider integrating this Subscriber into Guzzle, I preferred to wait with that. In addition to that, you certainly already have noticed that I am not a native speaker :).

Cheers
:octocat: Jérôme