Search
« Extending Prototype for Aborting Ajax Requests | Main | The Production Server has Bad Code, and The Bad Code is Yours »
Monday
Apr182011

PHPUnit Installed on Mac OSX

I think I failed in every possible way setting this up, at least this guide should be exhaustive, it is how I felt making all these changes.

Configure Pear


Discover the channels for the pear install to run. The main channel and it also requires files from other repositories.

[bash]sudo pear channel-discover pear.phpunit.de[/bash]

[bash]sudo pear channel-discover pear.symfony-project.com
sudo pear channel-discover components.ez.no[/bash]

Run the install::

[bash]sudo pear install phpunit/PHPUnit[/bash]

Command Line


Command line needs a reference on where to look when the command phpunit is called. This is configured in the .bash_profile:

[bash]sudo nano ~/.bash_profile[/bash]

Add the line below, save and exit. Quit Terminal and reopen the window again.

[bash]export PATH=/usr/local/bin:$PATH[/bash]

This is telling the command line, when a command is called, it will look for the function to run in one of the directories.

Include Path


Finally, you will need to update the include_path in your php.ini file. I have seen some tutorials where a symbolic link is used to fake-configure the include path. This is not a great idea, because all the require_once calls in the Pear library need to reference the include files.

It is best to update the php.ini file - once change configures everything. Look in the php.ini file to find the lines ::

[bash]; UNIX: "/path1:/path2"
include_path = "php/includes"[/bash]

And add the directory which points to your PEAR library ::

[bash]include_path = "/usr/local/PEAR:php/includes"[/bash]

You may need to include a .: at the start, like this ::

[bash]include_path = ".:/usr/local/PEAR:php/includes"[/bash]

Caution


Watch out here. If you are like me, and for some stupid reason you have XAMPP running on a Mac, there is a fair chance that you will have more than one php.ini file. This causes confusion and delay.

[bash]PHP Warning: require_once(PHP/CodeCoverage/Filter.php): failed to open stream: No such file or directory in /usr/local/bin/phpunit on line 38
PHP Fatal error: require_once(): Failed opening required 'PHP/CodeCoverage/Filter.php' (include_path='php/includes') in /usr/local/bin/phpunit on line 38[/bash]

If you get an error like this, it is saying that the function 'phpunit' cannot find the correct file to require. This caused me hours of trouble.

To find which php.ini the computer is running the include_path from just type:

[bash]php --ini[/bash]

This will result in something like ::
[bash]Configuration File (php.ini) Path: /etc
Loaded Configuration File: /private/etc/php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed: (none)[/bash]

Edit this php.ini and it should correct the require_once functions.

Command Not Found


[bash]phpunit: command not found[/bash]
phpunit needs to be in a bin folder to run on the command line. This usually happens on pear install of phpunit, but if you're a numpty, like me, who has deleted it then the best way to correct it is force an install.

[bash]sudo pear install --force --alldeps phpunit/PHPUnit[/bash]

~End


[bash]PHPUnit 3.5.13 by Sebastian Bergmann.[/bash]

Bonus


For those playing at home... You will notice I am using 'nano' as the editor ~ Not hardcore enough to use vim yet. The commands below are for my future reference, so feel free to ignore them.

ctrl + w = Search the file. So hit the keys and type ;include_path in the ini file.
ctrl + x = Save and Quit.

Reader Comments (4)

Very helpful! thanks

May 5, 2011 | Unregistered CommenterAmrita

You just saved my day! thanks

June 12, 2011 | Unregistered CommenterKevin

Hi...
I have this error at the "Caution" part you mentioned above...

but I don't understand...what do you mean by
"Edit this php.ini and it should correct the require_once functions."

How to edit the php.ini...and which part I should edit?

Thanks in advanced!!

July 20, 2011 | Unregistered CommenterAnne

Hi Anne,
When you run the php --ini on the command line it will display the few lines that include "Loaded Configuration File".

If you edit the include_path with the PEAR package in that specified php.ini it will correctly include the files when it calls the require_once.

Let me know if I didn't explain it.
- james

July 20, 2011 | Unregistered CommenterJames

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>