问题
I'm going to integrate PHP project with Jenkins follow this guide.
Here's my build.xml file
This one is from the output when running ant -f build.xml
:
phpunit:
[exec] PHPUnit 3.6.10 by Sebastian Bergmann.
[exec] Usage: phpunit [switches] UnitTest [UnitTest.php]
[exec] phpunit [switches] <directory>
[exec] --log-junit <file> Log test execution in JUnit XML format to file.
[exec] --log-tap <file> Log test execution in TAP format to file.
[exec] --log-json <file> Log test execution in JSON format.
[exec] --coverage-clover <file> Generate code coverage report in Clover XML format.
[exec] --coverage-html <dir> Generate code coverage report in HTML format.
[exec] --coverage-php <file> Serialize PHP_CodeCoverage object to file.
[exec] --coverage-text=<file> Generate code coverage report in text format.
[exec] Default to writing to the standard output
[exec] ...
.
Snippet of the config around the line 132:
<target name="phpunit" description="Run unit tests with PHPUnit">
<exec executable="phpunit" failonerror="true"/>
</target>
phpunit/PHPUnit is installed:
pear list -c phpunit
Installed packages, channel pear.phpunit.de:
============================================
Package Version State
File_Iterator 1.3.1 stable
PHPUnit 3.6.10 stable
PHPUnit_MockObject 1.1.1 stable
PHP_CodeBrowser 1.0.2 stable
PHP_CodeCoverage 1.1.2 stable
PHP_Invoker 1.1.0 stable
PHP_Timer 1.0.2 stable
PHP_TokenStream 1.1.3 stable
Text_Template 1.1.1 stable
phpcpd 1.3.5 stable
phploc 1.6.4 stable
Reply to @oers Thu May 3 20:31:50 ICT 2012:
I've edited the build.xml file to something like this:
<target name="phpunit" description="Run unit tests with PHPUnit">
<exec executable="phpunit" failonerror="true"/>
<arg line="--log-junit ${basedir}/build/logs/phpunit.xml serving" />
</target>
but nothing changes.
回答1:
I've edited the build.xml file to something like this:
Your build.xml has an error in the tree structure.
--- build.xml
+++ build.xml.new
@@ -1,4 +1,5 @@
<target name="phpunit" description="Run unit tests with PHPUnit">
- <exec executable="phpunit" failonerror="true"/>
+ <exec executable="phpunit" failonerror="true">
<arg line="--log-junit ${basedir}/build/logs/phpunit.xml serving" />
+ </exec>
</target>
回答2:
As you can see from the output (Usage: ...), phpunit
needs some arguments to execute correctly. <exec executable="phpunit" failonerror="true"/>
will just print the help for phpunit
and exit (like calling phpunit
directly from the command line).
In the official guide for phpunit you are told to run phpunit like this:
<target name="phpunit">
<exec dir="${basedir}" executable="phpunit" failonerror="true">
<arg line="--log-xml ${basedir}/build/logs/phpunit.xml MoneyTest" />
</exec>
</target>
回答3:
In my case, I got this problem because I set an error BaseDir, the base dir should be set as same the project path or the same path of phpunit.xml.dist.
Anyway, You also can appoint phpunit config file path in build.xml like this
<target name="phpunit">
<exec dir="${basedir}" executable="phpunit" failonerror="true">
<arg line="-c /your/path/to/phpunit.xml.dist" />
<arg line="--log-xml ${basedir}/build/logs/phpunit.xml MoneyTest" />
</exec>
</target>
来源:https://stackoverflow.com/questions/10430740/ant-f-build-xml-exec-returned-2-with-phpunit