简体   繁体   English

运行 PHPUnit 时出错

[英]Error when running PHPUnit

I get the following error when I try to run phpunit .当我尝试运行phpunit .时出现以下错误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

I installed PHPUnit via these commands:我通过以下命令安装了 PHPUnit:

sudo pear channel-discover pear.symfony-project.com
sudo pear channel-discover components.ez.no
sudo pear install --alldeps phpunit/PHPUnit

As none of the other methods seem to work, including apt-get .由于其他方法似乎都不起作用,包括apt-get

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.认为CodeCoverage 在某个时间点改变了他们的单例模式,因此删除了getInstance但我不知道如何解决这个错误。 How can I either downgrade CodeCoverage or upgrade PHPUnit?如何降级 CodeCoverage 或升级 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 :\\现在我到处都是一堆垃圾:\\


Version info:版本信息:

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

you can try this, I have done it on my Ubuntu 12.04你可以试试这个,我已经在我的 Ubuntu 12.04 上完成了

  1. sudo pear uninstall phpunit/PHPUnit sudo pear 卸载 phpunit/PHPUnit
  2. sudo pear uninstall pear.phpunit.de/PHPUnit_MockObject sudo pear 卸载 pear.phpunit.de/PHPUnit_MockObject
  3. sudo pear install pear.phpunit.de/PHPUnit_MockObject须藤梨安装 pear.phpunit.de/PHPUnit_MockObject
  4. sudo pear install --alldeps pear.phpunit.de/PHPUnit须藤梨安装 --alldeps pear.phpunit.de/PHPUnit

I have tried many other methods.我尝试了许多其他方法。 This works when I get the error blow.当我收到错误消息时,这会起作用。

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/ 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第 48 行 PHP 致命错误:require_once(): 需要打开失败 >'PHPUnit/Framework/MockObject/Autoload.php' >(include_path='.:/usr/share/php:/usr/share/pear') 在 /usr /share/php/PHPUnit/Autoload.php >line 48 hegaofeng@ubuntu:~$ cd /usr/share/php/

I've had issues when not using the actual pear.phpunit.de channel to install PHPUnit, especially when trying to use a package manager like apt-get or yum.我在不使用实际的pear.phpunit.de通道安装 PHPUnit 时遇到了问题,尤其是在尝试使用 apt-get 或 yum 等包管理器时。 Try removing all the manually installed stuff you pulled from the git repository and do a pear uninstall of PHPUnit and its optional dependencies.尝试删除您从 git 存储库中提取的所有手动安装的内容,并对 PHPUnit 及其可选依赖项进行pear uninstall Then:然后:

  • sudo pear upgrade PEAR须藤梨升级梨
  • sudo pear config-set auto_discover 1须藤梨配置集 auto_discover 1
  • sudo pear install --alldeps pear.phpunit.de/PHPUnit须藤梨安装 --alldeps pear.phpunit.de/PHPUnit

This has worked for me ... hope it helps.这对我有用......希望它有帮助。


UPDATE更新

It probably goes without saying, but you should also purge your previous apt-get attempts as well before following the steps above:这可能不言而喻,但在执行上述步骤之前,您还应该清除之前的 apt-get 尝试:

  • sudo apt-get purge php5-pear sudo apt-get 清除 php5-pear

Manual Installation for Ubuntu 11.10 Ubuntu 11.10 手动安装

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
cd phpunit && git checkout 3.6 && cd ..
cd dbunit && git checkout 1.1 && cd ..
cd php-code-coverage && git checkout 1.1 && cd ..
cd phpunit-mock-objects && git checkout 1.1 && cd ..
cd phpunit-selenium && git checkout 1.1 && cd ..
sudo mv ./* /usr/share/php/
ln -s /usr/share/php/phpunit/phpunit.php ~/bin/phpunit
gksudo gedit /etc/php5/cli/php.ini

Add the following to your include_path :将以下内容添加到您的include_path

/usr/share/php/dbunit:/usr/share/php/php-code-coverage:/usr/share/php/php-file-iterator:/usr/share/php/php-text-template:/usr/share/php/php-timer:/usr/share/php/php-token-stream:/usr/share/php/phpunit:/usr/share/php/phpunit-mock-objects:/usr/share/php/phpunit-selenium:/usr/share/php/phpunit-story:/usr/share/php/php-invoker

Open /usr/share/php/PHPUnit/Framework.php and you will see this:打开/usr/share/php/PHPUnit/Framework.php ,你会看到:

trigger_error(
    'Please no longer include "PHPUnit/Framework.php".', E_USER_NOTICE
);

That's all!就这样! Please no longer include "PHPUnit/Framework.php"!!!请不要再包含“PHPUnit/Framework.php”!!!

Before installing PHPUnit on your system, clear pear's cache在你的系统上安装 PHPUnit 之前,清除 pear 的缓存

pear clear-cache

From what i have seen, maybe you haven't integrated PHPUnit with your project.据我所见,也许您还没有将 PHPUnit 与您的项目集成。 You don't need to only install PHPUnit using PEAR, i believe the files you need are not in the project.您不需要只使用 PEAR 安装 PHPUnit,我相信您需要的文件不在项目中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM