First things first, wamp does not come with PEAR, so we need to install that before we can install PHPUnit.

Installing the PEAR package

  1. Add the php directory (in my case “C:\wamp\bin\php\php5.3.13″) to your Windows’ Environment Variables PATH if it is not already added. (Advanced System Settings, Environment Variables, Edit Path)
  2. Download http://pear.php.net/go-pear.phar to some location in your system.
    (I downloaded it to C:\wamp\bin\php\php5.3.13)
  3. Open a new command prompt as an administrator and cd to the directory where go-pear.phar is placed.
    (I did: cd C:\wamp\bin\php\php5.3.13)
  4. Now run the command
    php go-pear.phar

Installing PHPUnit

  1.  Open a new command prompt as an administrator and run:
    pear config-set auto_discover 1
    pear install pear.phpunit.de/PHPUnit

Now the tricky part begins..  As the wamp installer had created two copies of php.ini file, one is placed at C:\wamp\bin\apache\apache2.2.22\bin and another at C:\wamp\bin\php\php5.3.13\.

While running pear installer detects php.ini file placed at the later location and makes changes to it. I guess it gave me an option (showing both php.ini’s) while installing but i chose the file it suggested and thus the following changes were made to C:\wamp\bin\php\php5.3.13\php.ini file.

;***** Added by go-pear
include_path=”.;C:\wamp\bin\php\php5.3.13\pear”
;*****

Now we need to copy these changes to actual php.ini file in use by wampserver i.e. C:\wamp\bin\apache\apache2.2.22\bin\php.ini file. Just copy these three lines of code to C:\wamp\bin\apache\apache2.2.22\bin\php.ini file and restart the wamp server.

Running test case in command prompt

Create a php file test.php with the following code and place it at server root i.e. C:\wamp\www or similar:

 <?php
class MyTest extends PHPUnit_Framework_TestCase {
public function testOneEqualsOne() {
$this->assertEquals(1, 1);
}
} ?>

Now open the command prompt as an adminstrator and run:

  1. cd c:/wamp/www
  2. phpunit test.php

It should output the test results, like:

PHPUnit 3.6.11 by Sebastian Bergmann.
Time: 1 second, Memory: 3.50Mb
OK (1 test, 1 assertion)

 

Running test cases in CakePHP

Open an url of CakePHP application while debug mode set to greater than 0. For example:  http://myCakeApp.localhost/test.php