Skip to content

Instantly share code, notes, and snippets.

@johnpbloch
Created May 20, 2013 18:50
Show Gist options
  • Select an option

  • Save johnpbloch/5614379 to your computer and use it in GitHub Desktop.

Select an option

Save johnpbloch/5614379 to your computer and use it in GitHub Desktop.
Run PHPUnit tests by group and report on pass/incomplete/fail by group
function testsbygroup(){
# Grab a list of groups
groups=`phpunit --list-groups | sed -rn 's/ - (.+)/\1/p'`
if [[ ! $groups ]]; then
return 1
fi
# Set up some empty arrays
pass=()
incomplete=()
fail=()
for x in $groups; do
# Run the tests, capturing the output
unittestoutput=`phpunit --group $x 2>&1`
# Put the group into the right array based on whether it passed, was incomplete, or failed
# Fallback is to mark the group as failing if we can't verify passing or incomplete
if [[ `echo $unittestoutput | ack 'OK \('` ]]; then
pass=("${pass[@]}" "$x")
elif [[ `echo $unittestoutput | ack 'OK, '` ]]; then
incomplete=("${incomplete[@]}" "$x")
else
fail=("${fail[@]}" "$x")
fi
done
# Display the passing groups
echo -e "\e[1;32mPass\e[0m"
for g in ${pass[@]}; do echo $g; done
# Display the incomplete groups
echo -e "\e[1;33mIncomplete\e[0m"
for g in ${incomplete[@]}; do echo $g; done
# Display the failing groups
echo -e "\e[1;31mFail\e[0m"
for g in ${fail[@]}; do echo $g; done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment