Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A pre-commit for running PHPUnit
#!/usr/bin/php
<?php
printf("%sGit pre-commit hook %1\$s", PHP_EOL);
$projectName = basename(getcwd());
exec('phpunit --configuration phpunit.xml', $output, $returnCode); // Assuming cwd here
if ($returnCode !== 0) {
$minimalTestSummary = array_pop($output);
printf("Test suite for %s failed: ", $projectName);
printf("( %s ) %s%2\$s", $minimalTestSummary, PHP_EOL);
return false; // exit(1);
}
printf("All tests for %s passed.%s%2\$s", $projectName, PHP_EOL);
return true; // exit(0);
@sebastianbergmann

This comment has been minimized.

Copy link

sebastianbergmann commented Sep 20, 2010

--configuration phpunit.xml is not required as phpunit.xml is automatically used by default.

@buddhamagnet

This comment has been minimized.

Copy link

buddhamagnet commented Nov 5, 2013

This don't work bad boy!

@buddhamagnet

This comment has been minimized.

Copy link

buddhamagnet commented Nov 5, 2013

This did work:

#!/usr/bin/env php

<?php

$projectName = basename(getcwd());

exec('vendor/bin/phpunit', $output, $returnCode);

if ($returnCode !== 0) {
  $minimalTestSummary = array_pop($output);
  printf("Test suite for %s failed: ", $projectName);
  printf("( %s ) %s%2\$s", $minimalTestSummary, PHP_EOL);
  printf("ABORTING COMMIT!\n");
  exit(1);
}

exit(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.