Quantcast
Viewing all articles
Browse latest Browse all 8

using phpunit2 with eclipse

A good IDE saves a lot of time, and besides all those commercial products phpeclipse is a nice alternative.

UnitTesting has also become a valuable task to the serious PHP programmer. There is already a plugin for simpletest available to use in eclipse. Judging after the UI, it comes very close to JUnit. Unfortunately, there is no plugin for PHPUnit(2) available yet (although Sebastian stated earlier that Zend wants to take care of this for the upcoming ZendIDE). However, there is a way how you can integrate PHPUnit2 as an external tool into eclipse. I’ve done this on my Windows system at home, but you may be able to adopt this howto on a *nix machine, substituting the respective parameters with your target os pendants.

Requirements: You need a PHP version >= 5.04 for running PHPUnit2.

  1. Get the PHPUnit2 package from the PEAR web page. Make sure there are no missing dependencies and your PEAR installation is all complete. Read the documentation, configure PHPUnit2 and do a few test runs on your system, making sure your environment meets the requirements.
  2. Add the path pointing to your php executable to the environment path of your system.
  3. Start eclipse and chose Run -> External Tools -> External Tools…
  4. In the left panel, select “Program”, then click the button “New” in the lower left corner of the window.
  5. Under “Name”, type in the name under which you want to save the external tool.
  6. The field “location” needs to hold the path to your php executable, including the executable itself.
  7. Now to the tricky part: The field “Arguments” needs to hold the arguments with which the php executable should be called.
    This are:
    -c [path_to_the_php.ini_the_exec_should_be_called_with] [php_script_to_run]
    Since I think I do not need to explain the -c parameter to you, I’ll go into detail on [php_script_to_run]. This must point to the folder where the script “phpunit” sits in. This could be for example: “C:/PEAR/PHPUnit2/phpunit”.
    The first part of the argument-list could look like this now:
    -c C:/php C:/PEAR/PHPUnit2/phpunit
    Now we have to work with variable substitutions. The pattern we will use to run a TestCase is “[TestClassName] [PathToTestClass]”
    The appropriate substitutions are: ${resource_name} ${workspace_loc}${resource_path}
  8. Taking the above example, the content of the field “Argument” should by now look like this: -c C:/php C:/PEAR/PHPUnit2/phpunit ${resource_name} ${workspace_loc}${resource_path}< /li>
  9. Click “Apply”, then “Close”

Running a TestCase is quite easy: Load an already existing PHPUnit2 TestCase into your file list, then select it – this is necessary to make the variable substitutions work. Then chose Run->external Tool->[the_name_for_your_PHPUnit2_tool]. If everything works right, you should see the output generated by PHPUnit2 in the eclipse console.

I have attached a screenshot of my configuration.

Image may be NSFW.
Clik here to view.
Making PHPUnit2 work in eclipse


Viewing all articles
Browse latest Browse all 8

Trending Articles