Skip to content

Instantly share code, notes, and snippets.

@mihaeu
Last active June 2, 2016 06:49
Show Gist options
  • Save mihaeu/7526e9172231936b1b3fe712d814096d to your computer and use it in GitHub Desktop.
Save mihaeu/7526e9172231936b1b3fe712d814096d to your computer and use it in GitHub Desktop.
Bash script to insure that your code coverage is above a certain limit (e.g. for the CI server or pre-commit hook)
#!/usr/bin/env bash
# This is just a quick hack to determine if the code coverage
# is enough or not. Change the path to PHPUnit if needed.
#
# @author Michael Haeuslmann <haeuslmann@gmail.com>
NO_COLOR='\x1b[0m'
OK_COLOR='\x1b[32;01m'
ERROR_COLOR='\x1b[31;01m'
WARN_COLOR='\x1b[33;01m'
min_cov=95
cov=`vendor/bin/phpunit --coverage-text --colors=never \
| egrep -o "Lines:[[:space:]]+([0-9])+" \
| head -n1 \
| sed 's/Lines: *//'`
if [ "$cov" -eq "100" ]; then
printf "${OK_COLOR}✓ Coverage is $cov%%${NO_COLOR}\n"
elif [ "$cov" -ge "$min_cov" ]; then
printf "${WARN_COLOR}! Coverage is only $cov%%${NO_COLOR}\n"
else
printf "${ERROR_COLOR}✗ Coverage is only $cov%%, but needs to be at least $min_cov%%${NO_COLOR}\n"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment