Thursday, September 12, 2013

How to configure PHPUnit and Aptana Studio 3?

Try to get PHPUnit integrated with Aptana Studio 3 for my unit testing, discover that it is not straight forward. Aptana Studio 3 is not ready for that kind of tight integration. I have to make use of "External Tools" on Aptana Studio to launch PHPUnit through DOS command.

Assumption
- PEAR has been installed
- Running on Window 7
- Download PHPUnit 3.7.25 from https://github.com/sebastianbergmann/phpunit/ ("phpunit.phar" will be downloaded)
- Follow the Zend 2 sample tutorial to prepare the unit testing script http://framework.zend.com/manual/2.0/en/user-guide/unit-testing.html

Steps to configure

1. Install phpunit on your machine by running the command as described below in "Command Prompt" window with phpunit.phar in the same directory.
  
pear config-set auto_discover 1
pear install pear.phpunit.de/PHPUnit
2. Once phpunit has been installed, phpunit.bat file will be created in [PEAR_INSTALL_PATH]. Launch the "Command Prompt" window and type in the command as described below to check the version of PHPUnit.
phpunit --version
PHPUnit 3.7.25 by Sebastian Bergmann.
Note: "phpunit" command is working provided you right click "Command Prompt" icon and select "Run as administrator" to launch the "Command Prompt" window.

3. In Aptana Studio 3.0, "External Tools" menu will not be available in the "Run" menu. Steps as described below are required to turn on the "External Tools" option.
- Right click the "Web Perspective" and select "Customize" menu, "Customize Perspective" screen will be displayed.


- Select "Command Groups Availability" tab and check the "External Tools" check box as shown in the screenshots below.

- Click on "Ok" button to dismiss the "Customize Perspective" screen. Click on "Run" menu, "External Tools" will be displayed.

4. Select "Run" ->  "External Tools" -> "External Tools Configuration", the configuration screen will be displayed.


5. Fill in the details as described below
Name: PHPUnit

Location: [PEAR_INSTALL_PATH]\phpunit.bat
Note: Normally phpunit.bat is located at the PEAR installation path if PEAR is used to install PHPUnit.

Working Directory: ${project_loc}/module/Application/test
Note: Based on the tutorial provided by Zend2, http://framework.zend.com/manual/2.0/en/user-guide/unit-testing.html, this should be the folder that consists of "phpunit.xml.dist" file.

6. Select unit testing class, for example, "IndexControllerText.php", click on "Run" -> "External Tools" -> "PHPUnit", the unit testing script will be executed and test result will be output to "Console" screen.

No comments: