The purpose of my test it's to check that a function returns error 404, or to be more accurate, function creates call to server ( i am using guzzle) and i expect the server to return error 404, but i can't find any @expectedException
which make sense cause it's an ERROR, but does anyone know how can i test this case with phpunit ??? thx
in case it might help, this is how the function looks like (last attempt) :
public function testApi_deleteExecuted()
{
$path = '/adserver/src/public/api/rule/288';
$client = new Client(['base_uri' => 'http://10.0.0.38']);
$response = $client->get($path);
$data = json_decode($response->getBody());
$code = $response->getStatusCode();
$this->assertEquals($code, 404);
}
so apparently guzzle has the answer, http_errors
.
function didn't work before but it works now:
public function testApiRule_deleteExecuted()
{
$path = '/adserver/src/public/api/rule/288';
$client = new Client(['base_uri' => 'http://10.0.0.38']);
$response = $client->get($path, ['http_errors' => false]);
$err = $response->getStatusCode();
$this->assertEquals($err, 404);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With