Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
This plugin allows you to convert a regular sentence to a PHPUnit test method.
# Create a file called in Plugins/ within your Sublime Text Packages folder
# You can run this via Sublime's console with: view.run_command("php_unit_test_method")
# You can bind it to ctrl+e as a regular command
import sublime
import re
import sublime_plugin
class PhpUnitTestMethodCommand(sublime_plugin.TextCommand):
def run(self, edit, lines = 10):
line = self.view.substr(self.view.line(self.view.sel()[0]))
lineSplit = re.compile(r"(\s{2,})").split(line)
self.view.replace(edit, self.view.line(self.view.sel()[0]), lineSplit[1] + '/** @test */\n' + lineSplit[1] + 'public function ' + lineSplit[2].strip().replace(' ', '_') + '()\n\t{\n' + lineSplit[1] + '\t\n' + lineSplit[1] + '}')
(row,col) = self.view.rowcol(self.view.sel()[0].begin())
self.view.run_command("goto_line", {"line": row})
self.view.run_command("move_to", {"to": "eol"})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment