forked from aerisweather/GuzzleHttpMock
-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Description
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 403What am I doing wrong?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels