emanueleminotto / guzzle-snapshot
Guzzle Snapshots Middleware
Installs: 10 152
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 3
Forks: 1
Open Issues: 0
Requires
- php: ~7.1
- guzzlehttp/guzzle: ^6.0|^7.0
Requires (Dev)
- doctrine/cache: ^1.8
- friendsofphp/php-cs-fixer: ^2.14
- mikey179/vfsstream: ^1.6
- phpunit/phpunit: >=7.0
This package is auto-updated.
Last update: 2024-10-26 18:38:55 UTC
README
Guzzle 6 & 7 middleware to store responses and requests and replay them in tests.
Structure
If any of the following are applicable to your project, then the directory structure should follow industry best practices by being named the following.
bin/
config/
src/
tests/
vendor/
Install
Via Composer
$ composer require emanueleminotto/guzzle-snapshot
Usage
use EmanueleMinotto\GuzzleSnapshot\Strategy\ReadableFileStrategy; use GuzzleHttp\Client; use GuzzleHttp\HandlerStack; // use Doctrine\Common\Cache\ArrayCache; // use EmanueleMinotto\GuzzleSnapshot\Strategy\DoctrineCacheStrategy; // $strategy = new DoctrineCacheStrategy(new ArrayCache()); $strategy = new ReadableFileStrategy(__DIR__.'/__snapshots__'); $middleware = new SnapshotMiddleware($strategy); // $middleware->setRequestStorage(true); // this will save requests too $stack = HandlerStack::create(); $stack->push($middleware); $client = new Client([ 'handler' => $this->stack, ]); // if the response file was already stored in // the directory __snapshots___, this request wont // be sent to the remote endpoint $client->get('http://www.example.com/'); // this request wont be sent in any case $client->get('http://www.example.com/');
Testing
$ composer test
Contributing
Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
Security
If you discover any security related issues, please email minottoemanuele@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.