PHPUnit Runner for VS Code
A comprehensive VS Code extension for running PHPUnit tests with integrated test discovery, execution, and result display.
Features
- Test Discovery: Automatically discovers PHPUnit tests in your workspace
- Test Explorer Integration: Tests appear in VS Code's built-in Test Explorer
- Individual Test Execution: Run specific test methods or entire test files
- Real-time Output: View PHPUnit output in real-time in the output panel
- Context Menu Integration: Right-click on PHP test files to run tests
- Configurable: Customize PHPUnit path, configuration file, and test directories
Requirements
- VS Code 1.102.0 or higher
- PHP installed and accessible from the command line
- PHPUnit installed in your project (recommended via Composer)
- Supported PHPUnit versions: 9.x, 10.x, 11.x (automatic version detection)
Installation
- Install the extension from the VS Code marketplace
- Open a workspace containing PHP tests
- Configure your PHPUnit settings if needed (see Configuration section)
Usage
Running Tests
Via Test Explorer:
- Open the Test Explorer panel (View → Test)
- Your tests will be automatically discovered and displayed
- Click the play button next to any test or test file to run it
Via Command Palette:
- Open Command Palette (
Ctrl+Shift+P
/ Cmd+Shift+P
)
- Run one of these commands:
PHPUnit: Run All Tests
PHPUnit: Refresh Tests
PHPUnit: Stop Tests
Via Context Menu:
- Right-click on a PHP test file in the editor or explorer
- Select "Run Test File"
Using Docker
To run tests inside a Docker container:
Enable Docker mode:
{
"aos-phpunit.docker.enabled": true
}
Using Docker Compose (recommended):
{
"aos-phpunit.docker.enabled": true,
"aos-phpunit.docker.useCompose": true,
"aos-phpunit.docker.serviceName": "app",
"aos-phpunit.docker.workingDirectory": "/var/www/html"
}
Using plain Docker:
{
"aos-phpunit.docker.enabled": true,
"aos-phpunit.docker.useCompose": false,
"aos-phpunit.docker.containerName": "my-php-container",
"aos-phpunit.docker.workingDirectory": "/var/www/html"
}
Note: Make sure your Docker container is running and has PHPUnit installed before running tests.
Configuration
Open VS Code settings and search for "PHPUnit" to configure the extension:
{
"aos-phpunit.phpunitPath": "vendor/bin/phpunit",
"aos-phpunit.configFile": "phpunit.xml",
"aos-phpunit.testSuffix": "Test.php",
"aos-phpunit.testDirectories": ["tests", "test"],
"aos-phpunit.showOutput": true,
"aos-phpunit.phpunitVersion": "",
"aos-phpunit.docker.enabled": false,
"aos-phpunit.docker.containerName": "",
"aos-phpunit.docker.serviceName": "app",
"aos-phpunit.docker.workingDirectory": "/var/www/html",
"aos-phpunit.docker.useCompose": true,
"aos-phpunit.docker.composeFile": "docker-compose.yml"
}
Configuration Options
Basic Settings
Setting |
Description |
Default |
aos-phpunit.phpunitPath |
Path to PHPUnit executable relative to workspace root |
vendor/bin/phpunit |
aos-phpunit.configFile |
Path to PHPUnit configuration file |
phpunit.xml |
aos-phpunit.testSuffix |
Test file suffix pattern |
Test.php |
aos-phpunit.testDirectories |
Directories to search for test files |
["tests", "test"] |
aos-phpunit.showOutput |
Show PHPUnit output in output panel |
true |
aos-phpunit.phpunitVersion |
Override PHPUnit version detection (e.g., '9.5', '10.0', '11.0') |
"" (auto-detect) |
Docker Settings
Setting |
Description |
Default |
aos-phpunit.docker.enabled |
Enable running PHPUnit tests in a Docker container |
false |
aos-phpunit.docker.containerName |
Name of the Docker container (used when not using docker-compose) |
"" |
aos-phpunit.docker.serviceName |
Docker Compose service name |
"app" |
aos-phpunit.docker.workingDirectory |
Working directory inside the Docker container |
"/var/www/html" |
aos-phpunit.docker.useCompose |
Use docker-compose instead of plain docker command |
true |
aos-phpunit.docker.composeFile |
Path to docker-compose file relative to workspace root |
"docker-compose.yml" |
Commands
Command |
Description |
aos-phpunit.runAllTests |
Run all discovered tests |
aos-phpunit.runTestFile |
Run tests in the current file |
aos-phpunit.refreshTests |
Refresh test discovery |
aos-phpunit.stopTests |
Stop running tests |
Release Notes
0.0.1
- Initial release
- Test discovery and execution
- Test Explorer integration
- Basic PHPUnit output parsing
- Configurable settings
Enjoy!
// https://marketplace.visualstudio.com/manage/publishers/AOSSoftware?auth_redirect=True