Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.


Include Page
Social Buttons PhpStorm
Social Buttons PhpStorm


PhpStorm uses PHPUnit as the test runner, a widely used unit testing framework for PHP which provides a lot of features. Let's see how it integrates with PhpStorm.

Table of Contents

1. Adding a unit test to a project

Adding unit tests to a project can be done in several ways. We can create a new file and select the PHPUnit | PHPUnit test file template. Another way to create a test for some specific class is to invoke use the Go to Test action (with Navigate | Go to Test or Cmd+Shift+T / Ctrl+Shift+T) and choose Create new test.



For more info on creating unit tests, see creating PHPUnit Tests in PhpStorm.

2. Enabling PHPUnit for our project

As we can see from the generated class above, there is no autocompletion support yet and PhpStorm does not know about the PHPUnit_Framework_TestCase class PHPUnit provides. Why is that? Because we haven't enabled PHPUnit yet for our project. Let's do that.


Let's go ahead and download PHPUnit PHAR file into a root folder of our project.

Image RemovedImage Added

Optionally, we can also specify the path to a phpunit.xml configuration file, or the path to a bootstrap file (to run arbitrary PHP code before unit tests run).



If you want to have an example class to test as well as a sample set of unit tests for it, checkout our Workshop project.

3. Running unit tests

The easiest way to run PHPUnit test in PhpStorm is to right click a test file in a Project Tool window and select > Run 'test name'. Once runA test class/separate method can be run by right clicking it directly in editor or by selecting a class file in a Project Tool window. Once run, PHPUnit run configuration will be automatically created: you can view it in Run menu > Edit configurations... . It should appear under PHPUnit node and named after a test file we've run.


We can also manually create a test run configuration but that it is often too cumbersome and should be reserved for the advanced PHPUnit test configurations. When we create a new PHPUnit run configuration (or edit existing one) we can provide details such as run configuration name, which tests should be run (all tests in a directory, a specific test class or one specific test). Adding test runner arguments or PHP interpreter options is also supported. 


4. Reviewing test results

We are now ready to run (or debug) our unit tests! Let's do this: just right click a PHPUnit test and select "Run 'test name' ...". This will bring up a new tool window in which test results will be displayed.

Image RemovedImage Added

The test results tool window is divided in 3 2 main areas: the left side allows us to filter tests or export results . The middle area shows us the raw PHPUnit output. In the right part, we can as well as drill down through all unit tests and see which ones succeeded and which ones failed. The right area shows us the raw PHPUnit output. 

From the test results we can also use the context menu to perform several actions, such as running one specific test or navigating to the test source code.

Image RemovedImage Added

Keep in mind that you can also debug unit tests, as well as use the techniques outlined in Profiling the Performance of PHP Applications to analyze the test run performance.