2、PHPunit的代码覆盖率以及打断点的配置

一、代码覆盖率:

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 这个方法

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值