phpunit - Phpunit 代码覆盖率没有捕获我的代码
问题描述
我正在尝试使用 codeception 和 guzzle 对我用 php 编写的 API 进行 phpunit 测试,所有测试都在运行,但代码覆盖率始终显示 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 运行 --coverage --coverage-html
解决方案
推荐阅读
- javascript - 如何仅使用一个 html 文件来显示不同但相似的内容
- r - combining list elements of different dimensions
- c# - 使用 .net C# System.Diagnostics.process 部署 DacPac 的 SQlPackage
- eclipse - Eclipse & Groovy - 无法解析类
- python - 交换列表字符并去掉嵌套列表中的逗号
- python-3.x - pandas 将如何覆盖默认分隔符
- wpf - WPF MVVM:如何在用户控件上设置绑定?
- sql - 加入问题
- javascript - 使用javascript设置鼠标焦点并将光标移动到输入的末尾
- python - 对“键”和“值”中的所有值进行排序