ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

PHPUnit​Kit

by gerardroche ST3

PHPUnit support for Sublime Text; provides an abstraction over running tests from the command-line; run your tests from within Sublime Text, requires zero configuration, supports composer, running tests on different granularities, testing different php versions, color test results panel, and more.

Labels php, phpunit, testing, tdd

Details

Installs

  • Total 4K
  • Win 3K
  • OS X 922
  • Linux 946
May 27 May 26 May 25 May 24 May 23 May 22 May 21 May 20 May 19 May 18 May 17 May 16 May 15 May 14 May 13 May 12 May 11 May 10 May 9 May 8 May 7 May 6 May 5 May 4 May 3 May 2 May 1 Apr 30 Apr 29 Apr 28 Apr 27 Apr 26 Apr 25 Apr 24 Apr 23 Apr 22 Apr 21 Apr 20 Apr 19 Apr 18 Apr 17 Apr 16 Apr 15 Apr 14 Apr 13 Apr 12
Windows 1 0 1 1 2 2 2 1 1 1 5 3 1 0 2 1 1 6 3 2 3 0 1 2 2 1 4 6 2 1 1 1 6 2 1 2 0 0 8 2 2 0 3 1 3 5
OS X 0 0 0 1 1 1 1 0 1 0 0 1 2 0 1 0 1 1 1 0 2 0 1 1 0 0 2 1 2 1 0 1 0 0 0 0 0 1 0 0 2 0 0 0 0 1
Linux 1 0 0 0 1 0 0 1 1 1 1 1 1 0 0 0 0 1 1 2 0 0 0 0 2 2 0 1 2 1 0 1 1 0 1 0 1 2 2 1 1 0 0 0 0 1

Readme

Source
raw.​githubusercontent.​com

PHPUnitKit

A Sublime Text wrapper for running tests on different granularities.

Build Status Build status Coverage Status Minimum Sublime Version Latest Stable Version GitHub stars Downloads

Screenshot

Features

  • Run Test File
  • Run Last Test
  • Run Test Suite
  • Run Nearest Test
  • Fully customisable configuration
  • Supports Composer installed PHPUnit
  • Supports colour results, diffs, errors, etc.
  • Jump to next and jump to previous failure
  • Supports the unify “Test” key bindings plugin

Installation

Package Control installation

The preferred method of installation is Package Control.

Manual installation

Close Sublime Text, then 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
  • OSX: 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

Commands

These commands are available through the Command Palette. To use the command palette. To use the command palette:

  1. Press Ctrl+Shift+P
  2. Select a command
  3. Press Enter
command description
TestSuite Runs the whole test suite (if the current file is a test file, runs that framework's test suite).
TestFile In a test file runs all tests in the current file, otherwise runs that file's tests.
TestNearest In a test file runs the test nearest to the cursor, otherwise runs that file's tests.
TestLast Runs the last test.
TestVisit Visits the test file from which you last run your tests (useful when you're trying to make a test pass, and you dive deep into application code and close your test buffer to make more space, and once you've made it pass you want to go back to the test file to write more tests).
TestSwitch In a test file opens the file under test, otherwise opens the test file.
TestResults Opens the test results panel.
TestCancel Cancels the test runner.
TestCoverage Opens the code coverage report in default browser.
ToggleOption Toggles PHPUnit options.

Key Bindings

Add your preferred key bindings via Menu > Preferences > Key Bindings or use the command palette:

  1. Press Ctrl+Shift+P
  2. Select the “Preferences: Key Bindings” command
  3. Press Enter
[
    { "keys": ["ctrl+shift+a"], "command": "phpunit_test_suite" },
    { "keys": ["ctrl+shift+c"], "command": "phpunit_test_cancel" },
    { "keys": ["ctrl+shift+f"], "command": "phpunit_test_file" },
    { "keys": ["ctrl+shift+l"], "command": "phpunit_test_last" },
    { "keys": ["ctrl+shift+n"], "command": "phpunit_test_nearest" },
    { "keys": ["ctrl+shift+r"], "command": "phpunit_test_results" }
    { "keys": ["ctrl+shift+s"], "command": "phpunit_test_switch" },
    { "keys": ["ctrl+shift+v"], "command": "phpunit_test_visit" }
]
key description
F4 Jump to Next Failure
Shift+F4 Jump to Previous Failure

Strategies

You can run tests using different execution environments called “strategies”. To use a specific strategy, assign it to a setting:

// make test commands execute using iTerm2
"phpunit.strategy": "iterm"
Strategy Identifier Description
Panel (default) default Runs test commands in a panel at the bottom of your editor window.
iTerm2.app iterm Sends test commands to iTerm2 >= 2.9 (useful in MacVim GUI).

Configuration

Configure settings via Menu > Preferences > Settings or by the Command Palette. To use the command palette:

  1. Press Ctrl+Shift+P
  2. Select the “Preferences: Settings” command
  3. Press Enter
key description type default
phpunit.options Default CLI options. dict {}
phpunit.composer Use Composer installed PHPUnit. boolean true
phpunit.save_all_on_run Save dirty buffers before test run. boolean true
phpunit.php_executable Custom PHP executable. string System PATH
phpunit.php_versions_path Location of phpenv versions. string ~/.phpenv/versions

phpunit.composer

When enabled, the test runner will checks if there is a Composer installed PHPUnit available, otherwise the system PATH will be used to find PHPUnit. When disabled, the Composer check is skipped. Composer support is enabled by default, but you can disabled it.

"phpunit.composer": false

phpunit.options

If you want some CLI options to stick around, you can configure them in your global preferences:

// The following options translates to:
//
//   --colors=never
//   --coverage-html build/coverage
//   -d "display_errors=1"
//   -d "xdebug.scream=0"
//   --no-coverage

"phpunit.options": {
    "colors=never": true,
    "coverage-html": "build/coverage",
    "d": ["display_errors=1", "xdebug.scream=0"],
    "no-coverage": true
}

phpunit.php_executable

You can instruct the test runner to use a custom PHP executable.

"phpunit.php_executable": "~/.phpenv/versions/7.3.1/bin/php"

phpunit.save_all_on_run

Write out every buffer that has changes before running tests.

"phpunit.save_all_on_run": false

Runner commands

Aside from the main commands, you can configure your own custom test runners (which also accept options):

// Key Binding to run two specific test suites
{"keys": ["ctrl+shift+a"], "command": "test_suite", "args": {"testsuite": "fizz,buzz"}},

// Key Binding to run test suite with code coverage
{"keys": ["ctrl+shift+c"], "command": "test_suite", "args": {"coverage-html": "build/coverage"}},

The following commands accept CLI options:

  • phpunit_test_suite
  • phpunit_test_file
  • phpunit_test_nearest

Contributing

See CONTRIBUTING.md.

Changelog

See CHANGELOG.md.

Credits

Based initially on, and inspired by, maltize/sublime-text-2-ruby-tests, stuartherbert/sublime-phpunit, and janko-m/vim-test.

License

Released under the BSD 3-Clause License.