【问题标题】:ant -f build.xml: exec returned: 2 with phpunit?ant -f build.xml: exec 返回: 2 with phpunit?
【发布时间】:2015-07-02 04:05:02
【问题描述】:

我将按照this 指南将 PHP 项目与 Jenkins 集成。

这是我的build.xml file

这个来自the output运行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] ...

.

第 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 Thu May 3 20:31:50 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>

但没有任何变化。

【问题讨论】:

    标签: ant jenkins phpunit


    【解决方案1】:

    我已将 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>
    

    【讨论】:

      【解决方案2】:

      从输出中可以看出(用法:...),phpunit 需要一些参数才能正确执行。 &lt;exec executable="phpunit" failonerror="true"/&gt; 只会打印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>
      

      【讨论】:

      • PHPUnit 3.6.10 使用--log-junit 开关,我一直在尝试这个选项,但得到了相同的结果。请查看我更新的问题。
      • @quanta 如果您在收到使用消息之前向 phpunit 提供了错误的参数,请确保服务目录是正确的。这可能只是您设置的本地问题,很难远程分析。
      【解决方案3】:

      在我的情况下,我遇到了这个问题,因为我设置了一个错误 BaseDir,基本目录应该设置为与项目路径相同或与 phpunit.xml.dist 相同的路径。

      无论如何,你也可以像这样在 build.xml 中指定 phpunit 配置文件路径

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

      【讨论】:

        猜你喜欢
        • 2012-07-31
        • 2014-10-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-08-14
        • 1970-01-01
        相关资源
        最近更新 更多