Skip to content

Instantly share code, notes, and snippets.

Last active Nov 2, 2020
What would you like to do?
Run phpunit tests before push and error if the tests fail
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;
done || exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment