For more informations, see gerardroche's PHPUNITKIT I also used Adam Wathan's and David Hempill's work to run a single method, as seen here
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 method)
- Run test case for current class under test Ctrl+Shift+r
- Rerun last test(s) Ctrl+Shift+e
- Test results output in color (including color failure diffs)
- Jump to next F4 / previous failure Shift+F4 (navigates to file line number of failure)
- Switch, split, and focus test case & class under test Ctrl+Shift+.
- PHPUnit: Run All Tests Ctrl+Shift+t
- PHPUnit: Run Last Test Ctrl+Shift+e
- PHPUnit: Run Single Test Ctrl+Shift+r
- 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 |
| OS X / Windows / Linux | Description |
|---|---|
| ,ta | Run test suite |
| ,ts | Run single test case or test(s) |
| ,tl | Rerun last test(s) |
| ,ts | 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.xmlorphpunit.xml.dist(in that order) exist in the current working directory and--configurationis 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 |
true |
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.
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.
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.