emanueleminotto / guzzle-snapshot
Guzzle 快照中间件
1.1.0
2020-11-26 10:23 UTC
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-08-26 18:24:09 UTC
README
Guzzle 6 & 7 中间件,用于存储响应和请求并在测试中重新播放。
结构
如果以下任何一项适用于您的项目,则目录结构应遵循行业最佳实践,并命名为以下。
bin/
config/
src/
tests/
vendor/
安装
通过 Composer
$ composer require emanueleminotto/guzzle-snapshot
用法
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/');
测试
$ composer test
贡献
请参阅 CONTRIBUTING 和 CODE_OF_CONDUCT 了解详细信息。
安全性
如果您发现任何安全相关的问题,请通过电子邮件 minottoemanuele@gmail.com 而不是使用问题跟踪器。
鸣谢
许可
MIT 许可证 (MIT)。有关更多信息,请参阅 许可文件。