I am trying to do phpunit testing using codeception and guzzle on my API written on php, all the tests are running but the codecoverage is always showing 0/0. I am sharing my test function below
public function testInputget()
{
$c = $this->id;
// create our http client (Guzzle)
$client = new Client();
$url = 'http://localhost/unit_test/testApi/user';
if($c != '')
{
$url .='/'.$c;
}
// echo $url;
try
{
// $response = $client->request('GET', 'http://localhost/unit_test/testApi/user');
$response = $client->request('GET', $url);
// var_dump(expression)
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('success', json_decode($response->getBody()->getContents())->status);
// $this->assertInternalType('array', json_decode($response->getBody()->getContents())->users);
// print_r(json_decode($response->getBody())->users);
$this->assertEquals($this->username, json_decode($response->getBody())->users[0]->username);
$this->assertEquals($this->age, json_decode($response->getBody())->users[0]->age);
$this->assertEquals($this->status, json_decode($response->getBody())->users[0]->status);
// var_dump(json_decode($response->getBody())->users);
}
catch (RequestException $z)
{
// Catch all 4XX errors
// To catch exactly error 400 use
if($z->getResponse()->getStatusCode() != '200')
{
// print_r($z->getResponse()->getBody()->getContents());
// echo json_decode($z->getResponse()->getBody()->getContents())->remark;
// $this->assertEquals($a, $z->getResponse()->getStatusCode());
// $this->assertEquals($b, json_decode($z->getResponse()->getBody()->getContents())->status);
// $this->assertContains('utsab', json_decode($response->getBody()->getContents())->users);
}
}
}
and the command I am using is
./vendor/bin/codecept run --coverage --coverage-html