我正在尝试使用代码识别进行phpunit测试,并在我的API上编写API,所有测试都在运行,但codecoverage总是显示0/0。 我在下面分享我的测试功能
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);
}
}
}
我正在使用的命令是
./ vendor / bin / codecept run --coverage --coverage-html