files/default/git/hooks/cakephp/phpunit
#!/bin/bash -e
PROJECT=`pwd`
APP=""
PLUGIN=""
if [ ! -z `echo $PROJECT | egrep 'app/Plugin'` ]
then
APP=`echo $PROJECT | perl -pe 's/\/\w\+\/\w\+\/\w\+$//'`
PLUGIN=`echo $PROJECT | perl -pe 's/.*\/(\w\+)$/$1/'`
fi
FILES=""
for FILE in `git diff --cached --name-only --diff-filter=ACMR HEAD | egrep \\\\.\(php\|ctp\)\$`
do
FILES="$FILES $PROJECT/$FILE"
done
if [ "$FILES" != "" ]
then
echo "Running phpunit..."
for TEST in `git diff --cached --name-only --diff-filter=ACMR HEAD`
do
echo $TEST
if [ -z `echo $TEST | egrep \\Test\\.\(php\)\$` ]
then
TEST=`echo $TEST | perl -pe 's/([a-zA-Z0-9\/]+)\.php/$1/g'`
else
TEST=`echo $TEST | perl -pe 's/app\/Test\/Case\/([a-zA-Z0-9\/]+)Test\.php/$1/g'`
fi
echo $TEST
if [ "$PLUGIN" != "" ]
then
cd $APP
[ ! -r "app/${PLUGIN}/Test/Case/${TEST}Test.php" ] && continue
./lib/Cake/Console/cake test $PLUGIN $TEST --stderr --configuration phpunit.xml.dist || exit $?
else
[ ! -r "app/Test/Case/${TEST}Test.php" ] && continue
./lib/Cake/Console/cake test app $TEST --stderr --configuration phpunit.xml.dist || exit $?
fi
done
fi
exit 0