什么网站可以做投资,设计接单,做网站每年要交不费用吗,园林景观设计公司成都【题记#xff1a;最近进行了ExcelBDD PHP版的开发#xff0c;查阅了大量资料#xff0c;发现PHP测试覆盖率解决方案存在不同的历史版本#xff0c;让我花费了蛮多时间#xff0c;为了避免后人浪费时间#xff0c;整理本文#xff0c;而且网上没有给出Azure DevOps里面P…【题记最近进行了ExcelBDD PHP版的开发查阅了大量资料发现PHP测试覆盖率解决方案存在不同的历史版本让我花费了蛮多时间为了避免后人浪费时间整理本文而且网上没有给出Azure DevOps里面PHP测试覆盖率的解决方案本文一并给出】
版本
PHP 8.2.12PHPUnit 10.4.2 php-code-coverage 10.1.7 Xdebug v3.3.0alpha3操作系统Win11
安装
分别安装PHP Composer见 Composer安装PHPUnitphp-code-coverage根据网上指南配置PHPUnit比如PHPUnit 手册 – 第 1 章 安装 PHPUnit下载Xdebug,见Xdebug: Downloads配置php.ini 在尾部加如下
[Xdebug]
zend_extensionD:\php\php_xdebug-3.3.0alpha3-8.2-vs16-x86_64.dll
xdebug.modecoverage
其中zend_extension是Xdebug的绝对路径
配置
PHPUnit前后版本在phpunit.xml上历经了多次修改网上能够查到的都是旧版浪费了我好多时间。如下是最新格式。
?xml version1.0 encodingUTF-8?
phpunit xmlns:xsihttp://www.w3.org/2001/XMLSchema-instance bootstrapvendor/autoload.phpxsi:noNamespaceSchemaLocationhttps://schema.phpunit.de/10.4/phpunit.xsdcacheDirectorytestReports/.phpunit.cachesourceincludedirectory suffix.phpsrc/directory/include/sourcecoveragereportcobertura outputFiletestReports/cobertura.xml //report/coverageloggingjunit outputFiletestReports/junit.xml //logging/phpunit
网上容易查到的“filter”“whitelist”已经过时。PHPUnit作者考虑到前后变化提供了自动改写功能如下
phpunit --migrate-configuration
目前PHPUnit支持的覆盖率格式如下
reportclover outputFileclover.xml/cobertura outputFilecobertura.xml/crap4j outputFilecrap4j.xml threshold50/html outputDirectoryhtml-coverage lowUpperBound50 highLowerBound90/php outputFilecoverage.php/text outputFilecoverage.txt showUncoveredFilesfalse showOnlySummarytrue/xml outputDirectoryxml-coverage/
/report
参见 5. The XML Configuration File — PHPUnit 10.4 Manual
测试结果所有选项如下
loggingjunit outputFilejunit.xml/teamcity outputFileteamcity.txt/testdoxHtml outputFiletestdox.html/testdoxText outputFiletestdox.txt/
/logging
Azure DevOps Pipelines的配置
微软官方没有给出PHP测试覆盖率解决方案经过摸索得到如下方案
在azure-pipelines.yml对应位置按下修改来准备好环境
- script: |sudo update-alternatives --set php /usr/bin/php$(phpVersion)sudo update-alternatives --set phar /usr/bin/phar$(phpVersion)sudo update-alternatives --set phpdbg /usr/bin/phpdbg$(phpVersion)sudo update-alternatives --set php-cgi /usr/bin/php-cgi$(phpVersion)sudo update-alternatives --set phar.phar /usr/bin/phar.phar$(phpVersion)
# 如下这行没有必要azure的VM已经安装了xdebugsudo apt-get install php8.1-xdebug
# 下行必需php.ini的位置可以通过 php -i 得到sudo sh -c echo xdebug.modecoverage /etc/php/8.1/cli/php.iniphp -versiondisplayName: Use PHP version $(phpVersion)
发布测试结果
- task: PublishTestResults2inputs:testRunner: JUnit# Make sure the file name matches the file name you specified.testResultsFiles: **/testReports/junit.xmlfailTaskOnFailedTests: truedisplayName: Publish Test Results
发布测试覆盖率
- task: PublishCodeCoverageResults1inputs:codeCoverageTool: CoberturasummaryFileLocation: **/testReports/cobertura.xml
提示PublishCodeCoverageResults2达到的效果不如PublishCodeCoverageResults1。 ExcelBDD PHP版在Azure DevOps配置了CI见ExcelBDD PHP CI
全部文件见ExcelBDD开源项目PHP部分