Skip to content

Instantly share code, notes, and snippets.

@dakira
Created May 27, 2021 21:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dakira/65380f181a53376f9fe0cc86c6272288 to your computer and use it in GitHub Desktop.
Save dakira/65380f181a53376f9fe0cc86c6272288 to your computer and use it in GitHub Desktop.
This plugin allows you to convert a regular sentence to a PHPUnit test method.
# Create a file called PHPUnitTestMethodPlugin.py 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