PHPUnit installation via Composer in PhpStorm

Since version 3.7, PHPUnit allows us to install the test runner and optional dependencies using Composer. With PhpStorm 6, this workflow is now supported from the IDE.

Using both the bundled Composer support and PhpStorm’s unit testing support, we can install PHPUnit via Composer without any hassle. Let’s find out how.

Let’s start off with a blank project. We can right-click the project and use the Composer | Init Composer… context menu to enable Composer support for our project. If you don’t have composer.phar anywhere on your system, the Click here to download from getcomposer.org helper will download the latest composer.phar from the official website.

Once initialized, we can use the new PhpStorm 6 Composer support to add dependencies. We can right-click the project and use the Composer | Add dependency… context menu to download PHPUnit into our project. That’s right: PhpStorm 6 comes with a nice UI for searching packages from the Packagist website.

After successfully installing PHPUnit and all dependencies, our project structure is now the following: the vendor folder containing all dependencies brought in using Composer, including PHPUnit.

Just like with PHPUnit installed using PEAR or as a PHAR file, we need to configure PhpStorm with the location of PHPUnit. Under settings, navigate to the PHP | PHPUnit pane. We can now select the Use custom loader option and specify the path to Composer’s generated autoload.php. Optionally we can specify a default PHPUnit configuration file or a PHPUnit bootstrap file to be used when running tests.

Our run configuration will look pretty simple: specify the directory containing tests (or a specific class/method or rely on the PHPUnit configuration file to find tests to run).

We can now invoke this run configuration and have our unit tests running using the PHPUnit version installed through Composer.

Please download the latest build, provide as much feedback for bugs and feature requests here, and leave questions in the comments below or in our forums!

Develop with pleasure!
– JetBrains Web IDE Team

This blog is permanently closed.

For up-to-date information please follow to corresponding WebStorm blog or PhpStorm blog.

 
This entry was posted in Cool Feature, PhpStorm and tagged , , , , . Bookmark the permalink.

7 Responses to PHPUnit installation via Composer in PhpStorm

  1. Anton says:

    Can’t wait to upgrade my PhpStorm 5! When are you going to release it?

  2. TiTerm says:

    Really great.
    Is there a way to add skeleton generator ?

    • Nikolay Matveev says:

      Hi, skeleton generator is not supported anymore. We’ve implemented tests generation via ‘New’ -> ‘PHPUnit’ -> ‘PHPUnit Test’

  3. Seems great, although am I right in thinking that I need PHP / LAMP installed locally for this to work? I’m getting an error when I try “add dependency…”:
    “Cannot run program “php” (in directory “/home/xxx/unittests”): error=2, No such file or directory”

    What I need is how to set-up PHPUnit from a server on my local network, but I haven’t been able to find instructions for this specifically. I’d rather not have to install LAMP locally as I work with a LAMP server I just plug into the network I’m working on (on a fixed IP address).

    I’m aware that this may be the wrong place to say this, so apologies if my last comment detracts from the main topic.

  4. Pingback: Phpstorm6からcomposerが組み込まれたのでテストしてみた | bulblub

Comments are closed.