Versions Compared

Key

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

...

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).

...

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 we 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.

...