Tuesday, January 12, 2010

PHPUnit on Windows, phew!

Wow, sometimes things can be so friggin difficult! I think I finally have phpUnit installed on my Windows development machine, and figured I'd record my actions here both for my own reuse and hopefully for anyone traveling down the same road.

If you want to jump straight to the instructions, feel free. Otherwise, here's a little backstory.

Backstory

First, to note, I have PHP installed from the thread-safe Win32 installer packages available from http://windows.php.net/download/. I am on version 5.3.1, though I believe this process has very little to do with the version of PHP.

The thing about installing PHPUnit, is that it first requires that you have PEAR installed. The thing about PEAR on Windows, is that the installers for PHP do not ship with a valid way of installing PEAR. All the instructions I could find on the web start with something like:

Install PEAR using c:\PHP\go-pear.bat
This script, however is broken, as it goes looking for PEAR/Pear5.php and just dies there. I tried numerous attempts at patching together the files it says it needs, but alas in the end I decided it just wouldn't work.

After much searching, I came across a go-pear.php script on pear.php.net's own site (http://pear.php.net/go-pear). Not to be confused with go-pear.bat, mind you.

This was the turning point to it all. There were still a few hiccups along the road that hopefully these instructions will help you overcome. Also note that I am working on a Windows 7 machine, so I also had some issues with having to run certain parts as an administrator. If you're on XP, you can ignore the "Run as Administrator" notes, I believe.

Instructions

  1. Copy the go-pear script ( http://pear.php.net/go-pear ) and save it as go-pear.php somewhere,
    I chose %temp% and will use that throughout these instructions

  2. Open a command prompt as an Administrator
    ( Start -> All Programs -> Accessories -> Command Prompt, right-click and select "Run as Administrator )

  3. Change to the directory where you saved go-pear.php
    cd %temp%

  4. Run go-pear.php
    php go-pear.php

  5. Set the prefix path to your PHP directory by selecting #1.
    For me this was: C:\Program Files\PHP, apparently lots of people also install PHP directly in C:\PHP

  6. Let PEAR install, the other defaults were fine for me

  7. The last bit of instructions encourage you to run the PEAR_ENV.reg file to include PEAR in your command path. I did just that, feel free to or not.
Yay, now you should have PEAR installed. Moving on to PHPUnit now:
  1. Tell PEAR where to find PHPUnit
    pear channel-discover pear.phpunit.de
    Note: that this still needs to be performed as an Administrator

  2. PHPUnit apparently depends on a YAML package maintained in a different channel, so also tell PEAR where to find that package
    pear channel-discover pear.symfony-project.com
    Note: that this still needs to be performed as an Administrator

  3. Now, you can install PHPUnit.
    Since I am a sucker for dependencies, and Love to install them all blindly just in case they'll make my life a little easier, I opt to install all dependencies.
    pear install --alldeps phpunit/PHPUnit
Yippie! Now you should have PHPUnit finally installed. The PHPUnit script should now be available in your PHP directory. For me this was C:\Program Files\PHP\phpunit.bat

I hope this helps at least one other person in the world not waste their morning figuring through these steps. If you find that your experience is different that this in any way, please post a comment here so that others may benefit as well.

Good Luck, and happy Unit Testing!

No comments:

Post a Comment