我正在尝试从PHPUnit捕获测试套件的输出,以确定是否发生了故障。但是,当我尝试将输出存储在bash变量中时,该变量始终为空:
PHPUNIT_RESULT=`vendor/bin/phpunit`
if [ -z "$PHPUNIT_RESULT" ]; then
echo "something there!
fi
但是,变量似乎总是空的。
编辑:示例输出
PHPUnit 3.4.5 by Sebastian Bergmann.
......F.......F
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.
答案 0 :(得分:3)
如果有任何测试失败,phpunit将以非零状态退出。您可以使用$?
变量进行检查。
./vendor/bin/phpunit /path/to/myTest.php
if [ $? -ne 0 ]; then
echo "failed test"
fi