TestPestTips and TricksTipsWeb Development

Dec 5, 2023

How to run Pint and Pest on Git hooks with Laravel Sail

By Antoni Putra, Fullstack Web Developer

How to run Pint and Pest on Git hooks with Laravel Sail

Developers use Git hooks to run scripts automatically when a specific Git event occurs, such as committing code changes. Pint and Pest are popular testing frameworks for PHP applications. Pint is a PHP code style checker, and Pest is a PHP testing framework. This tutorial shows you how to set up Git hooks for Pint and Pest while using Laravel Sail.

Laravel Sail is a lightweight command-line interface (CLI) for running Laravel applications in a Docker container. It simplifies the development environment setup process by providing preconfigured Docker images that work out of the box.

Assuming you already have Pint and Pest installed, follow these steps to set up Git hooks with Laravel Sail:

1. Create pre-commit

Create a Git hook file Navigate to your Laravel application's root directory and create a new file called pre-commit in the .git/hooks/ directory:

touch .git/hooks/pre-commit

2. Make it executeable

Make the Git hook file executable Make the pre-commit file executable by running the following command:

chmod +x .git/hooks/pre-commit

3. Write the script

Open the Git hook file and add the following code Open the pre-commit file in a text editor and add the following code:

#!/bin/sh
echo "Running Pint ..."
./vendor/bin/pint

echo "Running Pest ..."
[ -f sail ] && bash sail pest || bash vendor/bin/sail pest

This code runs Pint and Pest before a Git commit is executed. It first runs Pint and then runs Pest using Laravel Sail if the sail script exists; otherwise, it runs Pest using the local vendor/bin/sail script.

Thats it guys! Now test the Git hook Save the changes to the pre-commit file and make a change to your code. Attempt to commit your changes, and you should see output similar to the following:

Running Pint ...
[OK] No syntax error found
Running Pest ...
PASS Tests: 2, Assertions: 2, Passed: 2, Skipped: 0, Incomplete: 0, Risky: 0, Error: 0, Failed: 0

If you encounter any issues, check that Pint and Pest are installed and that the paths in the pre-commit file are correct.

In conclusion, setting up Git hooks for Pint and Pest with Laravel Sail is a straightforward process that can save you time by automatically running tests before committing code changes. By following these steps, you can ensure that your code adheres to the coding standards and that your tests pass before pushing code changes to your repository.

Other posts:

Laravel.rs Meetup #1: A New Era for the Serbian Laravel Community
Laravel
Laravel.rs Meetup #1: A New Era for the Serbian Laravel Community

On May 10th, 2025, Laravel.rs officially launched its first-ever meetup in Temerin, bringing together developers from across Serbia for a night of lightning talks, community networking, and a shared love for Laravel. With inspiring talks, open discussions, and future plans for workshops and hackathons, this kickoff event marked the beginning of a vibrant new chapter for Laravel in Serbia. 🚀🇷🇸

Vladimir NikolicVladimir Nikolic
May 15, 2025
Code, Stress, and Recovery: My Path to a Healthier Developer Life
Tips and Tricks
Code, Stress, and Recovery: My Path to a Healthier Developer Life

For years, I ignored the signs of burnout—long hours, constant stress, and the fear of failure. It caught up with me. I landed in the emergency room. This is my story of hitting rock bottom and rebuilding my health, mindset, and career.

Vladimir NikolicVladimir Nikolic
Feb 28, 2025
How to use git hooks to run scripts before the committing code to repo
LaravelTips and Tricks
How to use git hooks to run scripts before the committing code to repo

Make sure that all and everything you want to run before the pushing code to production, works as you expect. Simply use git hooks.

Vladimir NikolicVladimir Nikolic
Feb 15, 2024

Are you set to create something extraordinary?

Ready to take the next step? Let's work together to transform your ideas into reality. Contact us today to discuss how we can help you create impactful, user-centered solutions that drive success.

Contact Us