Monday, September 2, 2013

Installing PHPUnit on Windows

I wanted to work on Selenium using PHP so I needed to install PHPUnit as PHPUnit supports Selenium for Automation Testing.

It wasn't an easy task, it took me a while to install PHPUnit on my system so I've written down the steps to finally get it working.


Steps:

  1. First you need to install PHP on your machine which is a mandate. Please download PHP for windows from here.

  2. Once you have downloaded the installer, run it and install and PHP anywhere you like and remember this path for later, choose your webserver and select any additional components as needed. Select none if you don't have any webserver.

  3. Once PHP is installed open a command prompt (cmd) and type php -v to check whether it is installed successfully or not. It should give you output like
              
                PHP 5.4.3 (cli) (built: Feb 2 2012 20:27:51)
                Copyright (c) 1997-2012 The PHP Group
                Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
    
    
    if this isn't the output, please check your installation again.

  4. Before Installing PHPUnit, you need to install PEAR, which is a dependency for PHPUnit:
    • You need to download the go-pear.phar which can be downloaded from here.
    • Save go-pear.phar in the directory where you have installed PHP in step 2.
    • Open the command prompt in administrator mode. Navigate to the folder where you have PHP installed or you have saved the file in previous step.
    • To install PEAR type php go-pear.php in the command prompt and press ENTER.
    • Installation is pretty self explanatory you just need to provide the inputs once its asked.
    • In last step, it will ask to modfiy php.ini file, type Y and press ENTER.
    • After you are done on command prompt go to the folder where PHP is installed, you will find a file PEAR_ENV.reg, double click on that file to add it to the registry, this help you to run pear command from any folder.
    • Verify PEAR is working properly by running the pear version command on CMD(command prompt).

  5. Installing PHPUnit:
  • Go to command prompt and turn on the auto_discover in PEAR, use the command pear config-set auto_discover 1
  • Download and Install PHPUnit by running the command mentioned below pear install pear.phpunit.de/PHPUnit
  • Now to run PHPUnit from any folder, you need to set it to your windows PATH variable. Right Click on My Computer => Properties => Advanced System Settings => Environment Variables => Select path under system variables, Click Edit, navigate to its end, type semicolon (;) and then append the full path of your PHP folder after the semicolon.
  • Verify PHPUnit is working by running the following command phpunit --version

By following the commands mentioned above you would be able to successfully install PHPUnit on windows operating system.
Source:
http://www.viper007bond.com/2012/08/21/installing-phpunit-on-windows/

No comments: