guzzle `http_errors` 将错误从 500 更改为 404
guzzle `http_errors` changes error from 500 to 404
我有一个正在测试的函数,假设 return 错误 500 但在将 'http_errors' => 'false'
添加到 put
定义后,returned 错误从 500 变为404.
这是我的职能:
public function testApiAd_updateWithIllegalGroupId($adId)
{
$client = new Client(['base_uri' => self::$base_url]);
try {
$response = $client->put(self::$path.$adId, ['form_params' => [
'name' => 'bellow content - guzzle testing',
'description' => 'guzzle testing ad - demo',
'group_id' => '999999999',
]]);
} catch (Guzzle\Http\Exception\BadResponseException $e) {
//Here i want to compare received error to 500
}
}
现在这个函数将 return server error: 500
但它也会阻止 class 执行其余测试,我无法断言。
我怎样才能在我的函数中使用 guzzle getStatusCode()
而得到错误 500 而不是我上面提到的 404
BadResponseException 包含原始请求和响应对象。所以你可以,catch 块下面的断言:
} catch (Guzzle\Http\Exception\BadResponseException $e) {
//Here i want to compare received error to 500
$responseCode = $e->getResponse()->getStatusCode();
$this->assertEquals(500, $responseCode, "Server Error");
}
更多信息in the doc
我有一个正在测试的函数,假设 return 错误 500 但在将 'http_errors' => 'false'
添加到 put
定义后,returned 错误从 500 变为404.
这是我的职能:
public function testApiAd_updateWithIllegalGroupId($adId)
{
$client = new Client(['base_uri' => self::$base_url]);
try {
$response = $client->put(self::$path.$adId, ['form_params' => [
'name' => 'bellow content - guzzle testing',
'description' => 'guzzle testing ad - demo',
'group_id' => '999999999',
]]);
} catch (Guzzle\Http\Exception\BadResponseException $e) {
//Here i want to compare received error to 500
}
}
现在这个函数将 return server error: 500
但它也会阻止 class 执行其余测试,我无法断言。
我怎样才能在我的函数中使用 guzzle getStatusCode()
而得到错误 500 而不是我上面提到的 404
BadResponseException 包含原始请求和响应对象。所以你可以,catch 块下面的断言:
} catch (Guzzle\Http\Exception\BadResponseException $e) {
//Here i want to compare received error to 500
$responseCode = $e->getResponse()->getStatusCode();
$this->assertEquals(500, $responseCode, "Server Error");
}
更多信息in the doc