Thursday, September 6, 2012

Installing PHPUnit with XAMPP


Install PHPUnit with XAMPP

Update:

This method is now deprecated per Sebastian Bergmann.  Use the phar or composer method to install PHPUnit.


XAMPP is a great utility to get you started quickly with Apache, MySQL, and PHP.  In fact I wasn't even able to get these programs working together properly on my new Windows 7 machine until I used XAMPP to install all the components I needed.  But do you how to setup PHPUnit with XAMPP?  To get PHPUnit working, the steps aren't quite as obvious.  As you will see the PEAR installation tool is used, but it needs some additional work as explained below.

1. First get and install XAMPP: http://www.apachefriends.org/en/xampp.html

Now after the install, usually you'll have your files under something like c:\xampp\php, etc.  This works pretty well, but to get PHPUnit, you need PEAR which needs some additional install.

2. Get the latest PEAR update and run the PEAR installer:
download the file at http://pear.php.net/go-pear.phar and place it in your C:\xampp\php folder
cd \xampp\php
php go-pear.phar
3. Change the location of your pear.ini (item#11 or 12 - the menu varies according to your system) to C:\xampp\php - This is especially important on Windows 7 that protects the windows folder. If this is not changed your PEAR install will not be able to save its configuration files.

4. Run the C:\xampp\php\PEAR_ENV.reg file created to import your PEAR environment variable settings.

5. Log out of Windows and back in - This will load the new environment variables into memory (otherwise the old location for pear.ini will be used).  Confirm your settings by running:
pear config-show
 It should now read: C:\xampp\php\pear.ini

6. Install PHPUnit & Skeleton Generator through PEAR
pear config-set auto_discover 1 
pear install pear.phpunit.de/PHPUnit
pear install phpunit/PHPUnit_SkeletonGenerator
7. Check your version of PHPUnit - It should be at least version 3.6.x

phpunit --version
You should also now have phpunit-skelgen.bat in the C:\xampp\php folder.

If this blog was helpful to you, please thank me by clicking on the google +1 link.  Every time you click +1 a unicorn gets its wings... and what's cooler than a flying unicorn?

Netbeans NOTE:
First of all, if you are trying to use Netbeans to do unit testing in PHP, then you should probably start at the great tutorial at: http://netbeans.org/kb/docs/php/phpunit.html#installing-phpunit

Update:
The PEAR install method is now at end of life and can no longer be used according to Sebastian Bergmann's github page.

Try this method for using the phar install method: Phar install method.


6 comments:

  1. Last installation of xampp offer to change pear.ini location with item 11, and not item 12

    ReplyDelete
    Replies
    1. Thanks for the note. I realize the menu may change per the individual users system when using the pear installer. I've updated the step description.

      Delete
  2. it's cool! Very nice the tutorial!

    Thank!

    ReplyDelete
  3. Search a lot on web, But only this works .

    Thanks a lot

    ReplyDelete