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 shape_predictor_68_face_landmarks.dat
  • ¥15 slam rangenet++配置
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题