doutang8098 2015-08-04 09:40
浏览 78
已采纳

guzzle`http_errors`将错误从500更改为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:

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. how can i use the guzzle getStatusCode() in my function while getting error 500 and not 404 as i mentioned above

  • 写回答

1条回答 默认 最新

  • dpcnm2132 2015-08-04 10:22
    关注

    The BadResponseException contains the original Request and the Response object. So you can, the catch block the following assertion:

    } 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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 深度学习残差模块模型
  • ¥20 两个不同Subnet的点对点连接
  • ¥50 怎么判断同步时序逻辑电路和异步时序逻辑电路
  • ¥15 差动电流二次谐波的含量Matlab计算
  • ¥15 Can/caned 总线错误问题,错误显示控制器要发1,结果总线检测到0
  • ¥15 C#如何调用串口数据
  • ¥15 MATLAB与单片机串口通信
  • ¥15 L76k模块的GPS的使用
  • ¥15 请帮我看一看数电项目如何设计
  • ¥23 (标签-bug|关键词-密码错误加密)