PHP_CodeCoverage_Filter::getInstance() Error running phpunit

爱⌒轻易说出口 提交于 2020-01-03 16:51:06

问题


I have installed phpunit in my ubuntu 11.10 having php version 5.2.14.

But when I run my test module it is throwing error,

PHP Fatal error:  Call to undefined method PHP_CodeCoverage_Filter::getInstance() in /usr/share/php/PHPUnit/Autoload.php on line 64

I followed the steps mention in this stack question but still no luck.

Call to undefined method PHP_CodeCoverage_Filter::getInstance()


回答1:


Following steps solved my problem.

sudo apt-get remove phpunit

sudo pear channel-discover pear.phpunit.de

sudo pear channel-discover pear.symfony.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



回答2:


One workaround - granted, not really a solution - is to bypass PEAR install and use a local copy via Composer install.

Create a file in project root called composer.json:

{
    "require": {
        "phpunit/phpunit" : "3.7.*"
    }
}

Of course, modify the phpunit version to "3.6.*" or similar, if you have such a requirement.

At project root:

# Install composer
$ curl -s https://getcomposer.org/installer | php

# Tell composer to install the dependencies identified in composer.json
$ php composer.phar install

# Now you can invoke the *local* copy of phpunit
$ ./vendor/phpunit/phpunit/composer/bin/phpunit --version

For simplicity, you can can create a symlink to the phpunit executable. Assuming you want the symlink in a directory called tests:

$ ln -s ./vendor/phpunit/phpunit/composer/bin/phpunit ./tests/phpunit

Then you can invoke as (from project root):

$ cd tests
$ ./phpunit --version

Even easier, you can direct Composer to handling the symlinking for you. Add this to your composer.json:

"config": {
    "bin-dir": "tests"
}

Then, as before, you can invoke as (from project root):

$ cd tests
$ ./phpunit --version

Actually, what I usually do is have a project-level directory called scripts and point my composer bin-dir there. Then I manually create a symlink in tests pointing to scripts/phpunit. But this last step is probably more personal taste than any kind of requirement.

Maybe a long way to go just to beat PEAR issues, but I find Composer-based install works pretty reliably for me.




回答3:


my platform Symfony 1.4 did not have installed the latest version of the plugin that is compatible with latest phpunit version. So updating to latest version of https://github.com/JWT-OSS/sfJwtPhpUnitPlugin/ worked for me.



来源:https://stackoverflow.com/questions/14028200/php-codecoverage-filtergetinstance-error-running-phpunit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!