Skip to content
On this page

Running Pest Tests in PHPStorm with Laravel Sail

This guide explains how to configure PHPStorm to run Pest tests inside your Laravel Sail Docker container. Pest is a modern PHP testing framework with an elegant syntax built on top of PHPUnit.

Prerequisites

  • PHPStorm installed
  • Laravel project with Sail configured
  • Sail container running (./vendor/bin/sail up -d)
  • Pest installed in your project
  • CLI Interpreter already configured (see Running Tests with Sail)

Step 1: Install the Pest Plugin

First, install the Pest plugin in PHPStorm to get proper syntax highlighting and test runner support.

  1. Open Settings (Ctrl+Alt+S)
  2. Navigate to Plugins
  3. Search for Pest
  4. Install the official Pest plugin by JetBrains

Install Pest Plugin

Step 2: Configure CLI Interpreter

Make sure your CLI Interpreter is configured to connect to the existing Sail container. This is essential for running tests inside Docker.

  1. Open Settings → PHP → CLI Interpreter
  2. Select your laravel.test interpreter
  3. Under Lifecycle, ensure Connect to existing container is selected

TIP

Make sure Sail is running in the background before running tests.

CLI Interpreter Config

Step 3: Add Pest Test Framework

  1. Go to Settings → PHP → Test Frameworks
  2. Click + to add a new test framework
  3. Select Pest (with the Remote interpreter)

Add Test Framework

Step 4: Configure Pest Path

Set the path to the Pest executable inside the Docker container:

  1. In the Pest library section, set Path to Pest executable:
    /var/www/html/vendor/bin/pest
    

Pest Path Configuration

Step 5: Configure Path Mappings

Ensure the path mappings are correctly configured so PHPStorm knows how to map your local files to the container.

  1. Click on the folder icon next to Path mappings
  2. Add a mapping:
    • Local Path: Your project root (e.g., /home/user/projects/my-app)
    • Remote Path: /var/www/html

Path Mappings

Running Tests

Once configured, you can run Pest tests directly from the editor:

  • Click the green play button next to a test function or describe block
  • Use Ctrl+Shift+R to run the test at cursor
  • Right-click on a test file and select Run

Troubleshooting

Tests fail with "Connection refused"

Make sure your Sail container is running:

bash
./vendor/bin/sail up -d

Pest executable not found

Verify Pest is installed in your project:

bash
./vendor/bin/sail composer require --dev pestphp/pest

Path mappings issues

Double-check that your local project path maps to /var/www/html in the container.