在php脚本中使用phpunit CLI输出

时间:2011-12-01 13:49:40

标签: php phpunit

phpunit测试的CLI输出包含有用的信息,例如:

PHPUnit 3.6.4 by Sebastian Bergmann.
F
Time: 7 seconds, Memory: 5.50Mb
There was 1 failure:
1) testHandler::testItem
Failed asserting that page text contains <itest New Family Name>.

Driver.php:632
testHandler.php:29
S163.php:18
testHandler.php:46

FAILURES!
Tests: 1, Assertions: 97, Failures: 1.

我想通过php curl通过POST将此信息发送到我的测试跟踪软件。

但是我找不到在我的测试类中捕获信息的方法(它扩展了PHPUnit_Framework_TestCase)。

任何帮助/想法都将不胜感激。

1 个答案:

答案 0 :(得分:1)

如果您有自定义构建解决方案,最简单的方法似乎是:

phpunit | curl -X http://url

phpunit 2>&1 > output.txt && cat output.txt | curl -X http://url

或类似的东西。

如果您使用的是正确的Continuous Integration服务器,请查看--log-junit--coverage-clover或其他输出格式,例如--log-json

我没有看到任何理由让您在测试运行时以编程方式获取输出。它似乎比获得更多的工作。有一些方法可以扩展PHPUnit以将其与bugtrackers集成。看看PHPUnit_Framework_TestListener