Phpunit – wrong path

pathPHPphpunitterminalzend-framework

Does anybody know what I'm doing wrong?
I've installed phpunit, and everything is fine when I'm in the /opt/local/PEAR directory, so if I go to /opt/local/PEAR directory and run phpunit I get:

PHPUnit 3.5.11 by Sebastian Bergmann.
Usage: phpunit [switches] UnitTest [UnitTest.php]
phpunit [switches]
blablabla

but if I am on some other path I get:

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

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

I know that is something wrong with my PATH. How can I fix it?

Best Answer

Try adding /opt/local/PEAR to your php.ini file include_path.

//Before:
include_path='.:/usr/lib/php'
//After:
include_path='.:/usr/lib/php:/opt/local/PEAR'

You may also need to restart your web server afterwards for the changes to take effect.

And as RobertPitt comments, this can also be done at runtime without access to the php.ini file.

<?php
$path = '/opt/local/PEAR';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
?>