Ariel Mejia
June 3rd, 2021 - 1 min read
Husky
is an excellent tool to automate hooks
, in this post we are running phpunit
tests before pushing code
npm install husky@4 --save-dev
On package.json
file add this code
"husky": {
"hooks": {
"pre-push": "php artisan test"
}
},
Husky
also allows to add hooks
before adding a commit
If you want to learn how to install and configure PHPInsights
or
any other package for static analyze
the links are at the end of the post
You can run any package or custom command, in this case I will add a artisan command from PHPInsights
.
"husky": {
"hooks": {
"pre-commit": "php artisan insights -v",
"pre-push": "php artisan test"
}
},
pre-commit
hookYou can configure Husky
to add more than one command on any hook
by adding &&
between every command
In this case it would be configured to run PHPInsights
and PHPCSFixer
, but you can run any package or custom command
"husky": {
"hooks": {
"pre-commit": "php artisan insights -v && vendor/bin/php-cs-fixer fix",
"pre-push": "php artisan test"
}
},
Thanks for reading!
Sign up & get tips and tricks
You'll get monthly updates regarding my most recent articles and products.