运行PHPUnit时出错 [英] Error when running PHPUnit
问题描述
当我尝试从项目的测试文件夹中运行phpunit .
时,出现以下错误:
I get the following error when I try to run phpunit .
from within my project's tests folder:
PHP Fatal error: Call to undefined method PHP_CodeCoverage_Filter::getInstance() in /usr/share/php/PHPUnit/Framework.php on line 46
我通过以下命令安装了PHPUnit:
I installed PHPUnit via these commands:
sudo pear channel-discover pear.symfony-project.com
sudo pear channel-discover components.ez.no
sudo pear install --alldeps phpunit/PHPUnit
其他方法似乎都不起作用,包括apt-get
.
As none of the other methods seem to work, including apt-get
.
我认为 CodeCoverage在某个时间点更改了其单例模式,因此删除了getInstance
,但是我不知道如何解决此错误.如何降级CodeCoverage或升级PHPUnit?
I think CodeCoverage changed their singleton pattern at some point in time and hence removed getInstance
but I don't know how to fix this error. How can I either downgrade CodeCoverage or upgrade PHPUnit?
我尝试通过以下命令手动安装所有组件的最新版本:
I tried manually installing the latest versions of everything via the following commands:
sudo apt-get install git
mkdir phpunit && cd phpunit
git clone git://github.com/sebastianbergmann/phpunit.git
git clone git://github.com/sebastianbergmann/dbunit.git
git clone git://github.com/sebastianbergmann/php-file-iterator.git
git clone git://github.com/sebastianbergmann/php-text-template.git
git clone git://github.com/sebastianbergmann/php-code-coverage.git
git clone git://github.com/sebastianbergmann/php-token-stream.git
git clone git://github.com/sebastianbergmann/php-timer.git
git clone git://github.com/sebastianbergmann/phpunit-mock-objects.git
git clone git://github.com/sebastianbergmann/phpunit-selenium.git
git clone git://github.com/sebastianbergmann/phpunit-story.git
git clone git://github.com/sebastianbergmann/php-invoker.git
sudo cp -r dbunit/PHPUnit /usr/share/php/
sudo cp -r php-code-coverage/PHP /usr/share/php/
sudo cp -r php-file-iterator/File /usr/share/php/
sudo cp -r php-invoker/PHP /usr/share/php/
sudo cp -r php-text-template/Text /usr/share/php/
sudo cp -r php-timer/PHP /usr/share/php/
sudo cp -r php-token-stream/PHP /usr/share/php/
sudo cp -r phpunit/PHPUnit /usr/share/php/
sudo cp -r phpunit-mock-objects/PHPUnit /usr/share/php/
sudo cp -r phpunit-selenium/PHPUnit /usr/share/php/
sudo cp -r phpunit-story/PHPUnit /usr/share/php/
sudo cp -r phpunit/phpunit.php /usr/share/php/
但是那没有帮助.现在我到处都是一堆垃圾:\
But that didn't help any. Now I just have a bunch of junk all over the place :\
版本信息:
PEAR Version: 1.9.4
PHP Version: 5.3.6-13ubuntu3.3
Zend Engine Version: 2.3.0
PHPUnit 3.6.9 by Sebastian Bergmann.
Installed packages, channel pear.phpunit.de:
============================================
Package Version State
File_Iterator 1.3.1 stable
PHPUnit 3.6.9 stable
PHPUnit_MockObject 1.1.1 stable
PHP_CodeCoverage 1.1.1 stable
PHP_Invoker 1.1.0 stable
PHP_Timer 1.0.2 stable
PHP_TokenStream 1.1.2 stable
Text_Template 1.1.1 stable
推荐答案
您可以尝试一下,我已经在Ubuntu 12.04上完成了
you can try this, I have done it on my Ubuntu 12.04
- sudo pear卸载phpunit/PHPUnit
- sudo pear卸载pear.phpunit.de/PHPUnit_MockObject
- sudo pear安装pear.phpunit.de/PHPUnit_MockObject
- sudo pear install --alldeps pear.phpunit.de/PHPUnit
我尝试了许多其他方法.当我收到错误提示时,此方法有效.
I have tried many other methods. This works when I get the error blow.
hegaofeng @ ubuntu:〜$ phpunit PHP警告:require_once(PHPUnit/Framework/MockObject/Autoload.php):无法打开>?> stream:第48行的/usr/share/php/PHPUnit/Autoload.php中没有此类文件或目录 PHP致命错误:require_once():无法在/usr/share中打开所需的>'PHPUnit/Framework/MockObject/Autoload.php'>(include_path ='.:/usr/share/php:/usr/share/pear') >第48行上的/php/PHPUnit/Autoload.php hegaofeng @ ubuntu:〜$ cd/usr/share/php/
hegaofeng@ubuntu:~$ phpunit PHP Warning: require_once(PHPUnit/Framework/MockObject/Autoload.php): failed to open >?>stream: No such file or directory in /usr/share/php/PHPUnit/Autoload.php on line 48 PHP Fatal error: require_once(): Failed opening required >'PHPUnit/Framework/MockObject/Autoload.php' >(include_path='.:/usr/share/php:/usr/share/pear') in /usr/share/php/PHPUnit/Autoload.php on >line 48 hegaofeng@ubuntu:~$ cd /usr/share/php/
这篇关于运行PHPUnit时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!