我有一个PHP项目,包含一些单元和一些集成测试 . 我使用Jenkins部署它:本地在我的Ubuntu VM上和在Windows Server 2008 r2上的测试服务器上 .
本地VM和测试服务器的 build.xml
和 phpunit.xml
在整体上是相同的(差异仅在于斜杠以及如何调用 phpunit
之类的服务,如下所示) . 但代码覆盖率报告显示不同的结果 . 在本地,代码覆盖率大约比服务器上高 10%
:
local VM (Ubuntu)
PHPUnit代码覆盖率:行90.24%,函数和方法95.31%,类和特征85.00%
三叶草PHP覆盖率报告:代码覆盖率 - 77%(5295/6880元素):77%(5295/6880元素),方法79.3%,声明76.5%
test server (Windows Server 2008 r2)
PHPUnit代码覆盖率:行81.89%,函数和方法85.25%,类和特征57.81 %%
三叶草PHP覆盖率报告:代码覆盖率 - 77%(5295/6880元素):77%(5295/6880元素),方法79.3%,声明76.5%
What might cause such a difference and how to correct it?
more info
local 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 on the server:
<?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>
local 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 on the server:
<?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>
UPDATE
软件版本:
local Ubuntu VM
-
PHP
7.0.3
-
Xdebug
2.4.0RC4
-
PHPUnit
6.2.2
Windows 2008 server
-
PHP
7.0.2
-
PHPUnit
6.2.2