“Fatal error: Call to undefined method PHPUnit_Uti

2019-03-03 14:41发布

问题:

I have just installed phpunit using PEAR on our Ubuntu/Linux server ( Linux mccoy 2.6.28-11-server #42-Ubuntu SMP Fri Apr 17 02:45:36 UTC 2009 x86_64 GNU/Linux )

when I try to run a unit test I get the error:

"Fatal error: Call to undefined method PHPUnit_Util_Filter::addfiletofilter() in /usr/bin/phpunit on line 48"

I have googled this and came across a few threads on it however none of these seem to fix my issue.

I have added the following line to my

/etc/php5/cli/php.ini:

include_path = ".:/usr/share/php/PHPUnit"

(I've also tried it without the "/PHPUnit" folder included)

But I still get this error.

Any help would be greatly appreciated

gvanto

edit: this is what is in start of file /user/bin/phpunit:

// ...just comments prior to this

 if (extension_loaded('xdebug')) {
     xdebug_disable(); }

 if (strpos('/usr/bin/php', '@php_bin') === 0) {
     set_include_path(dirname(__FILE__) . PATH_SEPARATOR . get_include_path()); }

 require_once 'PHPUnit/Util/Filter.php';

 PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); //line 48

 require 'PHPUnit/TextUI/Command.php';

 define('PHPUnit_MAIN_METHOD', 'PHPUnit_TextUI_Command::main');

回答1:

Seems like a version conflict / installation issue.

pear version should produce 1.9.4.. If not pear upgrade and follow the commands until it does.

Then sudo pear install --force --alldeps phpunit/phpunit to fix the installation.+

Your include path should include the "pear" dir. Use pear config-show to find that.