一、代码覆盖率:
a.首先保证你已经安装好了Xdebug,并且在PHP.ini文件中配置好了Xdebug,配置如下(可根据个人需求进行更改):
[Xdebug]
zend_extension="D:/phpstudy_pro/Extensions/php/php7.3.4nts/ext/php_xdebug.dll"
是否开启远程调试
xdebug.remote_enable = 1
xdebug.remote_connect_back = 1
;允许调试的客户端IP
xdebug.remote_host=localhost
;远程调试的端口(默认9000)
xdebug.remote_port=9001
b、配置phpunit.xml文件,配置如下(可根据个人需求进行更改):
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
<testsuite name="Application Test Suite">
<directory>./tests/</directory>
</testsuite>
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
</testsuites>
<!--覆盖率报告白名单-->
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./_car_v2/Controllers</directory>
<directory suffix=".php">./_car_v2/Services</directory>
</whitelist>
</filter>
<!--测试数据库入口配置-->
<php>
<env name="APP_ENV" value="testing"/>
<env name="BCRYPT_ROUNDS" value="4"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
<env name="MAIL_DRIVER" value="array"/>
</php>
<!-- 代码覆盖率报告 -->
<logging>
<!-- target(report/html) 生成html 文件的目录-->
<log type="coverage-html" target="./tests/codeCoverage" />
</logging>
</phpunit>
c、执行单元测试命令:phpunit 测试用例的绝对路径(phpunit tests/Unit/ExampleTest.php)
d、生成的报告是在phpunit.xml的logging的target中进行设置的,然后生成的目录直接在该路径下点击index.html进行代码覆盖率的查看
二、打断点
a、环境配置
setting---》搜索CLI,左侧选择PHP,点击 + 新增一个PHP解释器
setting---》搜索test---》左侧选择Test Framework,点击 +
新增一个 PHPUnit Local
b、打上断点,然后在要测试的方法名上右键,选择 Debug
这个方法