Skip to content

Instantly share code, notes, and snippets.

@androzd
Last active September 24, 2015 18:56
Show Gist options
  • Select an option

  • Save androzd/98c9736607d7d2c69b20 to your computer and use it in GitHub Desktop.

Select an option

Save androzd/98c9736607d7d2c69b20 to your computer and use it in GitHub Desktop.
git pre-commit hook for symfony2. Runs phpunit test, before commit.
#!/usr/bin/php
<?php
echo PHP_EOL."\033[43mStarting unit tests\033[0m".PHP_EOL;
exec('phpunit -c app', $output, $returnCode);
if ($returnCode !== 0)
{
while (($minimalTestSummary = array_pop($output)) !== null)
{
if (strpos($minimalTestSummary, 'Tests:') !== false)
{
break;
}
}
echo "\033[41m+ Test suite for project failed:\033[0m".PHP_EOL;
echo $minimalTestSummary;
echo "\033[0m".PHP_EOL;
echo PHP_EOL;
exit(1);
}
echo "\033[42mAll tests for project passed.\033[0m".PHP_EOL.PHP_EOL;
exit(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment