我将首先不回答您的实际问题,但这些建议可能对您要解决的任何潜在问题有用:
- 您可以have phpunit log results 以一种更方便的方式
机器阅读。
- PHP 是 BASH 的有效替代方案,可用于编写命令行脚本。我将 BASH 用于简单的东西,但是一旦它超出了几行,或者当我想添加循环、if 语句等时,我决定在 PHP 中正确地完成它。其他人可能会使用 perl 或 python。
在您的特定情况下,我会使用 PHP,而不是 BASH,因为它可能最终需要一些复杂的解析。但是让我们看看如何在 BASH 中做一些简单的事情。挑战在于输出可能如下所示:
PHPUnit 3.4.5 by Sebastian Bergmann.
......................................
Time: 10 seconds, Memory: 9.00Mb
OK (38 tests, 660 assertions)
或者可能看起来像这样:
PHPUnit 3.4.5 by Sebastian Bergmann.
............................................................ 60 / 380
............................................................ 120 / 380
...............................................S............ 180 / 380
.......S.................................................... 240 / 380
............................................................ 300 / 380
............................................................ 360 / 380
....................
Time: 01:44, Memory: 14.50Mb
OK, but incomplete or skipped tests!
Tests: 380, Assertions: 6546, Skipped: 2.
或者可能看起来像这样:
PHPUnit 3.4.5 by Sebastian Bergmann.
..IF
Time: 0 seconds, Memory: 8.00Mb
There was 1 failure:
1) MyTest::testTemp
Failed asserting that <boolean:false> is true.
/path/to/myTest.php:68
FAILURES!
Tests: 4, Assertions: 5, Failures: 1, Incomplete: 1.
我猜您的应用程序类似于每小时运行一次的 cron 作业来运行您的所有测试并确保没有任何问题。所以我就去use a regex寻找“FAILURES”这个词:
#!/bin/bash
RESULT=`phpunit tests/myTest.php`
if [[ $RESULT =~ FAILURES ]]
then
echo "Excuse me, Sir, but we have a problem in the unit tests...";echo "$RESULT"
fi
我正在使用反引号来捕获输出。一些 BASH 专家会告诉您改用 $()。无论哪种方式都适用:
....
RESULT=$(phpunit tests/myTest.php)
...