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).
phpunit.xml
configuration file)To run tests with debugging:
To run test coverage, either:
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 class with tag | phpunit-test-workbench.runClassWithTag |
If the active editor is for a test class, execute all test methods within the class tagged with the selected group. |
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 test suite with tag | phpunit-test-workbench.runSuiteWithTag |
Display a dialog allowing the user to select from the list of test suites found in configuration files. All test methods tagged with the selected group within the test suite will be executed. |
PHPUnit: Run all tests | phpunit-test-workbench.runAll |
Run all tests identified in the Test Explorer. |
PHPUnit: Run all tests with tag | phpunit-test-workbench.runAll |
Run all tests identified in the Test Explorer tagged with the selected group. |
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 class with tag | phpunit-test-workbench.debugClassWithTag |
If the active editor is for a test class, debug all test methods within the class tagged with the selected group. |
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 test suite will be executed using the debugger. |
PHPUnit: Debug test suite with tag | phpunit-test-workbench.debugSuiteWithTag |
Display a dialog allowing the user to select from the list of test suites found in configuration files. All test methods tagged with the selected group within the suite will be executed using the debugger. |
PHPUnit: Debug all tests | phpunit-test-workbench.debugAll |
Debug all tests identified in the Test Explorer. |
PHPUnit: Debug all tests with tag | phpunit-test-workbench.debugAllWithTag |
Debug all tests identified in the Test Explorer tagged with the selected group. |
PHPUnit: Re-execute last test run | phpunit-test-workbench.rerunLastTestRun |
Re-run the most recent test run. This could be a regular run, a debug run, or a run including test coverage. |
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.coverageDriver |
Code coverage driver that PHPUnit will use to generate code coverage statistics. Either PCOV or Xdebug must be selected to enable code coverage functionality. |
phpunit.coverageSourceDirectory |
Path to the folder containing source code that should be included in code coverage statistics. If left emtpy, PHPUnit Test Workbench will attempt to use ./src , ./lib or ./app in that order. If none of these directories are found, the workspace root will be used (however, this is not recommended as it will include test files and vendor packages). |
phpunit.coverageOutputDirectory |
Path to the location where a generated code coverage file should be stored. If left empty, PHPUnit Test Workbench will attempt to save it to the system temporary directory. |
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 . |
@tests
docblock annotation (#21)xml2js
library was not referenced properly