Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/238.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHPUnit和Clover代码覆盖率报告:测试未执行,命令退出_Php_Phpunit_Code Coverage_Clover_Php Code Coverage - Fatal编程技术网

PHPUnit和Clover代码覆盖率报告:测试未执行,命令退出

PHPUnit和Clover代码覆盖率报告:测试未执行,命令退出,php,phpunit,code-coverage,clover,php-code-coverage,Php,Phpunit,Code Coverage,Clover,Php Code Coverage,我“继承”了一个只与PHP5.6兼容的非常老的PHP项目,并且没有任何框架,我正在尝试为PHP7.x“现代化”,并添加一些单元测试和一些代码检查工具,如SonarQube with Jenkins 该项目有一些可执行脚本,需要正确执行一些参数,当我在启用生成Clover覆盖率的情况下执行phpunit时,它会尝试执行这些脚本,但由于缺少必需的参数,这些脚本失败: ⋊> ~/P/myproject on mybranch ⨯ ./phpunit tests/ PHPUnit 5.7.27 b

我“继承”了一个只与PHP5.6兼容的非常老的PHP项目,并且没有任何框架,我正在尝试为PHP7.x“现代化”,并添加一些单元测试和一些代码检查工具,如SonarQube with Jenkins

该项目有一些可执行脚本,需要正确执行一些参数,当我在启用生成Clover覆盖率的情况下执行phpunit时,它会尝试执行这些脚本,但由于缺少必需的参数,这些脚本失败:

⋊> ~/P/myproject on mybranch ⨯ ./phpunit tests/
PHPUnit 5.7.27 by Sebastian Bergmann and contributors.

Runtime:       PHP 7.4.5 with Xdebug 2.9.5
Configuration: /Users/me/Projects/myproject/phpunit.xml


You must specify a source (--source)!
这是来自项目根文件夹的
files index.php
命令的输出,需要运行
--source
参数:

[...]

if (!$args['source']) {
    exit("You must specify a source (--source)!\n");
}

[...]
我不明白的是,如果我在没有启用覆盖率报告的情况下执行PHPUnit,那么项目中的(少数)测试执行时不会出现错误(无论如何,文件
files index.php
目前没有测试):

这是我的
phpunit.xml
文件:

⋊> ~/P/myproject on mybranch ⨯ cat phpunit.xml                                                                                               22:10:25
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="phpunit.xsd"
         backupGlobals="false"
         verbose="true">

    <testsuites>
        <testsuite name="My Project">
            <directory>./tests</directory>
        </testsuite>
    </testsuites>

    <filter>
        <whitelist processUncoveredFilesFromWhitelist="true">
            <directory suffix=".php">.</directory>
            <exclude>
                <directory suffix=".php">./vendor</directory>
                <directory suffix=".php">./_classes</directory>
            </exclude>
        </whitelist>
    </filter>

    <logging>
        <log type="junit" target="./reports/logfile.xml"/>
        <log type="coverage-clover" target="./reports/coverage.xml"/>
    </logging>

    <php>
        <const name="PHPUNIT_TESTSUITE" value="true"/>
    </php>
</phpunit>
⋊> ~/mybranch上的P/myproject⨯ cat phpunit.xml 22:10:25
/测试
.
/供应商
./\u类

我错在哪里?

exit
在php(单元)(测试)中非常麻烦,因为它存在于运行时。将文件保存在测试之外(同样地考虑将它们放入测试中,而不是<代码>退出>代码>,不完全好,但我知道的一种方式是使用异常来表示退出状态,您的里程可能会有所不同)。我不太确定phpunit代码的覆盖率,因为我不希望它包含白名单文件(因此可能更像是您代码库中的一个问题),但是比白名单中的“
”更好的是明确排除错误消息来自该文件。
exit
在php(单元)(测试)中非常麻烦,因为它存在于运行时。将文件保存在测试之外(同样地考虑将它们放入测试中,而不是<代码>退出>代码>,不完全好,但我知道的一种方式是使用异常来表示退出状态,您的里程可能会有所不同)。我不太确定phpunit代码的覆盖范围,因为我不希望它包括白名单文件(因此可能在您的代码库中是一个更大的问题),但是比白名单中的“
”更好的是明确排除错误消息来自它的文件。
⋊> ~/P/myproject on mybranch ⨯ cat phpunit.xml                                                                                               22:10:25
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="phpunit.xsd"
         backupGlobals="false"
         verbose="true">

    <testsuites>
        <testsuite name="My Project">
            <directory>./tests</directory>
        </testsuite>
    </testsuites>

    <filter>
        <whitelist processUncoveredFilesFromWhitelist="true">
            <directory suffix=".php">.</directory>
            <exclude>
                <directory suffix=".php">./vendor</directory>
                <directory suffix=".php">./_classes</directory>
            </exclude>
        </whitelist>
    </filter>

    <logging>
        <log type="junit" target="./reports/logfile.xml"/>
        <log type="coverage-clover" target="./reports/coverage.xml"/>
    </logging>

    <php>
        <const name="PHPUNIT_TESTSUITE" value="true"/>
    </php>
</phpunit>