Skip to content

Instantly share code, notes, and snippets.

@mamor
Created May 29, 2014 12:34
Show Gist options
  • Save mamor/fac1e1c75e3e0bcc2f9b to your computer and use it in GitHub Desktop.
Save mamor/fac1e1c75e3e0bcc2f9b to your computer and use it in GitHub Desktop.
example-for-pre-commit
#!/usr/bin/php
<?php
// @see https://gist.github.com/raphaelstolt/588697
printf("%sGit pre-commit hook %1\$s", PHP_EOL);
putenv('PATH=/usr/local/bin');
$projectRoot = getcwd();
$projectName = basename($projectRoot);
$run = function ($projectName, $command) {
exec($command, $output, $returnCode);
if ($returnCode) {
$minimalTestSummary = array_pop($output);
printf("Test suite for %s failed: ", $projectName);
printf("( %s ) %s%2\$s", $minimalTestSummary, PHP_EOL);
exit(1);
}
};
// PHPUnit
$command = sprintf("cd %s && phpunit", $projectRoot);
$run($projectName, $command);
// Jasmine
$command = sprintf("cd %s && gulp karma", $projectRoot);
$run($projectName, $command);
printf("All tests for %s passed.%s%2\$s", $projectName, PHP_EOL);
exit(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment