Skip to content

Instantly share code, notes, and snippets.

@paulund
Last active November 2, 2020 22:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulund/20aa6fa2815ceb6cee0b24794eb0d1c6 to your computer and use it in GitHub Desktop.
Save paulund/20aa6fa2815ceb6cee0b24794eb0d1c6 to your computer and use it in GitHub Desktop.
Run phpunit tests before push and error if the tests fail
#!/bin/bash
git diff --cached --name-only | while read FILE; do
if [[ "$FILE" =~ ^.+(php|inc|module|install|test)$ ]]; then
echo "Running tests..."
cd "${0%/*}/.."
phpunit 1> /dev/null
if [ $? -ne 0 ]; then
echo -e "\e[1;31m\tUnit tests failed ! Aborting commit.\e[0m" >&2
exit 1;
fi
fi
done || exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment