Skip to content

Instantly share code, notes, and snippets.

@oqq
Created February 17, 2017 09:00
Show Gist options
  • Save oqq/c7c2a7ae509206e762dc58afaa360bff to your computer and use it in GitHub Desktop.
Save oqq/c7c2a7ae509206e762dc58afaa360bff to your computer and use it in GitHub Desktop.
#!/usr/bin/env php
<?php declare(strict_types=1);
$projectName = basename(getcwd());
echo <<<EOT
+ Starting unit tests for \033[1m\033[37;44m ${projectName} \033[0m.
EOT;
exec('vendor/bin/phpunit', $output, $returnCode);
if (0 === $returnCode) {
echo <<<EOT
+ All tests \033[1m\033[47;42m passed \033[0m.
+ Proceeding with commit. Have a nice day.
EOT;
exit(0);
}
while (null !== ($summary = array_pop($output))) {
if (false !== strpos($summary, 'Tests:')) {
break;
}
}
echo <<<EOT
+ Test suite \033[1m\033[47;41m failed \033[0m:
$summary\033[0m
+ \033[1m\033[47;41m ABORTING COMMIT \033[0m
EOT;
exit($returnCode);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment