Skip to content

geminilabs/sublime-phpunit

 
 

Repository files navigation

WHAT PHPUNITKIT IS

Author Source Code License GitHub stars Sublime version Latest version Downloads

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.

Screenshot

OVERVIEW

FEATURES

  • 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+.

COMMANDS

  • 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

KEY BINDINGS

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

Vintage / Vintageous

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

CONFIGURATION

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 or phpunit.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

Command-Line Options

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).

Example — phpunit.xml or phpunit.xml.distConfiguration

<?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>

Example — Per-Project PHPUnit Command-Line Options

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

Example — User PHPUnit Command-Line Options

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

Settings

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

User Settings

Preferences > Settings - User

{
    "phpunit.{Key}": "{Value}"
}

Per-Project Settings

Project > Edit Project

{
    "settings": {
        "phpunit.{Key}": "{Value}"
    }
}

INSTALLATION

Works best alongside PHP Grammar, PHP Completions, and PHP Snippets.

Package Control installation

The preferred method of installation is Package Control.

Manual installation

  1. Close Sublime Text.
  2. 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
  3. Done!

CONTRIBUTING

Your issue reports and pull requests are welcome.

Debug messages

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?

Example — Linux

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.

Example — Windows

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).

  1. Control Panel > System and Security > System > Advanced system settings
  2. Advanced > Environment Variables
  3. System variables > New...
  4. Add Variable name SUBLIME_PHPUNIT_DEBUG with Variable value y
  5. Restart Windows

Running tests

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
}

CHANGELOG

See CHANGELOG.md.

CREDITS

Based initially on maltize/sublime-text-2-ruby-tests and stuartherbert/sublime-phpunit.

LICENSE

Released under the BSD 3-Clause License.

About

PHPUnit support for Sublime Text

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%