Running PHPUnit tests from Eclipse Helio

This article describes how to unit tests from the Eclipse - Helio IDE, using PHPUnit as an external tool.

To configure an external tool, launch the Eclipse Workbench and (from the top menu bar) click: Run > External Tools > External Tools Configurations... You should see the external tools configurations dialogue. Select the Program configuration in the left tab and click the New launch configuration button above it. Fill in the fields as follows:

  1. Name
    Enter a name for this external tool in the name box e.g. MyPHPUnit
  2. Location
    Enter the full path to your PHP executable. For a Zend Server install on Windows, the default location is probably C:\Program Files\Zend \ZendServer\bin\php.exe.
  3. Working directory
    Enter the working directory for the tool. If you want PHPUnit to autoload an xml configuration file, set this to the folder containing the xml file. Using the ${project_loc}/tests sets this to the folder 'tests' within the current Eclipse project - click the Variables button to see more variables that Eclipse can resolve for you.
  4. Arguments
    Enter the location of PHPUnit, and the name of the tests file to run. Rather than hardcoding the filename, specify it as an Eclipse variable to allow you to select the file from the IDE.

    You can pass PHPUnit switches in this arguments field e.g. to set the verbose switch set arguments to: "C:\Program Files\Zend\ZendServer\bin\phpunit" --verbose ${selected_resource_loc}

Click the Apply or Run button to save your launch configuration. Here is an example of a complete configuration. Eclipse external tool configuration

To run a PHPUnit test from your workspace, left click the test file (e.g. UserControllerTest.php). Then from the top menu bar click Run > External Tools > External Tools Configurations and select your launch configuraton (e.g. PHPUnit in diagram above). This will run the tests in the selected test file.

After running the external tool once it will be added to the launch history, and you can run it as e.g.: Run > External Tools > PHPUnit

See also Eclipse - PHPUnit.