forked from evgeny-golubev/SimplePHPUnit-for-Sublime-Text
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathRemotePHPUnit.py
More file actions
133 lines (104 loc) · 4.64 KB
/
Copy pathRemotePHPUnit.py
File metadata and controls
133 lines (104 loc) · 4.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import os
import sys
import shlex
import subprocess
import sublime
import sublime_plugin
if sys.version_info < (3, 3):
raise RuntimeError('RemotePHPUnit works with Sublime Text 3 only')
SPU_THEME = 'Packages/RemotePHPUnit/RemotePHPUnit.hidden-tmTheme'
SPU_SYNTAX = 'Packages/RemotePHPUnit/RemotePHPUnit.hidden-tmLanguage'
class ShowInPanel:
def __init__(self, window):
self.window = window
def display_results(self):
self.panel = self.window.get_output_panel("exec")
self.window.run_command("show_panel", {"panel": "output.exec"})
self.panel.settings().set("color_scheme", SPU_THEME)
self.panel.set_syntax_file(SPU_SYNTAX)
class RemotePhpUnitCommand(sublime_plugin.WindowCommand):
def __init__(self, *args, **kwargs):
super(RemotePhpUnitCommand, self).__init__(*args, **kwargs)
self.settings = sublime.load_settings('RemotePHPUnit.sublime-settings')
self.phpunit_path = self.settings.get('phpunit_path')
self.root_folder = self.settings.get('root_folder')
self.ssh_key = self.settings.get('ssh_key')
self.server_user = self.settings.get('server_user')
self.server_address = self.settings.get('server_address')
self.phpunit_xml_path = self.settings.get('phpunit_xml_path')
if (str(self.phpunit_path) == ""):
sublime.status_message("You have to set the phpunit_path in the RemotePHPUnit configuration")
if (str(self.server_address) == ""):
sublime.status_message("You have to set the server_address in the RemotePHPUnit configuration")
def run(self, *args, **kwargs):
try:
# The first folder needs to be the Laravel Project
self.PROJECT_PATH = self.window.folders()[0] + "/"
if self.phpunit_xml_path:
self.CONFIG_PATH = self.PROJECT_PATH + self.phpunit_xml_path
else:
self.CONFIG_PATH = self.PROJECT_PATH
if os.path.isfile("%s" % os.path.join(self.CONFIG_PATH, 'phpunit.xml')) or os.path.isfile("%s" % os.path.join(self.CONFIG_PATH, 'phpunit.xml.dist')):
self.params = kwargs.get('params', False)
self.type = kwargs.get('type', False)
self.group = ""
self.filename = ""
if self.type == "unit":
self.group = " --exclude-group functional_test"
elif self.type == "functional":
self.group = " --group functional_test"
elif self.type == "current_file":
self.filename = self.file_name()
if not os.path.isfile(self.filename):
sublime.status_message("file " + self.filename + " not found")
return False
else:
self.filename = self.filename[len(self.PROJECT_PATH):]
self.on_done()
else:
sublime.status_message("phpunit.xml or phpunit.xml.dist not found")
except IndexError:
sublime.status_message("Please open a project with PHPUnit")
def file_name(self):
return self.window.active_view().file_name()
def on_done(self):
try:
self.run_shell_command(self.PROJECT_PATH)
except IOError:
sublime.status_message('IOError - command aborted')
def run_shell_command(self, working_dir):
self.window.run_command("exec", {
"cmd": self.build_command(),
"shell": True,
"working_dir": working_dir
})
self.display_results()
return True
def build_command(self):
command = "ssh "
# add ssh key if configured
if (self.ssh_key):
command += " -i " + self.ssh_key + " "
# add server user if configured
if (self.server_user):
command += self.server_user + "@"
# add server address
command += self.server_address
command += " '"
if (self.root_folder):
command += "cd /" + self.root_folder + "; "
# set the php_unit path and group
command += self.phpunit_path + self.group
# set the xml configuration path if configured
if (self.phpunit_xml_path):
command += " -c " + self.phpunit_xml_path
# set file name if set
if (self.filename):
command += " " + self.filename
command += "'"
return command;
def display_results(self):
display = ShowInPanel(self.window)
display.display_results()
def window(self):
return self.view.window()