#!/bin/bash

logfile=./testdox.xml
if test -f "$logfile"; then
    echo "Logfile found. Searching for failed tests..."
    failed_tests="$(xmlstarlet tr --omit-decl ./vendor/chrisdicarlo/phpunit-failed-runner/failed-tests.xsl testdox.xml)"

    if [ "$failed_tests" = "" ]; then
        echo "No failed tests!  Great job!"
        rm ./testdox.xml
    else
        ./vendor/bin/phpunit --filter "'$failed_tests'"
    fi

else
    echo "Logfile not found. Running the full test suite..."
    ./vendor/bin/phpunit
fi

exit 0
