IntelliJ IDEA 2016.2 Help

Enabling PHPUnit Support

IntelliJ IDEA supports unit testing of PHP applications through integration with the PHPUnit tool.

You can use PHPUnit in IntelliJ IDEA in the following ways:

  • Install PHPUnit and run it from PEAR that is configured as include path. The advantage of this approach is that once installed, PHPUnit can be re-used in other IntelliJ IDEA projects.

    The PHPUnit installation procedure depends on the operating system you use and your system settings. Please, refer to the PHPUnit installation instructions for information on installing and configuring this tool.

  • Install PHPUnit using the Composer Dependency Manager and run this instance.
  • Without installing PHPUnit. Just run it from the phpunit.phar archive.

On this page:

Configuring the PEAR folder with PHPUnit as an include path

The PHPUnit installation procedure depends on the operating system you use and your system settings. Please, refer to the PHPUnit installation instructions for information on installing and configuring this tool.

  1. Open the Settings dialog box, and click PHP. The PHP page opens.
  2. From the Interpreter drop-down list, choose the PHP installation to use.
  3. Configure the PEAR folder as an include path. Click the Add button in the Include path area, and select the PEAR folder in the dialog box, that opens.
  4. Click PHPUnit under the PHP node, and on the PHPUnit page that opens choose Load from include path.

Loading PHPUnit with autoload.php from the Composer dependency manager

The Composer Dependency Manager can download PHPUNit and add it to the current project. The tool loads packages using the autoload.php file in the vendor folder.

  1. Enable Composer in your project. Do one of the following:
    • Download composer.phar, configure Composer as a command line tool, and initialize it in your project in the command line mode.
    • Set up Composer in your project through the user interface: choose Tools | Composer | Init Composer and then specify the location of an existing composer.phar file or have IntelliJ IDEA download the file. For more details, see Using Composer Dependency Manager.
      When the initialization process is completed, the autoload.php file is stored in the vendor folder.
  2. Open the Settings dialog box, and click PHPUnit under the PHP node.
  3. On the PHPUnit page that opens, choose Use custom loader and specify the location of the autoload.php in the Path to script text box below.

When you start a testing session for the first time, the autoload.php file starts, installs and runs PHPUnit.

Running PHPUnit from the phpunit.phar archive

You can download phpunit.phar manually and then tell IntelliJ IDEA to load the libraries from it or have IntelliJ IDEA download phpunit.phar automatically. Depending on your preferences, do one of the following:

  • Download phpunit.phar manually:
    1. Download phpunit.phar manually.
    2. Open the Settings dialog box, and click PHPUnit under the PHP node.
    3. On the PHPUnit page that opens, choose Path to phpunit.phar and specify the location of the archive in the Path to phpunit.phar text box below.
  • Have IntelliJ IDEA download phpunit.phar:
    1. Open the Settings dialog box, and click PHPUnit under the PHP node.
    2. On the PHPUnit page that opens, choose Path to phpunit.phar and click the Download phpunit.phar... link.
    3. In the dialog box that opens, specify the folder to store the phpunit.phar archive after download. IntelliJ IDEA starts the download. After the process is completed successfully the file is stored in the chosen folder and the path to this folder is displayed in the Path to phpunit.phar text box below.

See Also

Last modified: 23 November 2016