Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call to undefined method PHP_CodeCoverage_Filter::getInstance()

I've got a fresh copy of PHPUnit installed on my system (Ubuntu 11), but whenever I type phpunit in the console I get the following error:

PHP Fatal error: Call to undefined method PHP_CodeCoverage_Filter::getInstance() in /usr/bin/phpunit on line 39

I have PHPUnit's code coverage installed, as far as I know:

>sudo pear install phpunit/PHP_CodeCoverage

phpunit/PHP_CodeCoverage is already installed and is the same as the released version 1.1.1

install failed

Why am I getting this error and how can I fix it?

like image 998
Ian Hunter Avatar asked Feb 08 '12 00:02

Ian Hunter


4 Answers

Ubuntu 11.10 has had an issue for a while that hasn't been fixed. This is the only thing that will get phpunit to work with pear. (Outside of using pear you can look up a way to do it without pear. There is an article online about that but I wouldn't want that kind of burden to do it manually). This is the only thing that worked for me:

sudo apt-get remove phpunit

sudo pear channel-discover pear.phpunit.de

sudo pear channel-discover pear.symfony-project.com

sudo pear channel-discover components.ez.no

sudo pear update-channels

sudo pear upgrade-all

sudo pear install --alldeps phpunit/PHPUnit

sudo pear install --force --alldeps phpunit/PHPUnit
like image 100
Anthony Avatar answered Nov 03 '22 18:11

Anthony


The executable script that loads PHPUnit must not have been updated when going to 3.6.x. Reinstall it.

sudo pear uninstall phpunit/PHPUnit
sudo pear install phpunit/PHPUnit

If this doesn't work, make sure PEAR itself is up-to-date.

like image 39
David Harkness Avatar answered Nov 03 '22 18:11

David Harkness


For some, Anthony's solution will not work fully because of the Unknown remote channel: pear.symfony.com or phpunit/PHPUnit requires package "channel://pear.symfony.com/Yaml".

SO here is the upgraded solution that solves this:

sudo apt-get remove phpunit

sudo pear channel-discover pear.phpunit.de

sudo pear channel-discover pear.symfony-project.com

sudo pear channel-discover components.ez.no

sudo pear channel-discover pear.symfony.com

sudo pear update-channels

sudo pear upgrade-all

sudo pear install pear.symfony.com/Yaml

sudo pear install --alldeps phpunit/PHPUnit

sudo pear install --force --alldeps phpunit/PHPUnit
like image 23
Starx Avatar answered Nov 03 '22 18:11

Starx


The method getInstance() seems to have been dropped from the class. https://github.com/sebastianbergmann/php-code-coverage/blob/master/PHP/CodeCoverage/Filter.php#L78

Use the constructor instead if you come across this error. However, this is not applicable to the opening post as the command came from PHPUnit itself.

like image 1
Tails Avatar answered Nov 03 '22 17:11

Tails