Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting up PHPUnit on OSX

Though I'm sure others have eventually managed to figure this out, I've been following the various documentation out there and have been having a heck of a rough time of it.

http://www.phpunit.de/manual/current/en/installation.html

Makes it sound pretty easy. However depending on your setup, you might be going down a rabbit hole.

PEAR for example must be of a version higher than 1.8.1. I had 1.8.0 at the time, so I went to find out how to update PEAR

PEAR upgrade-all

Gives an error. No access.

sudo PEAR upgrade-all

Works, but upgrades the PEAR install owned by the user 'sudo' (and not your primary account... or something like that, short version is 5that it plain don't work)

cd ~
pico .bash_profile

add

export PATH=/usr/local/bin:$PATH

give you the correct PEAR when you type PEAR, you're finally ready for step 1 of the install PHPUnit instructions.

pear channel-discover pear.phpunit.de

Error. You don't have access to /usr/local/temp

sudo chmod 777 /usr/local/temp

Error. You don't have access to /usr/local/temp/channel.xml

sudo chmod 777 /usr/local/temp/channel.xml
pear channel-discover pear.phpunit.de

Error.

Registry directory is not writeable by the current user

BUT I'M ON A MAC!

/sigh
/facepalm
/tears

I've actually got a "working copy" of phpunit on my machine. (YAY!) the odd problem is that it only works when I type phpunit from one specific folder

cd /usr/local/PEAR
phpunit

^^ WORKS

cd ~
phpunit

^^ Returns

Warning: require_once(PHPUnit/Util/Filter.php): failed to open stream: No such file or directory in /usr/local/bin/phpunit on line 46

Fatal error: require_once(): Failed opening required 'PHPUnit/Util/Filter.php' (include_path='.:/usr/lib/php') in /usr/local/bin/phpunit on line 46

So close yet so far... I'm wondering if anyone has some input on getting this guy working right?

like image 821
Alex C Avatar asked Jul 21 '10 16:07

Alex C


3 Answers

To install via terminal:

curl https://phar.phpunit.de/phpunit.phar -L -o phpunit.phar

chmod +x phpunit.phar

mv phpunit.phar /usr/local/bin/phpunit
like image 196
Andy Avatar answered Nov 12 '22 05:11

Andy


We can install it using Homebrew

$ brew install phpunit
like image 44
Mike Nguyen Avatar answered Nov 12 '22 05:11

Mike Nguyen


Via homebrew (only if you've installed php via homebrew as well):

brew tap josegonzalez/php
brew install phpunit
like image 16
Nathan Kot Avatar answered Nov 12 '22 07:11

Nathan Kot