Appearance
Running Tests in PHPStorm with Laravel Sail
This guide explains how to configure PHPStorm to run PHPUnit tests inside your Laravel Sail Docker container. This allows you to run tests directly from the IDE with a single click.
Prerequisites
- PHPStorm installed
- Laravel project with Sail configured
- Sail container running (
./vendor/bin/sail up -d)
Step 1: Add a CLI Interpreter
First, you need to configure PHPStorm to use the PHP interpreter from your Docker container.
- Open Settings (
Ctrl+Alt+S) - Navigate to PHP → CLI Interpreter
- Click the + button to add a new interpreter

Step 2: Select Docker Compose
In the interpreter selection dialog:
- Click From Docker, Vagrant, VM, WSL, Remote...

Step 3: Configure Docker Compose
- Select Docker Compose as the type
- Set Configuration files to
./compose.yaml(ordocker-compose.ymlfor older projects) - Select laravel.test as the service

Step 4: Confirm Configuration
Review the settings and click OK:
- Server: Docker
- Service: laravel.test
- PHP interpreter path: php

Step 5: Final Interpreter Settings
Make sure to select Connect to existing container under Lifecycle. This ensures PHPStorm uses your already running Sail container instead of starting a new one each time.

Step 6: Configure Test Framework (Optional)
If PHPStorm doesn't automatically detect PHPUnit:
- Go to Settings → PHP → Test Frameworks
- Add a new PHPUnit configuration
- Select your Docker interpreter
- Set the path to PHPUnit (usually
vendor/autoload.php)

Running Tests
Once configured, you can run tests directly from the editor:
- Click the green play button next to a test class or method
- Use
Ctrl+Shift+Rto 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
PHPStorm starts a new container instead of using existing one
Verify that Connect to existing container is selected in the CLI Interpreter settings (Step 5).
Cannot find PHPUnit
Ensure PHPUnit is installed in your project:
bash
./vendor/bin/sail composer require --dev phpunit/phpunit