PHPUnit on Mac OS X Snow Leopard 10.6 and Lion 10.7

As documentation suggest — we should use PEAR to install PHPUnit. Snow Leopard and Lion comes with PEAR preinstalled, but if you try running commands described in PHPUnit manual you wil run into errors because version of PEAR bundled with the system is outdated.

So let's fix that by installing fresh version:

cd /tmp && mkdir pear && cd pear
curl > go-pear.phar
sudo php -d detect_unicode=0 go-pear.phar

Now you need to change setting presented to you to match these ones:

 1. Installation base ($prefix)                   : /usr/lib/php
 2. Temporary directory for processing            : /tmp/pear/install
 3. Temporary directory for downloads             : /tmp/pear/install
 4. Binaries directory                            : /usr/bin
 5. PHP code directory ($php_dir)                 : /usr/lib/php
 6. Documentation directory                       : /usr/lib/php/doc
 7. Data directory                                : /usr/lib/php/data
 8. User-modifiable configuration files directory : /usr/lib/php/cfg
 9. Public Web Files directory                    : /usr/lib/php/htdocs
10. Tests directory                               : /usr/lib/php/tests
11. Name of configuration file                    : /Users/your_username/.pearrc

Now you need to update php.ini as described here. On Mac it's located in /etc/php.ini. If you don't see it there you need to rename /etc/php.ini.default to /etc/php.ini. After that you are good to go with commands from PHPUnit manual, just need to prefix them with sudo:

sudo pear channel-discover
sudo pear channel-discover
sudo pear channel-discover
sudo pear install phpunit/PHPUnit
Social comments Cackle