Download the PHP package tomb1n0/guzzle-mock-handler without Composer
On this page you can find all versions of the php package tomb1n0/guzzle-mock-handler. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package guzzle-mock-handler
Guzzle Mock Handler
When testing third party APIs it is often challenging to mock them in a way that's simple and declarative. This package aims to help make this process simpler by providing a custom handler for guzzle that has router-like behaviour, rather than relying on the responses being popped off the stack in any particular order.
Installation
You can install the package via composer:
Usage
Basic Example
Request Assertion
Sometimes it is useful to perform assertions on the request that returned your response. Maybe you have a class that logs in to a third party API, and you want to assert the username and password were sent through correctly.
Note: You can also perform the exact same assertions using ->assertRequestHeaders()
, this will allow you to ensure API requests contain a X-API-KEY
header or similar.
Custom Assertions
Asserting the body or headers might not be enough, so we allow you to call ->withAssertion()
, passing you the request and response objects, so you can perform your own assertions:
Asserting Order
Sometimes it is useful to assert API calls were made in the correct order. Maybe you have to call /login
before you fetch /users
for example. This is achieved by giving a name to your responses, then asserting the order after your calls have been made.
Only allowing responses to be called once
Sometimes you might want to only allow an endpoint to be called once in your tests - this can be achieved by calling ->once()
on your response object.
Testing
Credits
- Tom Harper
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
PHP Package Boilerplate
This package was generated using the PHP Package Boilerplate.