Skip to content

Instantly share code, notes, and snippets.

@paulund
Last active Nov 2, 2020
Embed
What would you like to do?
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