Skip to content

Instantly share code, notes, and snippets.

@ricardoboss
Forked from jasonbradley/run-tests
Last active January 22, 2020 09:30
Show Gist options
  • Save ricardoboss/45df6ab57e258e8a1bd638697f18fec9 to your computer and use it in GitHub Desktop.
Save ricardoboss/45df6ab57e258e8a1bd638697f18fec9 to your computer and use it in GitHub Desktop.
Bash script for running PHPUnit tests. Intended for use a pre-push git hook. Uses the project specific PHPUnit executable (vendor/bin/phpunit), the system-wide PHPUnit executable or phpunit.phar, whatever it finds first in this order.
#!/bin/bash
PHPUNIT_COMMAND=""
PHPUNIT_ARGS="--stderr --no-coverage"
# get phpunit executable (composer bin > system bin > phar file)
if [ -f "vendor/bin/phpunit" ]; then
PHPUNIT_COMMAND="vendor/bin/phpunit"
elif hash phpunit 2>/dev/null; then
PHPUNIT_COMMAND="phpunit"
elif [ -e phpunit.phar ]; then
PHPUNIT_COMMAND="phpunit.phar"
fi
# check if phpunit was found
if [ ! -z "$PHPUNIT_COMMAND" ]; then
if [ "phpunit.phar" = "$PHPUNIT_COMMAND" ]; then
$OUTPUT = `php "$PHPUNIT_COMMAND" $PHPUNIT_ARGS | tail -n 2`
else
$OUTPUT = `"$PHPUNIT_COMMAND" $PHPUNIT_ARGS | tail -n 2`
fi
echo $OUTPUT
fi
# do nothing if no phpunit was found
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment