Skip to content

Instantly share code, notes, and snippets.

@drfraker
Last active March 26, 2022 17:05
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save drfraker/72806c2d210602d835b81b2411264d44 to your computer and use it in GitHub Desktop.
Save drfraker/72806c2d210602d835b81b2411264d44 to your computer and use it in GitHub Desktop.
Live Template For PHPUnit Tests
// 1. In PhpStorm go to: Preferences > Editor > Live Templates.
// 2. Click on the + button on the top right to create a new template.
// 3. Enter "@test" (no quotes) in the Abbreviation field, and give the template a name. (mine is named test case)
// 4. Copy and paste the code below into the "Template text:" section in PhpStorm
/** @test */
$NAME$
public function $SNAKENAME$()
{
$END$
}
// 6. Click the edit variables button on the right of the code window
// a. Leave the NAME variable blank.
// b. Choose the expression snakeCase() and enter the NAME variable as the string to snake case.
// c. The final result should be snakeCase(NAME)
// 7. Click the define button at the bottom of the screen and select the box labeled PHP to allow this template to be used in php files.
// 8. Select the box next to "Reformat according to style to insert the template according to your PHP style settings.
// That's it, now it should work!
// type @test and press tab to insert the template in a phpunit test file,
// type the name of the test and PhpStorm will automatically convert it to snake case. Once it's named, delete the original text with cmd + delete
@iFrancs
Copy link

iFrancs commented Mar 26, 2022

Is there a way to remove the $NAME$ automatically?

Sure press cmd + delete and that's all

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment