You can prevent developers pushing broken tests to Git repository by using client-side pre-push git hook. Example below checks PHP coding standards with php-cs-fixer as defined in the PSR-1 and PSR-2.


Git hook


This file goes into .git/hooks/ folder of your project where all the other sample hooks are stored. Name it as pre-push.


#!/bin/sh

if [ -f ./bin/php-cs-fixer ]
then
./bin/php-cs-fixer fix --dry-run --quiet src
if [ $? -ne 0 ]
then
RED='\033[0;31m'
CYAN='\033[0;36m'
NA='\033[0m'

printf "\n\t${CYAN}[GIT POLICY]${NA} PHP-CS-Fixer has failed - ${RED}Push Aborted${NA}\n\n"

return 1
fi
fi

Setup


$ chmod +x .git/hooks/pre-push

Test