PHPUnit testing in Eclipse with PHP Tool Integration

PHPUnit testing in Eclipse can easily be accomplished with PHP Tool Integration (http://www.phpsrc.org).

You’ll of course need to have Eclipse installed as well as the PHP Development Tools (PDT) plugin.  You’ll also need to have PHP installed and PHPUnit.

To install, use the install utility in Eclipse.  Open Eclipse and from the main menu select Help > Install New Software…

Inside the Install window, Click the “Add…” button next to the “Work with” select box to add the PHP Tool Integration software site.
 

For the repository location, enter “http://www.phpsrc.org/eclipse/pti/”.  You may enter a name or leave it blank to use the default. Then, click the “OK” button.
 

Once you’re back at the install window, select the items you want installed.  Be sure to select PHPUnit and, while you’re at it, you might as well install the other helpful packages.

Once you hit the “Next >” button, you’ll have the usual Eclipse install detail windows. Click through them and accept the agreements.

After it finishes installing, you need to configure PHPUnit.  From the main menu bar select Window > Preferences

Check to make sure you have your PHP executable set up.  Select “PHP Executable” on the left pane.  If an executable hasn’t been added, add one now by clicking the “Add” button.

Select the PHP executable file and give it a name.  Click the aptly named “Finish” once you’re finished.
 

Now set up PEAR libraries.  Select “PHP Tools” > Library > PEAR on the left preferences pane.  Click “New…” to add a new library path.

Enter your PEAR library path inside your php installation.
 

After setting up your PEAR library path and PHP executable.  Select “PHP Tools” > PHPUnit in the left preferences pane.  Under PHP Executable select the executable you set up and under PEAR Library select the library path you selected.  If they do not appear in the drop down box, you may need to apply changes and reenter the preferences window.
 

Now to use PHPUnit, from the main menu select Window > Show View > PHPUnit.  If it is not shown in the menu select Window > Show View > Other…
 

If PHPUnit did not show under the “Show View” menu, and you selected Other… Select the PHPUnit view under the PHP Tools folder.
 

You’ll now have a familiar Unit testing view to work with!