我有一个PHP项目,包含一些单元和一些集成测试。我使用Jenkins部署它:本地在我的Ubuntu VM上和Windows Server 2008 r2上的测试服务器上。
本地VM和测试服务器的build.xml
和phpunit.xml
在整体上是相同的(区别仅在于斜杠以及如何调用phpunit
之类的服务,s在下面)。但代码覆盖率报告显示不同的结果。在本地,代码覆盖率比服务器上高10%
:
本地VM(Ubuntu)
PHPUnit代码覆盖率:行90.24%,函数和方法95.31%,类和特征85.00%
Clover PHP覆盖率报告:代码覆盖率 - 77%(5295/6880元素):77%(5295/6880元素),方法79.3%,声明76.5%
测试服务器(Windows Server 2008 r2)
PHPUnit代码覆盖率:81.89%行,函数和方法85.25%,类和特征57.81 %%
Clover PHP覆盖率报告:代码覆盖率 - 77%(5295/6880元素):77%(5295/6880元素),方法79.3%,声明76.5%
可能导致这种差异的原因以及如何纠正?
更多信息
本地build.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<project name="MyProject" default="full-build">
...
<property name="phpunit" value="./vendor/bin/phpunit" />
<target name="full-build" depends="prepare,static-analysis,phpdox,phpunit,-check-failure" description="Performs static analysis, runs the tests, and generates project documentation." />
...
<target name="phpunit" unless="phpunit.done" depends="prepare" description="Run unit tests with PHPUnit">
<exec executable="${phpunit}" resultproperty="result.phpunit" taskname="phpunit">
<arg value="--configuration" />
<arg path="${basedir}/phpunit.xml" />
</exec>
<property name="phpunit.done" value="true" />
</target>
<target name="-check-failure">
<fail message="PHPUnit did not finish successfully">
<condition>
<not>
<equals arg1="${result.phpunit}" arg2="0" />
</not>
</condition>
</fail>
</target>
</project>
服务器上的 build.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<project name="MyProject" default="full-build">
...
<property name="phpunit" value="vendor\phpunit\phpunit\phpunit" />
<target name="full-build" depends="prepare,static-analysis,phpdox,phpunit,-check-failure" description="Performs static analysis, runs the tests, and generates project documentation." />
...
<target name="phpunit" unless="phpunit.done" depends="prepare" description="Run unit tests with PHPUnit">
<exec executable="cmd" resultproperty="result.phpunit" taskname="phpunit">
<arg value="/c" />
<arg value="phpdbg" />
<arg value="-qrr" />
<arg value="${phpunit}" />
<arg value="--configuration" />
<arg path="${basedir}/phpunit.xml" />
</exec>
<property name="phpunit.done" value="true" />
</target>
<target name="-check-failure">
<fail message="PHPUnit did not finish successfully">
<condition>
<not>
<equals arg1="${result.phpunit}" arg2="0" />
</not>
</condition>
</fail>
</target>
</project>
本地phpunit.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.1/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="test/Bootstrap.php"
cacheTokens="false"
colors="true"
>
<php>
<env name="RUNTIME_CONTEXT" value="testing"/>
</php>
<testsuites>
<testsuite name="unit-app-only">
<directory suffix="Test.php">test/Unit</directory>
</testsuite>
<testsuite name="integration-app-only">
<directory suffix="Test.php">test/Integration</directory>
</testsuite>
<testsuite name="app-lib">
<directory suffix="Test.php">vendor/my-lib/mlb-common-lib/tests</directory>
</testsuite>
</testsuites>
<logging>
<log type="coverage-html" target="build/coverage"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
<log type="coverage-crap4j" target="build/logs/crap4j.xml"/>
<log type="junit" target="build/logs/junit.xml" logIncompleteSkipped="false"/>
</logging>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">module/**/src</directory>
<directory suffix=".php">vendor/my-lib/**/src</directory>
<exclude>
<directory suffix=".php">vendor/my-lib/**/tests</directory>
</exclude>
</whitelist>
</filter>
</phpunit>
服务器上的 phpunit.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.1/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="test/Bootstrap.php"
cacheTokens="false"
colors="true"
>
<php>
<env name="RUNTIME_CONTEXT" value="testing"/>
</php>
<testsuites>
<testsuite name="unit-app-only">
<directory suffix="Test.php">test\Unit</directory>
</testsuite>
<testsuite name="integration-app-only">
<directory suffix="Test.php">test\Integration</directory>
</testsuite>
<testsuite name="app-lib">
<directory suffix="Test.php">vendor\my-lib\mlb-common-lib\tests</directory>
</testsuite>
</testsuites>
<logging>
<log type="coverage-html" target="build\coverage"/>
<log type="coverage-clover" target="build\logs\clover.xml"/>
<log type="coverage-crap4j" target="build\logs\crap4j.xml"/>
<log type="junit" target="build\logs\junit.xml" logIncompleteSkipped="false"/>
</logging>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">module\**\src</directory>
<directory suffix=".php">vendor\my-lib\**\src</directory>
<exclude>
<directory suffix=".php">vendor\my-lib\**\tests</directory>
</exclude>
</whitelist>
</filter>
</phpunit>
更新
软件版本:
本地Ubuntu VM
7.0.3
2.4.0RC4
6.2.2
Windows 2008服务器
7.0.2
6.2.2