verdet / guzzle-mock
Guzzle Mock Handler
Installs: 61
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 1
Type:guzzle-extension
Requires
- php: ^8.0
- guzzlehttp/guzzle: ^7
Requires (Dev)
- phpunit/phpunit: ^9.3.5
This package is auto-updated.
Last update: 2025-01-04 19:11:15 UTC
README
Description
Inspired by guzzle/guzzle MockHandler and alekseytupichenkov/GuzzleStub library.
Mock Handler functional same as default GuzzleHttp\Handler\MockHandler
except filling queue. Argument $queue
expected to be array of Request and Response objects.
When you pass Request to MockHanlder it will try to find suitable Request in queue and return paired Response.
Prerequisite
php >= 8.0
guzzlehttp/guzzle >= 7.0
Installation
Use the package manager composer to install.
composer require --dev verdet/guzzle-mock
Basic usage
// 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')) ] ]);
Rest of usage same as https://docs.guzzlephp.org/en/stable/testing.html