This is a short guide on setting up PHP Storm to run your unit tests inside your Vagrant machine, and displaying the results within PHP Storm itself - removing the need to flip between your terminal app and PHP Storm repeatedly. Once you're set up, you'll be able to run your tests from the press of a button or a key command of your choice.
The first step is to tie into the remote interpreter on your Vagrant machine if you haven't already. Click: Add
By Remote Interpreter
, and then select the From Vagrant
option. From here, you'll need to select the folder your Vagrant machine runs from. Save the new interpreter and apply your changes.
PHP Storm - Vagrant - Setup PHP Interpreter
Next up we need to specify the path of PHP Unit on your Vagrant machine. I have my machine set up with PHP Unit running from /usr/bin/phpunit
, so I specified this with the Path to phpunit.phar
option.
All that's left is to define which phpunit.xml
file to run and your autoload config. Set the paths in the Test Runner
section, and then save everything.
PHP Storm - Vagrant - PHP Unit Settings
To run the tests easily we need to create a Debug Configuration using our new settings. In the debug control panel (Top Right on my install of PHP Storm) select the drop down menu and click Edit Configurations...
. In the new window, create a new PHP Unit configuration and give it a name. If you have a button labelled Fix
in the bottom right of the window, click it and select your PHP interpreter. Then save your new configuration.
Edit Configurations
Fix Problems
To run the test you just click the green arrow in the same debug control panel area, a new window will open with your runnings tests!
Run Your Tests!