djt djt - 1 year ago 88
PHP Question

PHPUnit - Bash Script Output to Variable

I'm trying to capture the output of my test suite from PHPUnit to determine whether a failure occurred. However, when I attempt to store the output in a bash variable, the variable is always empty:


if [ -z "$PHPUNIT_RESULT" ]; then
echo "something there!

However, the variable always seems to be empty.

EDIT: Sample output

PHPUnit 3.4.5 by Sebastian Bergmann.


Time: 0 seconds, Memory: 8.00Mb

There was 1 failure:

1) MyTest::testTemp
Failed asserting that <boolean:false> is true.


Tests: 4, Assertions: 5, Failures: 1, Incomplete: 1.

Answer Source

if there's any test failure, phpunit will exit with a non-zero status. you can check this with the $? variable.

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

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