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
- Loading PHPUnit with autoload.php from the Composer dependency manager
- Running PHPUnit from the phpunit.phar archive
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.
- Open the Settings dialog box, and click PHP. The PHP page opens.
- From the Interpreter drop-down list, choose the PHP installation to use.
-
Configure the
PEAR
folder as an include path. Click the Add button in the Include path area, and select thePEAR
folder in the dialog box, that opens. - 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.
-
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 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, theautoload.php
file is stored in thevendor
folder.
-
Download
- Open the Settings dialog box, and click PHPUnit under the PHP node.
-
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:- Download phpunit.phar manually.
- Open the Settings dialog box, and click PHPUnit under the PHP node.
- 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
:- Open the Settings dialog box, and click PHPUnit under the PHP node.
- On the PHPUnit page that opens, choose Path to phpunit.phar and click the Download phpunit.phar... link.
-
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.