verdet / guzzle-mock
Guzzle Mock 处理器
1.0.0
2022-08-15 11:11 UTC
Requires
- php: ^8.0
- guzzlehttp/guzzle: ^7
Requires (Dev)
- phpunit/phpunit: ^9.3.5
This package is auto-updated.
Last update: 2024-09-04 18:22:13 UTC
README
描述
受guzzle/guzzle MockHandler 和 alekseytupichenkov/GuzzleStub 库的启发。
Mock 处理器功能与默认的 GuzzleHttp\Handler\MockHandler
相同,除了填充队列。期望参数 $queue
是请求和响应对象的数组。当你向 MockHandler 传递请求时,它将尝试在队列中找到合适的请求,并返回相应的响应。
先决条件
php >= 8.0
guzzlehttp/guzzle >= 7.0
安装
使用包管理器 composer 安装。
composer require --dev verdet/guzzle-mock
基本用法
// Create a mock and queue three pairs of request and responses. $mock = new MockHandler([ [ new Request('GET', 'https://example.com'), new Response(200, ['X-Foo' => 'Bar'], 'Hello, World') ], [ new Request('GET', 'https://example.com/latest'), new Response(202, ['Content-Length' => '0'])], [ new Request('POST', 'https://example.com/foo'), new RequestException('Error Communicating with Server', new Request('POST', 'https://example.com/foo')) ] ]);