systemhaus / guzzlehttpmock Goto Github PK
View Code? Open in Web Editor NEWThis project forked from aerisweather/guzzlehttpmock
A mock library for verifying requests made with the Guzzle Http Client, and mocking responses
This project forked from aerisweather/guzzlehttpmock
A mock library for verifying requests made with the Guzzle Http Client, and mocking responses
The original functionality makes one feel it should be possible to set up multiple expectations in one test scenario, e.g.:
In fact, this tests does not run through. The counter contained output shows the encountered three requests and maps them to one expected request only: the first of the tree which were set up.
I suspect the expected_count is only for replaying the same request multiple times, not for separate requests in one tests. But sometimes it is necessary for the integrity. We should extend the framework to expect multiple requests in the order in which they were set up, distinguishing between an individual expected_count and a total one.
A slightly modified code from the readme (after fixing the namespace with \Aeris\GuzzleHttpMock\
instead of \Aeris\GuzzleHttp\
):
$httpMock = new \Aeris\GuzzleHttpMock\Mock();
// Create a guzzle http client and attach the mock handler
$guzzleClient = new \GuzzleHttp\Client([
'base_url' => 'http://www.example.com',
'handler' => $httpMock->getHandlerStackWithMiddleware()
]);
// Setup a request expectation
$httpMock
->shouldReceiveRequest()
->withUrl('http://www.example.com/foo')
->withMethod('GET')
->withBodyParams([ 'foo' => 'bar' ])
->andRespondWithJson([ 'faz', 'baz' ], 403);
// Make a matching request
$response = $guzzleClient->get('/foo', ['json' => ['foo' => 'bar'] ]);
echo $response->getStatusCode(); //200, even though it should return 403
What am I doing wrong?
It would be great if the library had also the ability to validate the request headers. Some APIs require certain headers being set and currently there's no way to test it using this library. You have revert to the built-in mocking capabilities of Guzzle, which are much lower-level and not so easy to use.
Currently, the library only works with Guzzle 5.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.