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.
Discover the channels for the pear install to run. The main channel and it also requires files from other repositories.
sudo pear channel-discover pear.phpunit.de
sudo pear channel-discover pear.symfony-project.com
sudo pear channel-discover components.ez.no
Run the install::
sudo pear install phpunit/PHPUnit
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.
This is telling the command line, when a command is called, it will look for the function to run in one of the directories.
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:
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.