I have the following code in PHP:
$response = $this->client->request('GET', $path, $requestBody, $headers);
$isRequestSuccess = $response->getStatusCode() === "200";
if ($isRequestSuccess) {
return $response->getBody()->getContents();
}
It seems like I was successful in creating a mock for the request:
$mockResponse = \Mockery::mock('GuzzleHttp\Psr7\Response');
$clientMock
->shouldReceive('request')
->once()
->withAnyArgs()
->andReturn($mockResponse);
$clientMock->shouldReceive('getStatusCode')->andReturn(200);
But, how should I use Mockery to mock getStatusCode
?
It should return a Psr7\Response
object of GuzzleHttp
.
I know that the $clientMock
return value should be assigned to a parameter, but how should I mock the
$response->getStatusCode();
and
$response->getBody()->getContents()
If I'm going to mock the getStatusCode
and return 200, I get the following error:
Method Mockery_4_GuzzleHttp_Psr7_Response::getStatusCode() does not exist on this mock object