为外部项目配置XDebug代码覆盖率

时间:2017-05-24 12:08:41

标签: jenkins ant phpunit xdebug

我有两个php项目:ProjectA和ProjectA-Test。 ProjectA包含应用程序的所有类和方法,而ProjectA-Test包含这些类的PHPUnit测试。

我正在尝试在Jenkins中设置代码覆盖率报告,以确定这些测试的覆盖范围。测试都运行正确,但代码覆盖率报告是ProjectA-Test,而不是ProjectA。

我使用ant来触发PHPUnit测试:

<target name="phpunit" description="Run unit tests with PHPUnit">
   <exec executable="phpunit" failonerror="true" />
</target>

我的phpunit.xml文件如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<phpunit strict="true" verbose="true">
    <testsuites>
        <testsuite name="ProjectA-Test">
            <directory suffix='.php'>./src/</directory>
        </testsuite>
    </testsuites>

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

    <logging>
        <log type="coverage-html" target="build/coverage" title="Project A Test" charset="UTF-8" yui="true" highlight="true" lowUpperBound="35" highLowerBound="70"/>
        <log type="junit" target="build/logs/phpunit.xml" logIncompleteSkipped="false"/>
    </logging>

</phpunit>

目录结构如下所示:

.
├── ProjectA
|   └── <PHP Files being tested>
└── ProjectA-Test
    ├── src
    |   └── <Unit test are all here>
    ├── build
    |   ├── logs
    |   |   └── phpunit.xml
    |   └── coverage
    |       └── <coverage reports are saved here>
    ├── phpunit.xml
    └── build.xml

每个测试都注释如下:

/**
 * @covers \ProjectA\ClassBeingTested::method_being_tested()
 */

如何配置XDebug来设置代码覆盖率以评估ProjectA类,而不是ProjectA-Test文件?

1 个答案:

答案 0 :(得分:0)

问题解决了。我在phpunit.xml的白名单部分输入了一个拼写错误