Skip to content

Can't make it work, mock always returns 200 status code #7

Description

@koichirose

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions