2

我创建了一个小包,我想获得一些资格。所以其中之一是Scrutinizer覆盖率和代码质量。与教程中一样,我创建了一个文件并将其重命名为scrutinizer.yml并将以下内容放入其中:

build:
tests:
    override:
        -
            command: 'vendor/bin/phpunit --coverage-clover=some-file'
            coverage:
                file: 'some-file'
                format: 'clover'

但是在我的Scrutinizer个人资料中同步后,我得到了这个“覆盖率 NaN%”

所以我该怎么做?

4

1 回答 1

1

我找到了。它与PHPUnit的设置有关。我创建了一个文件并将其重命名为 phpunit.xml 并将以下配置代码放入其中。

<phpunit backupGlobals="false"
     backupStaticAttributes="false"
     colors="true"
     convertErrorsToExceptions="true"
     convertNoticesToExceptions="true"
     convertWarningsToExceptions="true"
     processIsolation="false"
     stopOnFailure="false"
     syntaxCheck="false"
>
<testsuites>
    <testsuite name="Package Test Suite">
        <directory suffix=".php">./tests/</directory>
    </testsuite>
</testsuites>
</phpunit>

并在运行 phpunit 后创建本地coverage.xml 文件;它给了我以下错误:

Error:         No code coverage driver is available

我经过一番搜索后发现我必须将以下代码插入 phpunit.xml

<filter>
    <whitelist processUncoveredFilesFromWhitelist="true">
        <directory suffix=".php">src</directory>
    </whitelist>
</filter>

所以最终的 phpunit.xml 文件是

<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
         backupStaticAttributes="false"
         colors="true"
         convertErrorsToExceptions="true"
         convertNoticesToExceptions="true"
         convertWarningsToExceptions="true"
         processIsolation="false"
         stopOnFailure="false"
         syntaxCheck="false"
>
    <testsuites>
        <testsuite name="Package Test Suite">
            <directory suffix=".php">./tests/</directory>
        </testsuite>
    </testsuites>

    <filter>
        <whitelist processUncoveredFilesFromWhitelist="true">
            <directory suffix=".php">src</directory>
        </whitelist>
    </filter>
</phpunit>
于 2018-04-22T06:25:18.477 回答