Friday, October 9, 2009

Manually Installing PHPUnit with MAMP on Snow Leopard (3rd time is a charm)

After scouring the web for awhile and having problems with installing PHPUnit with PEAR and MAMP, I figured it out, so I thought I would share...

1. Get a copy of the latest version of PHPUnit (PHPUnit 3.4.1 - 8 Oct 2009) here ~ http://pear.phpunit.de/get/

2. Extract your folder to your desktop.

3. Edit "phpunit.php" found in "PHPUnit-3.4.1/PHPUnit-3.4.1/".
3.1. Scroll near to the bottom and replace "@php_bin@" with "/Applications/Mamp/bin/php5/bin/php".

3.2. <Save As> "phpunit" (*Notice no extension used.) in "/usr/local/bin/", or save to your Desktop, then copy to "/usr/local/bin/".

[ Side Note: if you want to reveal hidden files and folders in Finder, you may type this in the Terminal:

defaults write com.apple.finder AppleShowAllFiles TRUE

then

killall Finder

to "reboot" finder (Note: this will close all your Finder windows and reopen all of them)
you can use FALSE instead of TRUE to return it back to "normal".

]

3.3. Make the file (phpunit) executable by typing the following in the Terminal:

sudo chmod +x /usr/local/bin/phpunit

4. Edit "PHP.php" found in "PHPUnit-3.4.1/PHPUnit-3.4.1/PHPUnit/Util/".
4.1. Scroll about 3/4 near the bottom and replace "@php_bin@" with "/Applications/Mamp/bin/php5/bin/php".

4.2. Save the file. Copy "PHPUnit-3.4.1/PHPUnit-3.4.1/PHPUnit" folder to "/usr/lib/php/". That's it!

5. Test it out by making a Test anywhere, here is some sample code you can plonk into "HowsitWorldTest.php".

<?php

class HowsitWorldTest extends PHPUnit_Framework_TestCase
{
public function testHowsit()
{
$this->assertTrue(1 == 1);
}
}

?>

6. Open up your Terminal to where your test (HowsitWorldTest.php) is located.

7. Type "phpunit HowsitWorldTest". Hopefully you will see the following:

TM

"It's only work if somebody makes you do it"

Posted via email from TigerMunky's Grrreat Trek

3 comments:

  1. TM, thank you very much for this! :) Got PHPUnit working in MAMP in 5 minutes because of this simple guide.

    ReplyDelete
  2. Thank you! Much simpler to follow than other documents and more recent! :)

    ReplyDelete
  3. Thank you very very very very much.

    ReplyDelete