gpt4 book ai didi

phpunit - 如何在文本输出中获取简单的 phpunit codecoverage 摘要?

转载 作者:行者123 更新时间:2023-12-04 14:53:39 24 4
gpt4 key购买 nike

我在 php 8.0.3 上使用 PHPUnit 9.5.7我想要一个检查器作为 git 钩子(Hook)来检查行的最小代码覆盖率。

我在在线示例中看到一个简单的 3 行输出作为运行测试后的摘要。我如何获得此输出?我搜索了几篇文章和配置文档,但没有找到任何东西。

我的目标是在未实现最小行覆盖率时拒绝提交。因此,如果您有其他想法来完成这项工作,我很乐意接受。

这是我当前的配置文件:

<?xml version="1.0" encoding="UTF-8"?>
<!-- https://phpunit.readthedocs.io/en/latest/configuration.html -->
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="tests/bootstrap.php"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
cacheResult="false"
printerClass="Codedungeon\PHPUnitPrettyResultPrinter\Printer"
>
<coverage>
<include>
<directory>src</directory>
</include>
</coverage>
<php>
<ini name="error_reporting" value="-1"/>
<server name="KERNEL_CLASS" value="\App\Kernel" />
<server name="APP_ENV" value="test" force="true"/>
<server name="SHELL_VERBOSITY" value="-1"/>
<server name="SYMFONY_PHPUNIT_REMOVE" value=""/>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak"/>
<env name="CORS_ALLOW_ORIGIN" value="^https?://(localhost|127\.0\.0\.1)(:[0-9]+)?$"/>
</php>
<extensions>
<extension class="DAMA\DoctrineTestBundle\PHPUnit\PHPUnitExtension"/>
</extensions>
<testsuites>
<testsuite name="Project Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>

最佳答案

你指的是phpunit text-output for coverage :

  --coverage-text=<file>      Generate code coverage report in text format [default: standard output]

它的替代方法是一个小脚本,您可以在运行覆盖率测试后运行该脚本以检查收集的数据。

这里是 composer.json {"script": {}} 部分的摘录:

    "unit-test": [
"@phpunit --log-junit build/log/junit.xml --coverage-clover build/log/clover.xml test/unit",
"@php -f lib/build/coverage-checker.php -- build/log/clover.xml"
],

取自具有脚本的现有项目:

这是一个维护版本,起源于这篇博文:

默认检查的百分比是 100%。如果您想降低它,可以将它作为第二个位置参数传递。

关于phpunit - 如何在文本输出中获取简单的 phpunit codecoverage 摘要?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68589782/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com