An extension to integrate PHPUnit with the native Test Explorer functionality within VS Code. Zero configuration required for common environment setups (i.e. where php
is in your environment path, and PHPUnit is installed via Composer or included as a PHAR library).
- Integrates with standard VS Code Test Explorer
- Organise and run your tests:
- By namespace
- By test suite (as defined in your
phpunit.xml
configuration file) - Simple list of files and methods
- Errors appear as a peek within the editor
- History of test run results and execution times is maintained
- Includes commands and hotkeys to allow quick running of test or test suites
- Debug test scripts using your existing debug profiles
- PHP: Version 7+
- PHPUnit: Version 9 & 10
- XDebug: Version 3
PHP binary and PHPUnit must be installed on the environment where the tests are being run.
If you are running in a Docker container, WSL or any other remote/virtual environment, this extension will work in conjunction with the Remote Development extension by Microsoft.
Command | ID | Description |
---|---|---|
PHPUnit: Run test method | phpunit-test-workbench.runMethod |
If the cursor is located within a test method, execute only that test method. |
PHPUnit: Run test class | phpunit-test-workbench.runClass |
If the active editor is for a test class, execute all test methods within the class. |
PHPUnit: Run test suite | phpunit-test-workbench.runSuite |
Display a dialog allowing the user to select from the list of test suites found in configuration files. All test methods within the class will be executed. |
PHPUnit: Run all tests | phpunit-test-workbench.runAll |
Run all tests identified in the Test Explorer |
PHPUnit: Debug test method | phpunit-test-workbench.debugMethod |
If the cursor is located within a test method, execute only that test method using the debugger. |
PHPUnit: Debug test class | phpunit-test-workbench.debugClass |
If the active editor is for a test class, debug all test methods within the class. |
PHPUnit: Debug test suite | phpunit-test-workbench.debugSuite |
Display a dialog allowing the user to select from the list of test suites found in configuration files. All test methods within the class will be executed using the debugger. |
PHPUnit: Debug all tests | phpunit-test-workbench.debugAll |
Debug all tests identified in the Test Explorer |
Option | Description |
---|---|
log.level |
Control the level of information displayed in the output panel. |
log.autoDisplayOutput |
Control when to automatically display the Output panel showing log messages. Regardless of this setting, log output can always be viewed by opening the relevant Output panel manually. |
log.displayFailuresAsErrorsInCode |
If enabled, the failed assertion will be highlighted as an error in source code. |
php.binaryPath |
Path to the location of the PHP binary. If left blank, it will be assumed that php is available via the environment $PATH variable. |
phpunit.locatorPatternComposerJson |
The glob describing the location of your composer file (usually named composer.json ). If left blank, PHPUnit Test Workbench will attempt to find a composer.json file in the root workspace folder. The default pattern is composer.json . |
phpunit.binaryPath |
Path to the location of the PHPUnit binary (either phpunit or phpunit.phar ). If left blank, the following locations will be checked: vendor directoryphpunit.phar in the root of the current workspace directoryphpunit.phar is available via the environment $PATH variable. |
phpunit.locatorPatternConfigXml |
The glob describing the location of your configuration file (usually named phpunit.xml ). The default pattern is phpunit.xml . |
phpunit.testDirectory |
Relative path from the workspace folder root to the directory where tests should be executed from (usually the tests folder). |
phpunit.testFileSuffix |
Suffix used to identify test files within the test directory. If left blank, PHPUnit default suffixes (Test.php and .phpt ) will be used. |
phpunit.testNamespacePrefix |
If using PSR-4 namespaces, use this setting to map your test namespace prefix to the test directory (as defined in the phpunit-test-workbench.phpunit.testDirectory setting). Default is blank - this assumes that either: composer.json file maps the namespaces for your test classes (recommended); or |
phpunit.testOrganization |
Method used to organise and display tests in the Test Explorer: |
phpunit.useTestSuiteDefinitions |
Use test suite definitions within your configuration file to locate and group tests in the Test Explorer. Note that using this option requires a valid PHPUnit configuration file to be found via the phpunit.locatorPatternConfigXml glob pattern. Test suite definitions in the configuration file will ignore the phpunit.testDirectory setting. |
xdebug.clientPort |
Default port to use for Xdebug connections, if a port is not defined in your selected debug launch configuration. Default is 9003 . |
xdebug.clientHost |
Default hostname to use for Xdebug connections, if a host is not defined in your selected debug launch configuration. Default is localhost . |
- FIXED: Namespace folder locations not being correctly identified on Remote Workspaces - for real this time (#58)
- FIXED: Namespace folder locations not being correctly identified on Remote Workspaces (#58)
- NEW: Add support for PHPUnit 10 (#49)
- NEW: Add detection for namespaces mapped in composer.json (#50)
- CHANGED: Refactor test file parsing to find additional test script edge cases (#54)
- FIXED: Not all test results captured when executing against large test suites (#51)
- FIXED: Editing an existing test script does not not update location of shifted class and function 'run' icons (#47)
- FIXED: Missing commands for debugging tests (#45)
- FIXED: New test added to Test Explorer on each keystroke instead of on file save (#42)
- FIXED: All test files being reparsed whenever any single test file is saved (#43)
- FIXED: Some test failures not correctly detected by results parser (#40)
- NEW: Include pertinent information in recorded test run output (#34)
- NEW: Add test debug run profile (#36)
- NEW: Include summary of test run in output (#38)
- NEW: Detect tests identified with the
@tests
docblock annotation (#21) - NEW: Setting to control when Output panel is displayed on test execution (#25)
- NEW: Highlight lines within test methods where test failures occur (#26)
- NEW: Wire up Test Explorer cancel button to actually cancel test run (#27)
- FIXED: Test run icons offset by 1 line from class and method identifiers (#23)
- FIXED: Output from Git editors being parsed for test cases (#31)
- FIXED: Clicking the 'Run test' icon in a test class sometimes refreshes the Test Explorer instead of running the test (#19)
- FIXED: Clicking 'Go to test' on a namespace in Test Explorer displays an error (#17)
- FIXED: Build error where
xml2js
library was not referenced properly
- FIXED: Commands not executing tests for specific classes or methods (#12)
- Updated documentation to include example images
- Initial release