All over the internet you can hundred of articles dealing with the installation of PHPUnit with Pear but rarely you will find any help for manual installation of PHPUnit with PHP or Wamp or XAMP on windows without installing Pear. There is no difference for the installation of PHPUnit if you have only PHP working on your system or have a wamp / xamp installation.
Related Tutorial: Easy Installation Install and set PHP Unit installation for a single project
What you need?
- Should have a PHPUnit bundle. You can get this from http://pear.phpunit.de/get/ . You can download PHPUnit-3.4.9.tar from the available list in official website mentioned.
- Need to set path of PHPUnit source code directly in include_path of php.ini. So where ever you have extracted PHPUnit it should be in php.ini include path. Read on to know more on this.
- PHP installation directory path should be set in Operating System Environment so that you can run php through command line.
Step By Step Guide for Installing PHPUnit manually without Pear
Now you are ready to setup phpunit. Following are the steps required to setup PHPUnit. I am using Windows XP with Wamp. If you are using custom php installation then only thing which should change are directory paths.
- Download PHPUnit- http://pear.phpunit.de/get/
- You can opt for the latest PHPUnit to download from above URL
- Setup the following path in Operating System Environment (win + break Key short cut OR right click on My Computer icon on desktop-> select properties-> select Advanced tab-> click environment variables button->select “Path” and then finally edit)-
Place this path (should be as per your setup)-> C:\wamp\bin\php\php5.2.9-2;
- This is the path to your PHP installation directory. In linux/unix based system the path can be /usr/bin/php
- Now in your php installation directory create a folder (if does not already exist) “includes”
- Open php.ini and set include path as “C:\wamp\bin\php\php5.2.9-2\includes” (if not already set). So it will look like- “include_path = “.;C:\wamp\bin\php\php5.2.9-2\includes;C:\wamp\bin\php\php5.2.9-2\includes\PHPUnit-3.2.0;”
- In above #6 assuming that PhpUnit is contained in parent folder “PHPUnit-3.2.0″
- Now in includes folder extract PHPUnit so that the folder structure is like “C:\wamp\bin\php\php5.2.9-2\includes\PHPUnit-3.2.0\PHPUnit” so that PHPUnit directory should include source code folder such as Extensions, Framework, Util etc.
- Now at this path “C:\wamp\bin\php\php5.2.9-2\includes\PHPUnit-3.2.0″ you will find a file pear-phpunit.bat file. Copy this file and place this file in “C:\wamp\bin\php\php5.2.9-2″ directory so that this file is accessible through operating system environment because “C:\wamp\bin\php\php5.2.9-2″ path we have set in the environment in step 4 above.
- Now rename this pear-phpunit.bat file to phpunit.bat. So the logic is that now through command line if we type in phpunit then operating system can detect file phpunit.bat
- Open this file phpunit.bat in a editor like notepad.
- Replace the string @php_bin@ with your php installation path. So you file should look something like-set PHPBIN=”C:\wamp\bin\php\php5.2.9-2\php.exe” “C:\wamp\bin\php\php5.2.9-2\php.exe” -dsafe_mode=Off “C:/wamp/bin/php/php5.2.9-2/includes/PHPUnit-3.2.0/PHPUnit/TextUI/Command.php” %*
- Note that the path to phpunit source code has also been changed above.
- Now we will check the installation. Go to command prompt and type phpunit – -version this should give you an output of the phpunit version you are using.
- Now you are done.
- Next you need to jump over to you php unit test file and run the test.
- So my phpunit test files are at cd projects/tests
- We can run the phpunit test file as phpunit MyTest.
- View and get a copy of modified / refactored phpunit.bat file for yourself- Click here to view
Setup Environment Variable
Get modified / refactored phpunit.bat file for yourself- Click here to view