Run and debug PHPUnit tests in PhpStorm
It's possible to run and debug single tests as well as tests from entire files and folders from PhpStorm. Here, we'll explain how to do the setup and the steps you need to follow to do this.
Run PHPUnit test
To run a PHPUnit test, you first need to create a CLI interpreter. To do this, open PhpStorm and then follow the steps below:
- Go to Settings, then Language & Frameworks, and then PHP
- Click the more icon (...) on the CLI interpreter option
You'll now see a new screen for CLI Interpreters.
- Click the add icon (+) and select the option From Docker, Vagrant, VM, ...
- Select Configure Remote PHP Interpreter
- Click the add icon (+) to create a new SSH configuration
- Enter the Host, User name, and Password with the details from your developer sandbox

Once you've done this, you should be able to see your new CLI interpreter:

After clicking the OK button, you'll be taken back to the PHP config screen. There, you can click on the folder icon and specify the mapping between your Local Path and the Remote Path /var/www/frontastic
:

Set up a new test framework
To set up a new test framework in PhpStorm, you'll need to follow the steps below:
- Go to Settings, then Language & Frameworks, then PHP, and select Test Frameworks
- Click the add icon (+) and select the PHPUnit by Remote Interpreter
This will open a new window.
- Select the CLI interpreter that you have created and click OK
- Once the new test framework is created, you should specify the Path to script with
/var/www/frontastic/<project_folder>/vendor/autoload.php
:

Set up PHPUnit test suit
To set up a test suit in PhpStorm, you'll need to follow the steps below:
- Go to Menu, then Run, and select Edit configuration
- Click the add icon (+) and select PHPUnit
- Input a name, for example,
Test suit
, and specify your local directory where your PHPUnit test will live - Click OK

You should now be able to run your PHPUnit test within PhpStorm.
Debug PHPUnit test
In order to debug the PHPUnit test, you'll need to update the PhpStorm config. To do this:
- Go to Settings, then Language & Frameworks, and then PHP
- On the CLI interpreter option, click the more icon (...)
- Go to Configuration options, click the folder icon, then the add icon (+)
- Set the directive
xdebug.client_host
and value127.0.0.1
- Click OK
You should see something like the below:

You'll then need to make sure that you're using the right port:
- Go to Settings, then Language & Frameworks, then PHP, and select Debug
- Check the Debug port in the Xdebug section is set to
9003

You can then open your Xdebug tunnel.
- Go to your terminal and select your project folder
- Run
$ frontastic xdebug
- Set a breakpoint in one of your tests and execute it by clicking the debug icon
Updated over 2 years ago