This section includes the installation of PHPUnit on windows. PHPUnit is testing framework for PHP. So lets start with the procedure :
- Download and Install WAMP.
- Once you have installed WAMP on your machine, open up the command prompt and go to your php directory in WAMP. Suppose Wamp is installed in C drive.
C:\> cd wamp\bin\php\php5.2.8
- From here you must run the go-pear.bat file to install PEAR and all the files needed for it.
- When executing above command, it will ask you a series of question to set itself up correctly, if you don’t know what to do, then just accept the defaults. But if you are using more than one version of PHP, then select “local” in [system/local] wide copy configuration.
- It’ll install pear 1.7.2. If you want to install PHPUnit 3.5, that package is available with PEAR 1.9.1 only. So upgrade it to higher version. To upgrade any pear, Use following command :
C:\wamp\bin\php\php5.2.8>pear upgrade pear
You can check the information of pear from any of the command.
C:\wamp\bin\php\php5.2.8>pear info pear
- Once installed you must run the PEAR_ENV.reg which will create the environment variables for the user, so that PEAR can be called in any directory on the command line.
If you cannot call PEAR from the command prompt, then you must manually add
directory to the path in the System Environment Variables list, then add the directory
"C:\wamp\bin\php\php5.2.8" to the 'PATH' & 'INCLUDE_PATH' variable. Or double click on the file
"PEAR_ENV.reg" in PHP folder, it'll register the environment variables in system.
- Once you have PEAR setup, then you must register the PHPUnit channel with PEAR.
C:\wamp\bin\php\php5.2.8>pear channel-discover pear.phpunit.de
C:\wamp\bin\php\php5.2.8>pear channel-discover components.ez.no
C:\wamp\bin\php\php5.2.8>pear channel-discover pear.symfony-project.com
- Now you can use the PEAR to install packages from the PHPUnit channel.
C:\wamp\bin\php\php5.2.8>pear install --alldeps phpunit/PHPUnit
You can check the version of PHPUnit with:
It’ll download and install PHPUnit package 1.3.1 that is compatible with PHP 4.
So to download package PHPUnit 3.5 we need to install it forcefully using command:
C:\wamp\bin\php\php5.2.8>pear install -f phpunit/PHPUnit
Note: -f is used for forcefully installation of package.
- Now your test environment is set and you can start writing testcases.
- If you want to run php or phpunit from any of the location, make sure that "path" and "include_path" environment variables are properly set to php directory.