Installing PHPUnit with MAMP’s PEAR installer is pretty straightforward, but there are a few things to note:
- Everything will be done through Terminal, so go ahead and launch it now. All of the commands I provide can be copied and pasted as they are.
- Make sure you’re using the version of PEAR that came with MAMP, not the version that came with your Mac. This means you have to use
/Applications/MAMP/bin/php5/bin/pearat the prompt, notpear. - PHPUnit 3.4 requires PHP 5.1.4 or later, but PHP 5.3.2 or later is recommended. MAMP 1.8.2 (the version I have installed) is running version 5.2.10. The latest version of MAMP includes version 5.3.2. So far, I haven’t noticed any problems running PHPUnit under 5.2.10.
- PHPUnit also requires PEAR 1.8.1. MAMP 1.8.2 ships with version 1.8.0. To check which version you have installed, type
/Applications/MAMP/bin/php5/bin/pear -V.
If you need to upgrade PEAR, first use the following two commands: /Applications/MAMP/bin/php5/bin/pear channel-update pear.php.net
/Applications/MAMP/bin/php5/bin/pear upgrade pear
Now, it’s time to install PHPUnit. The PEAR channel used to distribute PHPUnit needs to be registered with the local PEAR environment and a component that PHPUnit depends upon is hosted on the Symfony Components PEAR channel. To register the channels and install, simply type: /Applications/MAMP/bin/php5/bin/pear channel-discover pear.phpunit.de
/Applications/MAMP/bin/php5/bin/pear channel-discover pear.symfony-project.com
/Applications/MAMP/bin/php5/bin/pear install phpunit/PHPUnit
PHPUnit is now installed, but to get it to run from Terminal, we need to move it into our $PATH. To do so, type: mv /Applications/MAMP/bin/php5/bin/phpunit /usr/local/bin/phpunit.
To test your install, type: phpunit --version.
You should see something like PHPUnit 3.4.15 by Sebastian Bergmann. And that’s it!