Home » Php » php – phpunit – wrong path

php – phpunit – wrong path

Posted by: admin July 12, 2020 Leave a comment


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]

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?

How to&Answers:

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


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.

$path = '/opt/local/PEAR';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);


The PEAR channel (pear.phpunit.de) that is used to distribute PHPUnit needs to be registered with the local PEAR environment. Furthermore, component that PHPUnit depends upon are hosted on additional PEAR channels.

pear channel-discover pear.phpunit.de
pear channel-discover components.ez.no
pear channel-discover pear.symfony-project.com

This has to be done only once. Now the PEAR Installer can be used to install packages from the PHPUnit channel:

pear install phpunit/PHPUnit


In Ubuntu, I used

pear config-set auto_discover 1
pear install pear.phpunit.de/PHP_CodeCoverage


For Ubuntu edit this php.ini for CLI:


add /usr/local/lib/php/ to your include line

include_path= "/opt/zend/library/:/var/www/library/:/usr/local/bin/pear/:/usr/local/lib/php/"

Took me a day to figure it out. Bingo.

If this does not work, try this, it will give you a hint where your PHP libs are located.

$ locate PHP_CodeCoverage


as far as I know PEAR installation method comes to his end, this is what’s says about it on the github repository.