-
-
Save okovalov/d4668f37540b2ff5e27fcb48c5610916 to your computer and use it in GitHub Desktop.
Run phpunit pre-commit stop commit if failed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/php | |
<?php | |
## SETUP | |
$isPhpCsPass = false; | |
$isPhpMdPass = false; | |
$isPhpUnitPass = false; | |
## PHPCS | |
echo PHP_EOL; | |
echo 'Starting phpcs' . PHP_EOL; | |
exec( 'php artisan sniff', $test_output, $returnCode ); | |
if ( 0 !== $returnCode ) { | |
echo implode( PHP_EOL, $test_output ); | |
echo PHP_EOL; | |
echo "Php code sniffer failed. Exiting. Please see the output above." . PHP_EOL; | |
exit(1); | |
} | |
echo 'All phpcs passed.' . PHP_EOL; | |
$isPhpCsPass = true; | |
## PHPMD | |
echo PHP_EOL; | |
echo 'Starting phpmd' . PHP_EOL; | |
exec( '/usr/local/bin/phpmd ./app/ text ./phpmd.xml', $test_output, $returnCode ); | |
if ( 0 !== $returnCode ) { | |
echo implode( PHP_EOL, $test_output ); | |
echo PHP_EOL; | |
echo "Php mess detector failed. Exiting. Please see the output above." . PHP_EOL; | |
exit(1); | |
} | |
echo 'All phpmd passed.' . PHP_EOL; | |
$isPhpMdPass = true; | |
## PHPUNIT | |
echo PHP_EOL; | |
echo 'Starting php unit tests' . PHP_EOL; | |
exec( 'vendor/bin/phpunit', $test_output, $returnCode ); | |
if ( 0 !== $returnCode ) { | |
echo implode( PHP_EOL, $test_output ); | |
echo PHP_EOL; | |
echo "Php unit failed. Exiting. Please see the output above." . PHP_EOL; | |
exit(1); | |
} | |
echo 'All tests passed.' . PHP_EOL; | |
$isPhpUnitPass = true; | |
## Results verification | |
echo PHP_EOL; | |
if ($isPhpUnitPass && $isPhpCsPass && $isPhpMdPass) { | |
echo 'All is verified. You commit was successful. You can push now.' . PHP_EOL; | |
exit(0); | |
} | |
echo PHP_EOL; | |
echo "It should never be shown. Something went wronng. Please check your phpcs, phpmd and phpunit and try to commit again" . PHP_EOL; | |
exit(1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment