3
votes

I am migrating to a new computer moving from snow leopard to lion at the same time. phpunit did not seem to make the migration, so I have reinstalled it. However the standard install with pear seems to not work with my home brew install of php. Here is the error:

phpunit
PHP Warning:  require(/usr/lib/php/PHPUnit/Autoload.php): failed to open stream: No such file or directory in /usr/bin/phpunit on line 43

Warning: require(/usr/lib/php/PHPUnit/Autoload.php): failed to open stream: No such file or directory in /usr/bin/phpunit on line 43
PHP Fatal error:  require(): Failed opening required '/usr/lib/php/PHPUnit/Autoload.php' (include_path='.:/Users/bimemployee/pear/share/pear:/usr/lib/php') in /usr/bin/phpunit on line 43

Fatal error: require(): Failed opening required '/usr/lib/php/PHPUnit/Autoload.php' (include_path='.:/Users/bimemployee/pear/share/pear:/usr/lib/php') in /usr/bin/phpunit on line 43

I have my computer setup with my main /etc/php.ini file as a symlink to the home brew php.ini file at /usr/local/etc/php.ini this contains my include path which seems to be working.

php -r 'foreach (explode(":", get_include_path()) as $path) echo $path . PHP_EOL;'
No log handling enabled - turning on stderr logging
Cannot find module (LM-SENSORS-MIB): At line 0 in (none)
.
/Users/bimemployee/pear/share/pear
/usr/lib/php

I am also setting up php to work with the homebrew version via the .bash_profile file.

export PATH="$(brew --prefix)/bin:$PATH"
which php
/usr/local/bin/php
which phpunit
/usr/bin/phpunit

Thanks for any help.

-Cory

3
I am pretty sure this is not the ideal way to fix it for now I symlinked to the directory and that seems to work. - Cory Gwin

3 Answers

6
votes

Maybe you don't have the latest version or the full phpunit installation. You need to install all dependencies using --alldeps So you should install phpunit like this:

pear channel-discover pear.symfony.com # for Yaml dependency
pear channel-discover pear.phpunit.de
pear install --alldeps phpunit/PHPUnit

This work for me ;)

2
votes

The problem you having might be connected with your include_path, actual (real) php lib directory and with brew link command.

Brew installs php lib into Cellar directory and than links (brew link) all existing resources to /usr/local/lib/php (or /usr/lib/php - depending on your installation).

The problem is File.php and File/ appears in Cellar php lib after linking process (probably after pear update/upgrade). That means it will be not linked in /usr/local/lib/php. To fix it you can simply brew unlink and brew link again.

Additionally it would be good to set your pear php_dir to /usr/local/lib/php. This way all new pear modules will be installed in correct destination without linking process. This makes nice separation between custom Pear modules and PHP lib itself.

1
votes

You need to set your php include path in php.ini so that it includes the PEAR directory where PHPUnit lives.

include_path = ".:/Applications/MAMP/bin/php/php5.3.6/lib/php:"

You may need to search for Autoload.php using spotlight to find the right location.