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.phararchive.
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
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
PEARfolder as an include path. Click the Add button in the Include path area, and select thePEARfolder in the dialog box, that opens. - Click PHPUnit under the PHP node, and on the PHPUnit page that opens choose Load from include path.
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.pharfile or have IntelliJ IDEA download the file. For more details, see Using Composer Dependency Manager.
When the initialization process is completed, theautoload.phpfile is stored in thevendorfolder.
-
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.phpin 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.
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.pharmanually:-
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.
-
Download phpunit.phar
-
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.phararchive 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.