After a few hours of Googling and headdesking, I finally got PHPUnit up and running in my local environment. In the end, I had to make reference to a bunch of different resources. It was a convoluted enough process that I don’t think I can replicate step-by-step instructions, but I can at least list some of the stumbling blocks I hit along the way.
My setup: OSX (10.6.8), running PHP 5.3.2 from the MAMP package. Generally, the commands I give here will have to be run as root; use either
sudo each time or enter the root prompt with
The basic instructions for installing PHPUnit tell you to use PEAR:
<br /> pear channel-discover pear.phpunit.de<br /> pear channel-discover components.ez.no<br /> pear channel-discover pear.symfony-project.com<br /> pear install --alldeps phpunit/PHPUnit<br />
But when you’re running MAMP, ‘pear’ may point to the wrong version of PHP – the version that comes bundled with OS X, or another of the versions that comes with MAMP. Make sure that you’re referencing the proper one (source). In my case, that means:
<br /> /Applications/MAMP/bin/php5.3/bin/pear channel-discover pear.phpunit.de<br />
and so forth.
As noted here and elsewhere, PHPUnit requires at least PEAR 1.8.1, but MAMP (or at least the version I have installed) ships with an earlier release. (You’ll know that this is the case, because when you try installing PHPUnit with the commands above, you’ll get a bunch of messages about required versions.) When I tried upgrading PEAR with the internal
<br /> /Applications/MAMP/bin/php5/bin/pear channel-update pear.php.net<br /> /Applications/MAMP/bin/php5/bin/pear upgrade pear<br />
I got a “Nothing to upgrade” message. I ended up doing a sort of manual upgrade, using step 6 of these instructions:
<br /> cd /Applications/MAMP/bin/php5.3<br /> curl -O http://pear.php.net/go-pear.phar<br /> php go-pear.phar<br />
and then following the on-screen instructions for configuring PEAR.
I found that, in my situation, the automatically generated PEAR configuration files pointed to the wrong version of PHP. I used the instructions in this comment to lead me in the right direction. More specifically, when I looked at the PEAR config settings
<br /> pear config-show<br />
I saw immediately that some of the paths were pointing to the wrong version of PHP (at /Applications/MAMP/bin/php/ rather than /Applications/MAMP/bin/php5.3/). I reconfigured the necessary paths like so:
<br /> pear config-set doc_dir /Applications/MAMP/bin/php5.3/lib/php/doc<br />
and so on.
This got me to the point where I could fire up PHPUnit on my version of PHP, without getting a ‘command not found’ error. However, I didn’t get very far in my testing, because I kept getting fatal errors. In my PHP error logs, I could see that lines in PHPUnit, like the following, were failing to find their targets:
<br /> require_once 'PHPUnit/Autoload.php';<br />
This suggested that the include_path in my php.ini didn’t have the correct directory. So I opened it up (on my installation, it’s at
/Applications/MAMP/conf/php5.3/php.ini). It turns out that PEAR had attempted to rewrite the include_path directive but it had pointed to the wrong path for my purposes. I appended the following path (which is where PEAR keeps the PHPUnit package files):
Et voilà – it finally worked:
<br /> phpunit --version<br /> # PHPUnit 3.5.15 by Sebastian Bergmann.<br />