我正在尝试从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.
bash
中使用反引号进行命令替换是不被鼓励的。请改用$(...)
语法。无论哪种情况,vendor/bin/phpunit
的预期输出是什么? - Sebastian Lenartowicz$()
,结果相同。我已经更新了问题并附上了样本输出。它是多行输出。 - djt-z
运算符检查空字符串 - 因此,如果你打印出 "Something there!",它实际上意味着你正在获得输出! - Sebastian Lenartowicz