Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,20 @@ If you use [fish shell](https://fishshell.com/), specify this in your settings:
```

This will instruct Sublime PHPUnit to connect the commands using fish's `; and` instead of bash's `&&`.

## Running tests over ssh (for VMs like Laravel Homestead)

```json
{
"phpunit-sublime-ssh": true,
"phpunit-sublime-ssh-host": "host",
"phpunit-sublime-ssh-user": "user",
"phpunit-sublime-ssh-port": 22,
"phpunit-sublime-ssh-paths": {
"/your/local/path": "/your/remote/path"
},
"phpunit-sublime-ssh-command-suffix": "--configuration /your/specific/path/to/phpunit.xml",
"phpunit-sublime-ssh-command-prefix": "TERM=xterm-256color"
}
```
Default ssh port is 22, so setting phpunit-sublime-ssh-port is optional. Also phpunit-sublime-ssh-command-suffix and phpunit-sublime-ssh-command-prefix are of course optional.
39 changes: 39 additions & 0 deletions sublime-phpunit.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
class PhpunitTestCommand(sublime_plugin.WindowCommand):

lastTestCommand = False
lastFilter = False

def get_setting(self, key, default=None):
return sublime.load_settings("Preferences.sublime-settings").get(key, default)
Expand Down Expand Up @@ -73,6 +74,11 @@ def find_phpunit_bin(self, directory):
def run_in_terminal(self, command):
osascript_command = 'osascript '

useSsh = self.get_setting('phpunit-sublime-ssh', False)

if useSsh:
command = self.localToSshCommand(self.filter);

if self.get_setting('phpunit-sublime-terminal', 'Term') == 'iTerm':
osascript_command += '"' + os.path.dirname(os.path.realpath(__file__)) + '/open_iterm.applescript"'
osascript_command += ' "' + command + '"'
Expand All @@ -81,21 +87,49 @@ def run_in_terminal(self, command):
osascript_command += ' "' + command + '"'
osascript_command += ' "PHPUnit Tests"'

self.lastFilter = self.filter
self.lastTestCommand = command
os.system(osascript_command)

def localToSshCommand(self, phpunitFilter):
localToHostProjectRoots = self.get_setting('phpunit-sublime-ssh-paths', {})
filePath = self.window.active_view().file_name()

for localRoot in localToHostProjectRoots:
if localRoot in filePath:
localProjectRoot = localRoot
hostProjectRoot = localToHostProjectRoots[localRoot]

sshCommand = "ssh -t -p" + str(self.get_setting('phpunit-sublime-ssh-port', 22)) + " " + self.get_setting('phpunit-sublime-ssh-user') + "@" + self.get_setting('phpunit-sublime-ssh-host') + " 'cd " + hostProjectRoot + "; vendor/bin/phpunit' " + phpunitFilter.replace(localProjectRoot, hostProjectRoot);

prefixCommand = self.get_setting('phpunit-sublime-ssh-command-prefix', False)

if prefixCommand:
sshCommand = prefixCommand + ' ' + sshCommand

suffixCommand = self.get_setting('phpunit-sublime-ssh-command-suffix', False)

if suffixCommand:
sshCommand = sshCommand + ' ' + suffixCommand

return sshCommand

class RunPhpunitTestCommand(PhpunitTestCommand):

def run(self, *args, **kwargs):
file_name, phpunit_config_path, phpunit_bin, active_view, directory = self.get_paths()

self.filter = file_name

self.run_in_terminal('cd ' + phpunit_config_path + self.get_cmd_connector() + phpunit_bin + ' ' + file_name)

class RunAllPhpunitTestsCommand(PhpunitTestCommand):

def run(self, *args, **kwargs):
file_name, phpunit_config_path, phpunit_bin, active_view, directory = self.get_paths()

self.filter = ''

self.run_in_terminal('cd ' + phpunit_config_path + self.get_cmd_connector() + phpunit_bin)


Expand All @@ -106,6 +140,8 @@ def run(self, *args, **kwargs):

current_function = self.get_current_function(active_view)

self.filter = file_name + " --filter '/::" + current_function + "$/'"

self.run_in_terminal('cd ' + phpunit_config_path + self.get_cmd_connector() + phpunit_bin + ' ' + file_name + " --filter '/::" + current_function + "$/'")

class RunLastPhpunitTestCommand(PhpunitTestCommand):
Expand All @@ -116,13 +152,16 @@ def run(self, *args, **kwargs):
if 'Test' in file_name:
RunSinglePhpunitTestCommand.run(self, args, kwargs);
elif self.lastTestCommand:
self.filter = self.lastFilter
self.run_in_terminal(self.lastTestCommand)

class RunPhpunitTestsInDirCommand(PhpunitTestCommand):

def run(self, *args, **kwargs):
file_name, phpunit_config_path, phpunit_bin, active_view, directory = self.get_paths()

self.filter = directory

self.run_in_terminal('cd ' + phpunit_config_path + self.get_cmd_connector() + phpunit_bin + ' ' + directory)

class RunSingleDuskTestCommand(PhpunitTestCommand):
Expand Down