Reputation: 1700
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
Upvotes: 1
Views: 610
Reputation: 39380
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
Upvotes: 3