Skip to content

Instantly share code, notes, and snippets.

@ghostwriter
Created May 11, 2017 02:50
Show Gist options
  • Select an option

  • Save ghostwriter/be79c57813e889ad098a2a8a0c8d50b2 to your computer and use it in GitHub Desktop.

Select an option

Save ghostwriter/be79c57813e889ad098a2a8a0c8d50b2 to your computer and use it in GitHub Desktop.
Git pre-commit hook for PHPUnit
#!/usr/bin/env php
<?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 "Cannot commit changes untill all tests pass." . 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