Skip to content

Instantly share code, notes, and snippets.

@VladReshet
Created February 13, 2023 12:45
Show Gist options
  • Save VladReshet/7df7220fa35da2eca08fd4f58927679a to your computer and use it in GitHub Desktop.
Save VladReshet/7df7220fa35da2eca08fd4f58927679a to your computer and use it in GitHub Desktop.
pre-commit
CHANGED_FILES=$(git diff --name-only --cached --diff-filter=ACM -- '*.php')
if [ -n "$CHANGED_FILES" ]; then
echo -e "Running PHPUnit, please wait...\n";
# --rm removes container after work
# -v mounts current directory to container
# -t Allocate a pseudo-tty (to have colored output)
# $(pwd) gives the current directory
TESTS_RESULT=$(docker container run --name "phpunit-runner" --rm -t -v "$(pwd)":/src tests-runner:php8.1 php ./vendor/bin/phpunit --colors && echo "TESTS_PASSED");
echo "${TESTS_RESULT}";
# if output doesn't contain TESTS_PASSED string
if [[ "$TESTS_RESULT" != *"TESTS_PASSED"* ]]; then
echo -e "\nCommit Interrupted, Unit Tests Failed \n";
exit 1;
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment