PHPUNITKIT is a plugin that provides PHPUnit support in Sublime Text. It provides an abstraction over running tests from the command-line. It works best alongside other PHP development plugins such as PHP Grammar, PHP Snippets, and PHP Completions.
- Zero configuration required; Does the Right Thing™
- Fully customized CLI options configuration
- Supports Composer
- Run test suite Ctrl+Shift+t
- Run test case Ctrl+Shift+r
- Run test method Ctrl+Shift+r (put cursor on test method)
- Run test methods Ctrl+Shift+r (use multiple cursor selection of test methods)
- Run test case for current class under test Ctrl+Shift+r
- Rerun last test Ctrl+Shift+e
- Test results in color (including failure diffs)
- Jump to next F4 / previous Shift+F4 failure (navigates to file, line, and column of failure)
- Switch, split, and focus test case / class under test Ctrl+Shift+.
- PHPUnit: Run All Tests Ctrl+Shift+t
- PHPUnit: Run Single Test Ctrl+Shift+r
- PHPUnit: Run Last Test Ctrl+Shift+e
- PHPUnit: Switch Test Case / Class Under Test Ctrl+Shift+.
- PHPUnit: Open HTML Code Coverage in Browser
- PHPUnit: Toggle Option --debug
- PHPUnit: Toggle Option --disallow-test-output
- PHPUnit: Toggle Option --disallow-todo-tests
- PHPUnit: Toggle Option --enforce-time-limit
- PHPUnit: Toggle Option --no-coverage
- PHPUnit: Toggle Option --report-useless-tests
- PHPUnit: Toggle Option --stop-on-error
- PHPUnit: Toggle Option --stop-on-failure
- PHPUnit: Toggle Option --stop-on-incomplete
- PHPUnit: Toggle Option --stop-on-risky
- PHPUnit: Toggle Option --stop-on-skipped
- PHPUnit: Toggle Option --strict-coverage
- PHPUnit: Toggle Option --strict-global-state
- PHPUnit: Toggle Option --tap
- PHPUnit: Toggle Option --testdox
- PHPUnit: Toggle Option --verbose
OS X | Windows / Linux | Description |
---|---|---|
Command+Shift+r | Ctrl+Shift+r | Run single test case or test(s) |
Command+Shift+t | Ctrl+Shift+t | Run test suite |
Command+Shift+e | Ctrl+Shift+e | Rerun last test(s) |
Command+Shift+. | Ctrl+Shift+. | Switch, split, and focus test case & class under test |
F4 | F4 | Jump to next failure |
Shift+F4 | Shift+F4 | Jump to previous failure |
Disabled by default.
OS X / Windows / Linux | Description |
---|---|
,r | Run single test case or test(s) |
,t | Run test suite |
,e | Rerun last test(s) |
,. | Switch, split, and focus test case & class under test |
phpunitkit goes to great lengths to predict how to invoke PHPUnit for the project environment.
For example, if PHPUnit is installed via Composer for the current project then the PHPUnit command-line test runner is invoked through vendor/bin/phpunit
, otherwise it is assumed PHPUnit is available on the system path and so is invoked via phpunit
.
Another example is, if phpunit.xml
or phpunit.xml.dist
(in that order) is found in the current or the nearest common ancestor directory of the active view file, that location is set as the current working directory when invoking PHPUnit and so that configuration file will be read by PHPunit. Placing PHPUnit configuration files at the root of a project is highly recommended.
If
phpunit.xml
orphpunit.xml.dist
(in that order) exist in the current working directory and--configuration
is not used, the configuration will be automatically read from that file. — PHPUnit Manual
PHPUnit's core functionality can be configured via its XML Configuration File or as Command-Line Options. Command-Line options can be specified via sublime text settings (User and Per-Project).
<?xml version="1.0" encoding="UTF-8"?>
<phpunit verbose="true"
stopOnFailure="true"
>
<php>
<ini name="display_errors" value="1" />
<ini name="xdebug.scream" value="0" />
</php>
<testsuites>
<testsuite name="unit">
<directory>test</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory>src</directory>
</whitelist>
</filter>
</phpunit>
Project > Edit Project
{
"settings": {
"phpunit.options": {
"v": true,
"stop-on-failure": true,
"no-coverage": true,
"d": [
"display_errors=1",
"xdebug.scream=0"
]
}
}
}
The above settings result in the following Command-Line Options being passed to PHPUnit.
--stop-on-failure -d "display_errors=1" -d "xdebug.scream=0" -v --no-coverage
Note: unlike User level settings, the "settings" key is not required.
Preferences > Settings - User
{
"phpunit.options": {
"v": true,
"stop-on-failure": true,
"no-coverage": true,
"d": [
"display_errors=1",
"xdebug.scream=0"
]
}
}
The above settings result in the following Command-Line Options being passed to PHPUnit.
--stop-on-failure -d "display_errors=1" -d "xdebug.scream=0" -v --no-coverage
Key | Description | Type | Default |
---|---|---|---|
phpunit.options |
Command-line options to pass to PHPUnit. See phpunit --help for an up-to-date list of command-line options. |
dict |
{} |
phpunit.keymaps |
Enable the default keymaps. | boolean |
true |
phpunit.keymaps.vi |
Enable the default vi keymaps (requires phpunit.keymaps to be enabled). |
boolean |
false |
phpunit.composer |
Enable Composer support. If a Composer installed PHPUnit is found then it is used to run tests. | boolean |
true |
phpunit.save_all_on_run |
Enable writing out every buffer (active window) with changes and a file name, on test runs. | boolean |
true |
Preferences > Settings - User
{
"phpunit.{Key}": "{Value}"
}
Project > Edit Project
{
"settings": {
"phpunit.{Key}": "{Value}"
}
}
Works best alongside PHP Grammar, PHP Completions, and PHP Snippets.
The preferred method of installation is Package Control.
- Close Sublime Text.
- Download or clone this repository to a directory named
phpunitkit
in the Sublime Text Packages directory for your platform:- Linux:
git clone https://github.com/gerardroche/sublime-phpunit.git ~/.config/sublime-text-3/Packages/phpunitkit
- OS X:
git clone https://github.com/gerardroche/sublime-phpunit.git ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/phpunitkit
- Windows:
git clone https://github.com/gerardroche/sublime-phpunit.git %APPDATA%\Sublime/ Text/ 3/Packages/phpunitkit
- Linux:
- Done!
Your issue reports and pull requests are welcome.
Debug messages are disabled by default. To enable them set an environment variable to a non-blank value e.g. SUBLIME_PHPUNIT_DEBUG=y
. To disable them set unset it or set it to a blank value e.g. SUBLIME_PHPUNIT_DEBUG=
.
For more information on environment variables read What are PATH and other environment variables, and how can I set or use them?
Sublime Text can be started at the Terminal with an exported environment variable.
$ export SUBLIME_PHPUNIT_DEBUG=y; subl
To set the environment permanently set it in ~/.profile
(requires restart).
export SUBLIME_PHPUNIT_DEBUG=y
Alternatively, create a debug script (subld) with debugging environment variables enabled.
Sublime Text can be started at the Command Prompt with an exported environment variable.
> set SUBLIME_PHPUNIT_DEBUG=y& "C:\Program Files\Sublime Text 3\subl.exe"
To set the environment permanently set it as a system environment variable (requires restart).
- Control Panel > System and Security > System > Advanced system settings
- Advanced > Environment Variables
- System variables > New...
- Add Variable name
SUBLIME_PHPUNIT_DEBUG
with Variable valuey
- Restart Windows
To be able to run the tests enable plugin development. This will make the command "PHPUnit: Run all Plugin Tests" available in the Command Palette.
Preferences > Settings - User
{
"phpunit.development": true
}
See CHANGELOG.md.
Based initially on maltize/sublime-text-2-ruby-tests and stuartherbert/sublime-phpunit.
Released under the BSD 3-Clause License.