PHPUnit - Bash 脚本输出到变量

PHPUnit - Bash Script Output to Variable

我正在尝试从 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.

如果有任何测试失败,phpunit 将以非零状态退出。你可以用 $? 变量来检查。

./vendor/bin/phpunit /path/to/myTest.php

if [ $? -ne 0 ]; then
        echo "failed test"
fi