Skip to content

Instantly share code, notes, and snippets.

@epicsagas
Created June 4, 2020 06:05
Show Gist options
  • Save epicsagas/017ccf8c9c5a5e88c552dbe60ab6d6a0 to your computer and use it in GitHub Desktop.
Save epicsagas/017ccf8c9c5a5e88c552dbe60ab6d6a0 to your computer and use it in GitHub Desktop.
git pre-commit for phpunit
#!/usr/bin/env php
<?php
// locate this {project root}/.git/hooks/pre-commit)
// and make this runnable with chmod +x
echo "Running tests.. ";
exec('vendor/bin/phpunit', $output, $returnCode);
if ($returnCode !== 0) {
// Show full output
echo PHP_EOL . implode($output, PHP_EOL) . PHP_EOL;
echo "Aborting commit.." . PHP_EOL;
exit(1);
}
// Show summary (last line)
echo array_pop($output) . PHP_EOL;
exit(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment