简体   繁体   English

耗时`http_errors`将错误从500更改为404

[英]guzzle `http_errors` changes error from 500 to 404

i have a function im testing which suppose to return error 500 but after adding 'http_errors' => 'false' to the put definition, the returned error changes from 500 to 404. this is my function: 我有一个函数im测试,该函数假定返回错误500,但是在put定义中添加了'http_errors' => 'false' ,返回的错误从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
    }
}

right now this function will return server error: 500 but it also stops the class from executing rest of the tests and i can't assert it. 现在,此函数将返回server error: 500但它也使该类停止执行其余测试,而我无法断言。 how can i use the guzzle getStatusCode() in my function while getting error 500 and not 404 as i mentioned above 我如何在我的函数中使用耗子getStatusCode() ,同时收到错误500而不是我上面提到的404错误

The BadResponseException contains the original Request and the Response object. BadResponseException包含原始的Request和Response对象。 So you can, the catch block the following assertion: 因此,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");
    }

Further info in the doc 文档中的更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM