4

我们有一个 Phing 脚本,Hudson 使用它来构建/测试我们的 PHP 站点。

我们的一些单元测试会加载主函数库;其他人使用模拟来避免这样做(或为测试提供特定的伪造结果)。

单独运行时(即在命令行上,使用phpunit),单元测试都可以完美运行。但是,当我们在 Phing 中将它们作为批处理一起运行时,会出现错误。

错误出现在我们为某些功能编写模拟的测试中。该错误表明我们要声明该函数两次。它显然是在尝试包含真正的函数库以及模拟。

测试包含互斥的代码,因此它们需要彼此隔离运行;看起来 Phing 正在一个进程中运行它们,因此包含冲突。

phing 脚本的相关部分如下所示:

<phpunit haltonfailure="true" printsummary="true">
  <batchtest>
    <fileset dir="${ws}/path/to/site/root/">
      <include name="*Test.php" />
      <include name="*/*Test.php" />
      <include name="*/*/*Test.php" />
      <include name="*/*/*/*Test.php" />
    </fileset>
  </batchtest>
  <formatter type="xml" todir="${builddir}/logs" outfile="units.xml" />
</phpunit>

有没有一种方法可以让 phing 彼此独立地运行测试,而无需在构建脚本中单独指定每个测试?

4

1 回答 1

1

那么最简单/最快的解决方法似乎是“不要使用 phing 任务,而是开始使用'真正的' phpunit 输出。

所以跑步<exec command="phpunit ... "> [...]

并使用 --coverage-html 并将其发布到 hudson 并使用 --coverage-clover 和 junit 开关将覆盖信息输入到 hudson。(参见jenkins-php.orgSetting up jenkins for php projects (there is a demo phpunit.xml.dist)供参考)


但是您可能不想这样做:/

from the Phing docs of the phpunit task据说我看不到直接告诉 phing 使用 switch 的方法--process-isolation

因此,也许其他人对此有解决方案。我没有一个仍然会产生代码覆盖率的东西。

从评论中

我将假设您有 2 段无法在单个进程中运行的独立测试代码,所以理想的情况是您可以说:

run 2 processes: "testsuite one do that, testsuite two do the other thing"
after that aggregate the results

可悲的是我不知道你怎么能告诉 phpunit 这样做。我会进一步调查,但现在我知道唯一可以肯定的是--process-isolation在整个测试套件中使用每个测试。如果有一种方法可以在一个单独的进程中运行整个套件,我不知道。


希望其他人对此有更简单的解决方案:)

于 2011-03-18T18:57:54.003 回答