Running PHPUnit tests in PHPStorm

Victor Bolshov
Jan 19, 2017 · 2 min read

Did you know that PHPStorm has a nice intergration with PHPUnit? Running tests directly from IDE offers several benefits that can boost your productivity to some extent:

  1. Running a test method / test class / test suite by simply pressing a combo on your keyboard
  2. Same as point 1 but I have to mention it separately: you can do it on a remote server as well — via SSH
  3. Failures are reported directly in the IDE, and a click on a file name takes you directly to the required line.

To have your tests run in PHPStorm, you will have to set up a few things:

  • PHP interpreter
  • PHPUnit

Setting up local PHP interpreter

Go to Settings ▶ Languages & Frameworks ▶ PHP

Image for post
Image for post
PHP interpreter settings screen

It’s pretty much self-explaining, as you can see, and you are likely to have this already set up, if you actively do PHP development.

A lot of companies use remote sandboxes to run development version of the project, run tests etc. For that, you can setup remote interpreter by clicking on the ellipsis button next to CLI Interpreter dropdown:

Image for post
Image for post
Remote PHP interpreter settings screen

Setting up PHPUnit

Go to Settings ▶ Languages & Frameworks ▶ PHP ▶ PHPUnit

Image for post
Image for post
PHPUnit settings screen

You can select a PHP interpreter, path to PHPUnit executable (often it is the path to phpunit.phar but I prefer to symlink it to have a shorter name). If you use XML configuration and/or a bootstrap file, those can be specified for your project as well.

Running tests

Easy as 2x2. Select the whole folder with tests in the project tree and press a combo (Ctrl+Shift+F10 in my configuration which has Eclipse keymap as a base; find yours in Settings ▶ Keymap). Alternatively, right-click folder name and choose “Run PHPUnit”.

But that’s not all PHPStorm can do for you. Place the cursor inside a test method and press the same combo: PHPUnit will run just that particular test method. Extremely handy when actively developing something and constantly switching between working code and test code and running the test. Moreover, if you place the cursor outside a test method, while still staying within the test class and run PHPUnit — the whole test class is run.

Keep calm and write unit tests. See you later ;-)

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store