Skip to content

Instantly share code, notes, and snippets.

@pierswarmers
Created March 9, 2015 23:50
Show Gist options
  • Select an option

  • Save pierswarmers/0c0c5f80d31daa94a461 to your computer and use it in GitHub Desktop.

Select an option

Save pierswarmers/0c0c5f80d31daa94a461 to your computer and use it in GitHub Desktop.
PHP Project: Syntax Checker, Unit Test and Git Commiter
#!/bin/bash
guiltmode=0
browse=0
push=0
iconbeer="🍺"
phpunitconfig="app"
phpunitdir="src"
coveragelocation="./coverage/index.html"
function line()
{
echo " ";
echo "β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦β—¦"
echo " ";
echo -e "$1";
}
function usage
{
echo "Check version 0.0.1"
echo "usage: check [options]"
echo ""
echo "Example: ./check.sh -g -b -p -m \"Fixed the stuff and things.\""
echo ""
echo "-m Add a git commit message"
echo "-p Push git commits, requires -m to be set."
echo "-b Open a browser window pointed at coverage report"
echo "-g Run the coverage suite, requires -g to be set."
echo "-h Prints this help message"
}
while [ "$1" != "" ]; do
case $1 in
-m | --message ) shift
message=$1
;;
-p | --push ) push=1
;;
-g | --guilt-mode ) guiltmode=1
;;
-b | --browse ) browse=1
;;
-h | --help ) usage
exit
;;
* ) usage
echo $1
exit 1
esac
shift
done
line "Running Compilation Tests and fixing syntax...\n"
git diff --name-only | while read FILE; do
if [[ "$FILE" =~ ^.+(php)$ ]]; then
if [[ -f $FILE ]]; then
php -l "$FILE" 1> /dev/null
if [ $? -ne 0 ]; then
echo -e "βœ—\tAborting due to syntax issue in: $FILE" >&2
exit 1
fi
fi
php-cs-fixer fix --level=symfony "$FILE" 1> /dev/null
if [ $? -ne 0 ]; then
echo -e "βœ—\tphp-cs-fixer: corrected issues in $FILE, continuing..." >&2
else
echo -e "βœ“\tphp-cs-fixer: passed check in $FILE"
fi
fi
done
if [ $? -eq 0 ]; then
line "Running PHPUnit Tests"
if [ $guiltmode -eq 0 ]; then
phpunit -c app src
else
phpunit --coverage-html coverage -c $phpunitconfig $phpunitdir
if [ $browse -eq 1 ]; then
open $coveragelocation
fi
fi
if [ $? -ne 0 ]; then
line "βœ—\tphpunit: failed" >&2
exit 1
else
line "βœ“\tphpunit: passed"
if [ ! -z "$message" ]; then
line "Commiting: $message"
git commit -am "$message"
if [ $push -eq 1 ]; then
git push
fi
line "$iconbeer ... beer o'clock!\n"
else
line "All checks passed. Carry on!\n"
fi
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment