Skip to content

Instantly share code, notes, and snippets.

@joelbutcher
Created May 15, 2020 13:18
Show Gist options
  • Save joelbutcher/5263c73ede7c2ed883d3aa40f95e53cd to your computer and use it in GitHub Desktop.
Save joelbutcher/5263c73ede7c2ed883d3aa40f95e53cd to your computer and use it in GitHub Desktop.
#!/usr/bin/env php
#
# Pre commit hook to run php unit tests.
# Place this file in .git/hooks and make it executable with:
#
# chmod +x .git/hooks/pre-commit
<?php
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