In any software development project, the key to success is the creation of unit test cases and thorough usage of them during development and post development.
On the same line of Java, which provides JUnit as the Unit Testing Framework, PHPUnit can be used. I have gone through many resources on Internet and collated the information in this blog.
Steps to follow
- On successful installation of WAMP, open up the command prompt and go to your php directory in WAMP
- D:\>cd wamp\bin\php\php5.2.5
Pear Set Up
- Execute go-pear.bat file to install PEAR
- Accept the defaults for the questions asked by PEAR
- On installation of PEAR, run PEAR_ENV.reg. It would create the environment variables to make pear globally available in command line
Register PHPUnit with PEAR
- Once you have PEAR setup, then you must register the PHPUnit channel with PEAR
- D:\wamp\bin\php\php5.2.5>pear upgrade pear
- You should now find the PHPUnit source files under the PHP directory with phpunit.bat in php main folder
- Restart wamp
XDebug Set Up
- Netbeans version should be 6.8 ( It will not work with version 6.5 )
- Install xdebug using the guidelines from http://xdebug.org/download.php and http://xdebug.org/install.php
- In php.ini ( Apache one ) copy the following lines
a. zend_extension_ts = “D:/wamp/bin/php/php5.2.9-1/ext/php_xdebug-2.1.0-5.2-vc6.dll”
- Restart wamp
- Go to Tools->Options->PHP->general tab
- In general tab there is debugging option: Debugging port:=9000 session ID= netbean xdebug
- Remove net beans and write session ID = xdebug
- Restart IDE.
- Right click on file in the project and go to Tool->create PHPUnit tests . It will ask select the directory with project test file. Create a folder let’s say called “tests” in the project
- Test files would be created inside the folder
- For e.g. if we are writing test case for search.php, searchtest.php in the test folder would be created.
- Right click on the project folder and click on Test which would run all the test cases in the project against all the classes
- Also you can run the code completion by right clicking on the project folder and select code completion which would show you the results as how many functions in the project are there with test cases written for them.
You are all set to test your PHP classes with PHPUnit with debugging enabled.