2012-05-03 36 views
0

我將與Jenkins集成PHP項目,並遵循this指南。ant -f build.xml:exec返回:2與phpunit?

下面是運行ant -f build.xml當我build.xml file

這一個是從the output

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] ... 

繞線的配置的代碼段132:

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

的PHPUnit/PHPUnit的安裝:

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 

回覆@oers星期四5月3日20點31分五十○秒ICT 2012:

我編輯了build.xml文件,如下所示:

<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> 

但沒有什麼變化。

回答

0

正如你所看到的從輸出(用法:...),phpunit需要一些參數才能正確執行。 <exec executable="phpunit" failonerror="true"/>只會打印phpunit的幫助並退出(如直接從命令行調用phpunit)。

the official guide for phpunit你被告知這樣運行的PHPUnit:

<target name="phpunit"> 
    <exec dir="${basedir}" executable="phpunit" failonerror="true"> 
    <arg line="--log-xml ${basedir}/build/logs/phpunit.xml MoneyTest" /> 
    </exec> 
</target> 
+0

PHPUnit的3.6.10使用'--log-junit'開關,我一直想這個選項,但是有相同的結果。請查看我更新的問題。 – quanta

+0

@quanta如果你直到收到使用信息,那麼你提供了錯誤的參數給phpunit,請確保服務是一個正確的目錄。這可能只是您的設置的一個本地問題,這很難遠程分析。 – oers

2

我已經編輯build.xml文件,這樣的事情:

你的build.xml有一個樹結構中的錯誤。

--- 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> 
0

就我而言,我是因爲我設置錯誤的BaseDir,基本目錄應設置爲相同的項目路徑或phpunit.xml.dist相同的路徑得到了這個問題。

反正,你也可以指定PHPUnit的配置文件路徑中的build.xml這樣

<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>