我在 PHP 中有以下代码:
$response = $this->client->request('GET', $path, $requestBody, $headers);
$isRequestSuccess = $response->getStatusCode() === "200";
if ($isRequestSuccess) {
return $response->getBody()->getContents();
}
似乎我成功地为请求创建了一个模拟:
$mockResponse = \Mockery::mock('GuzzleHttp\Psr7\Response');
$clientMock
->shouldReceive('request')
->once()
->withAnyArgs()
->andReturn($mockResponse);
$clientMock->shouldReceive('getStatusCode')->andReturn(200);
但是,我应该如何使用 Mockery 来模拟getStatusCode
?
它应该返回Psr7\Response
一个GuzzleHttp
.
我知道$clientMock
应该将返回值分配给一个参数,但是我应该如何模拟
$response->getStatusCode();
和
$response->getBody()->getContents()
如果我要模拟getStatusCode
并返回 200,我会收到以下错误:
Method Mockery_4_GuzzleHttp_Psr7_Response::getStatusCode() does not exist on this mock object