Create Custom Side Menus
Frodo's Ghost | PHPUnit Installed on Mac OSX
post-template-default,single,single-post,postid-28,single-format-standard,eltd-core-1.0.1,ajax_fade,page_not_loaded,,borderland - frodosghost-child-ver-1.0.0,borderland-ver-1.2, vertical_menu_with_scroll,smooth_scroll,side_menu_slide_with_content,width_470,paspartu_enabled,paspartu_on_bottom_fixed,wpb-js-composer js-comp-ver-4.4.4,vc_responsive

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.

sudo pear channel-discover

sudo pear channel-discover
sudo pear channel-discover

Run the install::

sudo pear install phpunit/PHPUnit

Command Line

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

sudo nano ~/.bash_profile

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

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

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 ::

; UNIX: "/path1:/path2"
include_path = "php/includes"

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

include_path = "/usr/local/PEAR:php/includes"

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

include_path = ".:/usr/local/PEAR:php/includes"


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.

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

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:

php --ini

This will result in something like ::
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)

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

Command Not Found

phpunit: command not found
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.

sudo pear install --force --alldeps phpunit/PHPUnit


PHPUnit 3.5.13 by Sebastian Bergmann.


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.


    Very helpful! thanks

    May 4, 2011 at 7:54 pm

    You just saved my day! thanks

    June 11, 2011 at 6:49 pm

    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 at 11:54 am
  • 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 at 12:44 pm

Post a Comment