Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
* develop:
  Add PowerShell strategy
  Update README
  Add cmd strategy #92
  Update README
  Add Toggle Run Test On Save command palette
  Refactor: cs
  • Loading branch information
gerardroche committed Aug 6, 2023
2 parents a46ddf9 + 9cbda67 commit 7d54036
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 39 deletions.
12 changes: 9 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,22 @@

All notable changes are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles.

## 3.18.0 - Unreleased

* [#126](https://github.com/NeoVintageous/NeoVintageous/issues/126): New "powershell" strategy to run tests in the PowerShell command-line shell (Windows)
* [#92](https://github.com/NeoVintageous/NeoVintageous/issues/92): New "cmd" strategy to run tests in the cmd.exe command-line (Windows)
* [#125](https://github.com/NeoVintageous/NeoVintageous/issues/125): New "Toggle Run Test On Save" command palette

## 3.17.1 - 2023-08-04

[#92](https://github.com/NeoVintageous/NeoVintageous/issues/92): Allow "external" strategy for custom strategies using `prepend_cmd`
* [#92](https://github.com/NeoVintageous/NeoVintageous/issues/92): Allow "external" strategy for custom strategies using `prepend_cmd`

## 3.17.0 - 2023-08-04

### Added

[#121](https://github.com/NeoVintageous/NeoVintageous/issues/121): Run tests from the side bar menu
[#122](https://github.com/NeoVintageous/NeoVintageous/issues/122): Run tests from the context menu
* [#121](https://github.com/NeoVintageous/NeoVintageous/issues/121): Run tests from the side bar menu
* [#122](https://github.com/NeoVintageous/NeoVintageous/issues/122): Run tests from the context menu

### Removed

Expand Down
2 changes: 2 additions & 0 deletions Default.sublime-commands
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
{ "caption": "PHPUnit: Test Switch", "command": "phpunit_test_switch" },
{ "caption": "PHPUnit: Test Visit", "command": "phpunit_test_visit" },

{ "caption": "PHPUnit: Toggle Run Test On Save", "command": "phpunit_toggle", "args": { "action": "test_file_on_post_save" } },

{ "caption": "PHPUnit: Toggle --cache-result", "command": "phpunit_toggle_option", "args": { "option": "cache-result" } },
{ "caption": "PHPUnit: Toggle --debug", "command": "phpunit_toggle_option", "args": { "option": "debug" } },
{ "caption": "PHPUnit: Toggle --disable-coverage-ignore", "command": "phpunit_toggle_option", "args": { "option": "disable-coverage-ignore" } },
Expand Down
64 changes: 34 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ PHPUnit support for [Sublime Text](https://sublimetext.com).
* Fast jump to next and previous failure
* Fast switch between test and file-under-test
* Toggle options from the command palette
* Toggle run test on save :new:
* Fully customized CLI options configuration
* Support for
- [Artisan] - Artisan is the command line interface included with Laravel.
Expand All @@ -36,7 +37,9 @@ PHPUnit support for [Sublime Text](https://sublimetext.com).
- [Kitty] - Kitt is a fast, feature-rich, cross-platform, GPU based terminal.
- [ParaTest] - ParaTest adds parallel testing support in PHPUnit.
- [Pest] - Pest is a testing framework with a focus on simplicity.
- [xterm] - A terminal emulator for the X Window System.
- [xterm] - A terminal emulator for the X Window System. :new:
- [cmd] - A command-line interpreter for Windows. :new:
- [PowerShell] - A cross-platform command-line shell. :new:
- Zero configuration required

Read [Running PHPUnit Tests from Sublime Text](https://blog.gerardroche.com/2023/05/05/running-phpunit-tests-within-sublime-text/) for a quick introduction.
Expand Down Expand Up @@ -95,19 +98,20 @@ Menu → Preferences → Key Bindings

## Commands

| Command | Description
| :-------------------------------------------- | :----------
| **PHPUnit: Test Nearest** | Run a test nearest to the cursor. If the current file is not a test file, it runs the tests for current file.
| **PHPUnit: Test File** | Run tests for the current file.
| **PHPUnit: Test Suite** | Run test suite of the current file.
| **PHPUnit: Test Last** | Runs the last test.
| **PHPUnit: Test Switch** | In a test file opens the file under test, otherwise opens the test file.
| **PHPUnit: Test Visit** | Open the last run test.
| **PHPUnit: Test Results** | Opens the test output panel (only applies to "basic" strategy).
| **PHPUnit: Test Cancel** | Cancel any currently running tests.
| **PHPUnit: Test Coverage** | Opens the code coverage in a browser.
| **PHPUnit: Toggle...** | Toggle options e.g. PHPUnit CLI options.
| **Preferences: PHPUnit Settings** | Edit settings.
| Command | Description
| :-------------------------------------------------------------| :----------
| **PHPUnit: Test Nearest** | Run a test nearest to the cursor. If the current file is not a test file, it runs the tests for current file.
| **PHPUnit: Test File** | Run tests for the current file.
| **PHPUnit: Test Suite** | Run test suite of the current file.
| **PHPUnit: Test Last** | Runs the last test.
| **PHPUnit: Test Switch** | In a test file opens the file under test, otherwise opens the test file.
| **PHPUnit: Test Visit** | Open the last run test.
| **PHPUnit: Test Results** | Opens the test output panel (only applies to "basic" strategy).
| **PHPUnit: Test Cancel** | Cancel any currently running tests.
| **PHPUnit: Test Coverage** | Opens the code coverage in a browser.
| **PHPUnit: Toggle Run Test On Save** | Toggle to quickly turn the Test File auto-command on and off.
| **PHPUnit: Toggle...** | Toggle options e.g. PHPUnit CLI options.
| **Preferences: PHPUnit Settings** | Edit settings.

## Key Bindings

Expand Down Expand Up @@ -135,7 +139,9 @@ Command Palette → Preferences: PHPUnit Settings
| **Basic** (default) | `basic` | Sends test commands to Sublime Text exec output panel.
| **iTerm2.app** | `iterm` | Sends test commands to `iTerm2 >= 2.9` (useful in MacVim GUI).
| **[Kitty]** | `kitty` | Sends test commands to Kitty terminal.
| **[xterm]** | `xterm` | Sends test commands to xterm terminal.
| **[xterm]** | `xterm` | Sends test commands to xterm terminal. :new:
| **[cmd]** | `cmd` | Sends test commands to cmd.exe terminal. :new:
| **[PowerShell]** | `powershell` | Sends test commands to PowerShell command shell. :new:

## Configuring

Expand Down Expand Up @@ -467,23 +473,19 @@ Menu → Preferences → Key Bindings

[NeoVintageous](https://github.com/NeoVintageous/NeoVintageous) is a Vim emulator for Sublime Text.

Add your preferred mappings to your `.neovintageousrc` file.
1. Open the Command Palette: `Command Palette → NeoVintageous: Open neovintageous file`.
2. Add your preferred mappings.

**Example**

Command Palette → NeoVintageous: Open .neovinageousrc

```vim
nnoremap <leader>t :TestNearest<CR>
nnoremap <leader>T :TestFile<CR>
nnoremap <leader>a :TestSuite<CR>
nnoremap <leader>l :TestLast<CR>
nnoremap <leader>g :TestVisit<CR>
```

Don't forget to reload your .neovintageousrc file.
**Example**

Command Palette → NeoVintageous: Reload .neovinageousrc
```vim
nnoremap <leader>t :TestNearest<CR>
nnoremap <leader>T :TestFile<CR>
nnoremap <leader>a :TestSuite<CR>
nnoremap <leader>l :TestLast<CR>
nnoremap <leader>g :TestVisit<CR>
```
3. To apply the changes, reload the neovintageousrc from the Command Palette: `Command Palette → NeoVintageous: Reload neovintageous file`.

## Contributing

Expand All @@ -506,5 +508,7 @@ Released under the [GPL-3.0-or-later License](LICENSE).
[Kitty]: https://github.com/kovidgoyal/kitty
[ParaTest]: https://github.com/paratestphp/paratest
[Pest]: https://pestphp.com
[PowerShell]: https://learn.microsoft.com/en-us/powershell/
[cmd]: https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/cmd
[iTerm2]: https://iterm2.com
[xterm]: https://invisible-island.net/xterm/
18 changes: 13 additions & 5 deletions lib/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,12 @@ def run(self, working_dir=None, file=None, options=None) -> None:
cmd += ['kitty', '--hold']
elif get_setting(self.view, 'strategy') == 'iterm':
cmd.append(get_osx_term_script_path())
elif get_setting(self.view, 'strategy') == 'powershell':
cmd += ['powershell', '-Command']
elif get_setting(self.view, 'strategy') == 'xterm':
cmd += ['xterm', '-hold', '-e']
elif get_setting(self.view, 'strategy') == 'cmd':
cmd += ['cmd.exe', '/c']

if get_setting(self.view, 'ssh'):
cmd += ['ssh']
Expand Down Expand Up @@ -145,7 +149,8 @@ def run(self, working_dir=None, file=None, options=None) -> None:
def run_last(self) -> None:
last_test_args = get_last_run()
if not last_test_args:
return status_message('PHPUnit: no tests were run so far')
status_message('PHPUnit: no tests were run so far')
return

self.run(**last_test_args)

Expand All @@ -172,7 +177,8 @@ def run_file(self, file=None, options=None) -> None:
def run_nearest(self, options) -> None:
file = self.view.file_name()
if not file:
return status_message('PHPUnit: not a test file')
status_message('PHPUnit: not a test file')
return

if has_test(self.view):
if 'filter' not in options:
Expand All @@ -197,11 +203,13 @@ def cancel(self) -> None:
def coverage(self) -> None:
working_dir = find_phpunit_working_directory(self.view.file_name(), self.window.folders())
if not working_dir:
return status_message('PHPUnit: could not find a PHPUnit working directory')
status_message('PHPUnit: could not find a PHPUnit working directory')
return

coverage_html_index_html_file = os.path.join(working_dir, 'build/coverage/index.html')
if not os.path.exists(coverage_html_index_html_file):
return status_message('PHPUnit: could not find PHPUnit HTML code coverage %s' % coverage_html_index_html_file) # noqa: E501
status_message('PHPUnit: could not find PHPUnit HTML code coverage %s' % coverage_html_index_html_file) # noqa: E501
return

webbrowser.open_new_tab('file://' + coverage_html_index_html_file)

Expand All @@ -221,7 +229,7 @@ def visit(self) -> None:
if os.path.isfile(file):
return self.window.open_file(file)

return status_message('PHPUnit: no tests were run so far')
status_message('PHPUnit: no tests were run so far')

def toggle(self, option: str, value=None) -> None:
options = get_phpunit_options(self.view)
Expand Down
2 changes: 1 addition & 1 deletion lib/strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@


def execute(window, view, env: dict, cmd: list, working_dir: str) -> None:
if get_setting(view, 'strategy') in ('external', 'iterm', 'kitty', 'xterm'):
if get_setting(view, 'strategy') in ('cmd', 'external', 'iterm', 'kitty', 'powershell', 'xterm'):
window.run_command('exec', {
'env': env,
'cmd': cmd,
Expand Down
18 changes: 18 additions & 0 deletions lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,3 +726,21 @@ def replace_param(param):
return param

return [replace_param(param) for param in command_params]


def toggle_on_post_save(view, item: str) -> None:
on_post_save = view.settings().get('phpunit.on_post_save')
if not isinstance(on_post_save, list):
on_post_save = []

try:
on_post_save.remove(item)
except ValueError:
on_post_save.append(item)

# If the new value is the same as the user's default then erase the
# value from the current and let it fallback to the default. This
# helps prevent confusion when the user modifies their default.
view.settings().erase('phpunit.on_post_save')
if on_post_save != view.settings().get('phpunit.on_post_save'):
view.settings().set('phpunit.on_post_save', on_post_save)
12 changes: 12 additions & 0 deletions plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from PHPUnitKit.lib.events import Listener
from PHPUnitKit.lib.runner import PHPUnit
from PHPUnitKit.lib.utils import toggle_on_post_save


class PhpunitTestSuiteCommand(sublime_plugin.WindowCommand):
Expand Down Expand Up @@ -87,6 +88,17 @@ def on_post_save(self, view):
Listener().on_post_save(view)


class PhpunitToggleCommand(sublime_plugin.WindowCommand):

def run(self, action):
view = self.window.active_view()
if not view:
return

if action == 'test_file_on_post_save':
toggle_on_post_save(view, 'phpunit_test_file')


class PhpunitSideBarTestFileCommand(sublime_plugin.WindowCommand):

def run(self, files):
Expand Down

0 comments on commit 7d54036

Please sign in to comment.