-
Notifications
You must be signed in to change notification settings - Fork 11
/
plugin.py
118 lines (73 loc) · 3.05 KB
/
plugin.py
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
# Copyright (C) 2023 Gerard Roche
#
# This file is part of PHPUnitKit.
#
# PHPUnitKit is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# PHPUnitKit is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with PHPUnitKit. If not, see <https://www.gnu.org/licenses/>.
import sublime_plugin
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):
def run(self, **options):
PHPUnit(self.window).run(options=options)
class PhpunitTestFileCommand(sublime_plugin.WindowCommand):
def run(self, **options):
PHPUnit(self.window).run_file(options=options)
class PhpunitTestLastCommand(sublime_plugin.WindowCommand):
def run(self):
PHPUnit(self.window).run_last()
class PhpunitTestNearestCommand(sublime_plugin.WindowCommand):
def run(self, **options):
PHPUnit(self.window).run_nearest(options=options)
class PhpunitTestResultsCommand(sublime_plugin.WindowCommand):
def run(self):
PHPUnit(self.window).show()
class PhpunitTestCancelCommand(sublime_plugin.WindowCommand):
def run(self):
PHPUnit(self.window).cancel()
class PhpunitTestVisitCommand(sublime_plugin.WindowCommand):
def run(self):
PHPUnit(self.window).visit()
class PhpunitTestSwitchCommand(sublime_plugin.WindowCommand):
def run(self):
PHPUnit(self.window).switch()
class PhpunitToggleOptionCommand(sublime_plugin.WindowCommand):
def run(self, option, value=None):
PHPUnit(self.window).toggle(option, value)
class PhpunitTestCoverageCommand(sublime_plugin.WindowCommand):
def run(self):
PHPUnit(self.window).coverage()
class PhpunitListener(sublime_plugin.EventListener):
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):
file = self._getTestableFile(files)
if file:
PHPUnit(self.window).run_file(file)
else:
PHPUnit(self.window).run_file()
def is_enabled(self, files):
return len(files) == 0 or bool(self._getTestableFile(files))
def _getTestableFile(self, files):
if files and len(files) == 1 and files[0].endswith('.php'):
return files[0]
return None