How to Set Up Pest Plugin in PHPStorm for Sail

Follow this step-by-step guide to install and configure Pest plugin for PEST/PHPUnit tests in PHPStorm. You'll learn how to create a new Run/Debug Configuration of type Pest and select your project's docker-compose.yml file in the "Configuration files" option. Ensure your settings are as per the below screenshot and that you have the correct version of PHP Executable. With these simple instructions, you'll be able to run Pest tests in PHPStorm with ease.

Are you looking to use Pest, a testing framework for PHP, in PHPStorm? Look no further than this guide to installing and configuring the Pest plugin for PEST/PHPUnit tests in PHPStorm.

Install PEST Plugin in PHPStorm

Firstly, install PEST plugin in PHPStorm.

Add CLI Interpreter

Go to Settings > PHP > Cli Interpreter. Click the three dots menu and select "From Docker, Vagrant, VM, WSL, Remote..." option. Next, select the "Docker Compose" radio button and choose your project's docker-compose.yml file in the "Configuration files" option. From the service, select your Laravel app service (for example, "laravel.test" for the default Laravel installation). Press "OK."

You will now see a new option added in CLI Interpreters, in this case, "laravel.test." Ensure that all the settings are as below. In Lifecycle, select "Connect to existing container" option, and in Service, select "laravel.test" if not already selected or any other service related to your project.

Make sure that under "general > PHP Executable," you have "php" and the version shows the same version that you have in Docker Sail.

Add PEST Remote Interpreter

Next, search for "pest" from the Settings menu and look for the option PHP > Test Frameworks. Click the "+" icon and select "Pest by Remote Interpreter." From the dialogue, select the interpreter you just created (in this case, "laravel.test"). Check that a new entry has been created with settings as per the below screenshot.

Match "Path Mappings," and other settings. Do not change /var/www/html that's the path inside sail container.

Add test configuration

To Add test configuration click "Add Configuration" below the menu bar on the right side, as per the screenshot below. Click "Add new" and select "Pest" from the menu. One item will be created under "Pest," and you should check that all the settings are as per the below screenshot. The "Directory" should point to your project's "tests" directory.

Finally, "Use alternative configuration file" is optional, and you should select "interpreter" as we just created above (in this case, "laravel.test"). With these simple steps, you'll be able to set up Pest plugin for PHPUnit tests in PHPStorm using Docker Compose.

Did you find this article valuable?

Support Ghanshyam Digital by becoming a sponsor. Any amount is appreciated!