Installing PHPUnit on OS X using MAMP via PEAR

Here is a quick and solid way to add PHPUnit to your MAMP Setup

Important:

The path to your PHP and PEAR if you are using MAMP is something similar to this

PHP:

/Applications/MAMP/bin/php/php5.xxx/bin/php

PEAR:

/Applications/MAMP/bin/php/php5.xxx/bin/pear

notice the php5.xxx this will depend on the version of php you are using, in my case is php5.3.6 so have that in mind if you are planning on copy pasting this guide

Instructions:

  1. Turn on PEAR auto discover
    /Applications/MAMP/bin/php/php5.3.6/bin/pear config-set auto_discover 1

    As Alex from the comments states you might need to update pear
    cd /Applications/MAMP/bin/php/php5.3.6/bin
    sudo ./pear upgrade pear

  2. Install PHPUnit from pear.phpunit.de
    /Applications/MAMP/bin/php/php5.3.6/bin/pear install pear.phpunit.de/PHPUnitThis will install PHPUnit under
    /Applications/MAMP/bin/php/php5.3.6/bin/phpunit
  3. If done right the phpunit file should already contain reference to the MAMP’s php you are choosing to use, now to have phpunit available on your system as a command you can do something similar to this:
    sudo ln -s /Applications/MAMP/bin/php/php5.3.6/bin/phpunit /usr/local/bin/phpunit

I always try to keep my binaries and executables under /usr/local/bin but this is my choice you can try some other directory as long as you have it exposed on via your EXPORTS

  • http://ciobi.ca Alex

    If you installation of PHPUnit doesn’t work it is most likely because pear is out of date.

    Just run:

    cd /Applications/MAMP/bin/php/php5.3.6/bin
    sudo ./pear upgrade pear

    before step 1 of the instructions to be safe.

    This was my case under Lion with MAMP PRO 2.0.5 installed.

  • admin

    Thanks Alex, I’ll update

  • Pingback: ew | MAMP PRO Pear Installation

  • Steve

    Kudos to you! Out of all the crazy ass instructions i found, this is by far the most coherent and simple.

    An issue I ran into was when running phpunit it wouldn’t output anything. I actually had to edit the phpunit executable file in /Applications/MAMP/bin/php/php5.4.4/bin and change @php_bin@ to the directory where the phpunit files.

    I just downloaded the zip from the phpunit.de site and put the PHPUnit folder in:

    /Applications/MAMP/bin/php/php5.4.4/lib/php

    Then changed the string in the phpunit exec. to:

    /Applications/MAMP/bin/php/php5.4.4/lib/php/PHPUnit