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!
Hi,
Through (4) on your list I have at least the requirements (MAMP v1.9.2, PHP v5.3.2), except I cannot check pear.
/Applications/MAMP/bin/php5.3/bin/pear -V (I added the 5.3) results in permission denied; prepending that with sudo I get command not found.
Same thing (including command not found result) happen when I try the channel-update pear.php.net line.
What I’m trying to accomplish is to add a debugger to the Eclipse for PHP Developers IDE on my OS-X v10.6.4 machine…
Try to use sudo before the command, the OSX admin password will be request.
Had the same problem. Using sudo does not resolve. I found this thread that helped me: http://forum.mamp.info/viewtopic.php?f=2&t=8465
You’ll also need to setup the components.ez.no channel:
/Applications/MAMP/bin/php5/bin/pear channel-discover components.ez.no
Not sure when this became required, but phpunit wouldn’t install for me until I ran that command.
David O is right. You’ll need to run this
/Applications/MAMP/bin/php5/bin/pear channel-discover components.ez.no
before you run the install. Otherwise when you try and move phpunit you’ll find that it’s not there. It works fine if you go back and reinstall though
i found that i needed to symlink php5.3 to php5 for updates to work.
ln -s /Applications/MAMP/bin/php5.3 /Applications/MAMP/bin/php5
and then instead of moving phpunit.. ln -s /Applications/MAMP/bin/php5/bin/phpunit /usr/local/bin/phpunit
I’m having issues with this. Can you help, please? When I run phpunit –version, I get the following returned:
-bash: /Applications/MAMP/bin/php5.3/bin/phpunit: /Applications/MAMP/bin/php5/bin/php: bad interpreter: No such file or directory
I’ve tried creating the symbolic link from above, ln -s /Applications/MAMP/bin/php5.3 /Applications/MAMP/bin/php5, with no luck. Any help would be appreciated. Thanks, PDB
I discovered a resolution:
Open the /Applications/MAMP/bin/php5.3/bin/phpunit in a text editor and change references to php5 to php5.3. This did the trick.
I know this was a long time ago, but do you remember if you did anything else to solve this? my phpunit file has the correct directories, but is still giving me the error.
Thanks in advance
Pingback: Teleogistic / Setting up PHPUnit with MAMP
Nice step through, i had a slight issue with a dodgy config file for pear, see http://forum.mamp.info/viewtopic.php?t=13815 for more details if youre experiencing errors such as:
Notice: unserialize(): Error at offset 276 of 1133 bytes in Config.php on line 1050
ERROR: The default config file is not a valid config file or is corrupted.
Cheers!
The following can resolve this poster’s issue. Delete the pear.conf file and reinstall
http://stackoverflow.com/questions/8375327/mamp-how-to-upgrade-pear
As of this comment, the following path should be used:
/Applications/MAMP/bin/php/php5.3.6/bin/pear
Thanks for this, the PHP path is slightly different depending on your version of MAMP and which PHP version you are running but all in all great and working thanks!
For my installation this line was incorrect:
/Applications/MAMP/bin/php/php5.4.4/bin/pear channel-discover pear.symfony.com/Yaml
When trying to install it required another channel, with the correct command being:
/Applications/MAMP/bin/php/php5.4.4/bin/pear channel-discover pear.symfony.com
Error:
Tyler$ /Applications/MAMP/bin/php/php5.4.4/bin/pear channel-discover pear.symfony.com/Yaml
Discovering channel pear.symfony.com/Yaml over http:// failed with message: channel-add: Cannot open “http://pear.symfony.com/Yaml/channel.xml” (File http://pear.symfony.com:80/Yaml/channel.xml not valid (received: HTTP/1.1 403 Forbidden))
Trying to discover channel pear.symfony.com/Yaml over https:// instead
Discovery of channel “pear.symfony.com/Yaml” failed (channel-add: Cannot open “https://pear.symfony.com/Yaml/channel.xml” (Connection to `pear.symfony.com:443′ failed: Connection refused))
You only need to use the top level domain: pear.symfony.com
pear channel-discover pear.symfony.com
Hi,
thank you… very usefull for ur explanation
works evereything….
Thanks – this worked great for me.
I had installed PhpUnit following other steps (trying to use Kenjis phpunit for CodeIgniter (http://d.hatena.ne.jp/Kenji_s/20120117/1326763908)), but realized I wanted to easily connect and test against a MAMP’s database, at least when working locally.
Note: Because I now have both phpUnits installed, I aliased this one to ‘mamp_phpunit’:
ln -s /Applications/MAMP/bin/php/php5.4.4/bin/phpunit ~/bin/mamp_phpunit
Don’t MOVE phpunit to your path, instead add the MAMP bin dir to your PATH. That will work far nicer than moving binaries around. something like:
export PATH=/Applications/MAMP/Library/bin/:/Applications/MAMP/bin/php/php5.3.6/bin/:/opt/local/bin:/opt/local/sbin:$PATH
replace php5.3.6 with your bin path.