Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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 */
public function $SNAKENAME$()
// 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
Copy link

wrabit commented Feb 7, 2020

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

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