Run PHPUnit tests automatically before pushing code in Laravel

Install Husky

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

Run all laravel tests after pushing code:

On package.json file add …


This content originally appeared on DEV Community and was authored by Ariel Mejia

Install Husky

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

Run all laravel tests after pushing code:

On package.json file add this code:

    "husky": {
        "hooks": {
            "pre-push": "php artisan test"
        }
    },

Go further

Husky also allows to add hooks before adding a commit.

Add pre commit hooks

If you want to learn how to install and configure PHPInsights or any other package for static analyze the links for posts 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"
        }
    },

Adding more than one pre-commit hook

You can configure Husky to add more than one command on any hook by adding "&&" between every command.

In this case it would be configure 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"
        }
    },

That is all for this post, thanks for reading.


This content originally appeared on DEV Community and was authored by Ariel Mejia


Print Share Comment Cite Upload Translate Updates
APA

Ariel Mejia | Sciencx (2021-06-03T18:49:13+00:00) Run PHPUnit tests automatically before pushing code in Laravel. Retrieved from https://www.scien.cx/2021/06/03/run-phpunit-tests-automatically-before-pushing-code-in-laravel/

MLA
" » Run PHPUnit tests automatically before pushing code in Laravel." Ariel Mejia | Sciencx - Thursday June 3, 2021, https://www.scien.cx/2021/06/03/run-phpunit-tests-automatically-before-pushing-code-in-laravel/
HARVARD
Ariel Mejia | Sciencx Thursday June 3, 2021 » Run PHPUnit tests automatically before pushing code in Laravel., viewed ,<https://www.scien.cx/2021/06/03/run-phpunit-tests-automatically-before-pushing-code-in-laravel/>
VANCOUVER
Ariel Mejia | Sciencx - » Run PHPUnit tests automatically before pushing code in Laravel. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/06/03/run-phpunit-tests-automatically-before-pushing-code-in-laravel/
CHICAGO
" » Run PHPUnit tests automatically before pushing code in Laravel." Ariel Mejia | Sciencx - Accessed . https://www.scien.cx/2021/06/03/run-phpunit-tests-automatically-before-pushing-code-in-laravel/
IEEE
" » Run PHPUnit tests automatically before pushing code in Laravel." Ariel Mejia | Sciencx [Online]. Available: https://www.scien.cx/2021/06/03/run-phpunit-tests-automatically-before-pushing-code-in-laravel/. [Accessed: ]
rf:citation
» Run PHPUnit tests automatically before pushing code in Laravel | Ariel Mejia | Sciencx | https://www.scien.cx/2021/06/03/run-phpunit-tests-automatically-before-pushing-code-in-laravel/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.