php phpunit require_once() 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1528717/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 02:57:33  来源:igfitidea点击:

phpunit require_once() error

phpinstallationphpunitfilepathphp-ini

提问by user185305

I recently installed phpunit on my server via the pear installer.

我最近通过 pear 安装程序在我的服务器上安装了 phpunit。

When I go to run a test I get the following error:

当我去运行测试时,我收到以下错误:

PHP Warning: require_once(PHPUnit/Util/Filter.php): failed to open stream: No such file or directory in /usr/bin/phpunit on line 44

PHP Fatal error: require_once(): Failed opening required 'PHPUnit/Util/Filter.php' (include_path='.:/usr/bin/php') in /usr/bin/phpunit on line 44

PHP 警告:require_once(PHPUnit/Util/Filter.php):无法打开流:第 44 行的 /usr/bin/phpunit 中没有这样的文件或目录

PHP 致命错误:require_once():在第 44 行的 /usr/bin/phpunit 中打开所需的“PHPUnit/Util/Filter.php”(include_path='.:/usr/bin/php')失败

After doing some searching, I tried making some modifications to the include_path in my php.ini file on the server. But that hasn't done a thing.

在做了一些搜索之后,我尝试对服务器上的 php.ini 文件中的 include_path 进行一些修改。但这并没有起到任何作用。

Any idea what might be causing this?

知道是什么原因造成的吗?

回答by arunas_t

UPDATE: As of 2013 November and Ubuntu 12.04 these 2 commands should suffice:

更新:截至 2013 年 11 月和 Ubuntu 12.04,这两个命令应该足够了:

sudo pear config-set auto_discover 1
sudo pear install pear.phpunit.de/PHPUnit

The following is an older answer. It's a known problem , although almost a year and a half had passed. Read about it here

以下是较旧的答案。这是一个已知的问题,尽管已经过去了将近一年半。在这里阅读

The code coverage must be installed in order for phpunit to work properly

必须安装代码覆盖率才能使 phpunit 正常工作

What you need to do is covered here:

您需要做的包括在此处:

code coverage installation through PEAR

通过 PEAR 安装代码覆盖率

Basically you have to type (with sudo if you don't have permissions, taken that phpunit is already installed):

基本上你必须输入(如果你没有权限,请使用 sudo,假设 phpunit 已经安装):

pear channel-discover pear.phpunit.de
pear channel-discover components.ez.no
pear install phpunit/PHP_CodeCoverage

回答by Steven Green

I had this problem on OS X. Fixed it with the following commands which force all the php dependencies to be reinstalled, which included a couple of packages from other channels that were not already configured:

我在 OS X 上遇到了这个问题。使用以下命令修复了它,这些命令强制重新安装所有 php 依赖项,其中包括来自其他渠道的几个尚未配置的包:

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

回答by jspeshu

https://bugs.launchpad.net/ubuntu/+source/phpunit/+bug/701544

https://bugs.launchpad.net/ubuntu/+source/phpunit/+bug/701544

and specially this comment for ubuntu 11.04 and may be for some others too

特别是针对 ubuntu 11.04 的评论,也可能适用于其他一些评论

even though i did ths steps as recommended above, i didn't get it to work but after i upgraded pear from 1.9.1 to 1.9.2 it's working perfectly just do this

尽管我按照上面的建议做了这些步骤,但我没有让它工作,但是在我将 pear 从 1.9.1 升级到 1.9.2 之后,它运行得很好,只是这样做

speshu@speshu-laptop:~$ sudo pear upgrade pear

speshu@speshu-laptop:~$ sudo pear 升级梨

   downloading PEAR-1.9.2.tgz ...
   Starting to download PEAR-1.9.2.tgz (295,120 bytes)
    .....................................................done: 295,120 bytes
    upgrade ok: channel://pear.php.net/PEAR-1.9.2
    PEAR: Optional feature webinstaller available (PEAR's web-based installer)
    PEAR: Optional feature gtkinstaller available (PEAR's PHP-GTK-based installer)
    PEAR: Optional feature gtk2installer available (PEAR's PHP-GTK2-based installer)
    PEAR: To install optional features use "pear install pear/PEAR#featurename"

回答by jeroen

If it is the first time you are using PEAR, perhaps you have not configured the include path right. Take a look at the appropriate section in the PEAR manual.

如果是第一次使用PEAR,可能是你没有正确配置include路径。查看PEAR 手册中的相应部分

回答by stanleyhlng

https://github.com/sebastianbergmann/php-code-coverage

https://github.com/sebastianbergmann/php-code-coverage

sb@ubuntu ~ % pear channel-discover pear.phpunit.de
Adding Channel "pear.phpunit.de" succeeded
Discovery of channel "pear.phpunit.de" succeeded

sb@ubuntu ~ % pear channel-discover components.ez.no
Adding Channel "components.ez.no" succeeded
Discovery of channel "components.ez.no" succeeded

sb@vmware ~ % pear install phpunit/PHP_CodeCoverage
downloading PHP_CodeCoverage-0.9.0.tgz ...
Starting to download PHP_CodeCoverage-0.9.0.tgz (108,376 bytes)
.........................done: 108,376 bytes
install ok: channel://pear.phpunit.de/PHP_CodeCoverage-0.9.0

回答by meder omuraliev

(include_path='.:/usr/bin/php')

(include_path='.:/usr/bin/php')

Are you sureyou added it to the include_path?

确定将其添加到 include_path 中吗?

It might also help if we saw your ini file, and the include_path snippet in it...

如果我们看到您的 ini 文件以及其中的 include_path 片段,这也可能有所帮助...

回答by user185305

I found it!

我找到了!

Looks like PEAR installed PHPUnit in /usr/share/pear. Not sure why but that's where it is. Must be a (mt) thing.

看起来 PEAR 在 /usr/share/pear 中安装了 PHPUnit。不知道为什么,但这就是它的位置。一定是(山)的东西。

Anyway, I'm all set. Thanks for the help.

不管怎样,我都准备好了。谢谢您的帮助。

回答by Josh Koenig

This is also what happens if you have an out-of-date or incomplete PHPUnit install. Please be aware that after you set up PEAR, you must add the PHPUnit.de channelin order to get an up-to-date package.

如果您的 PHPUnit 安装过时或不完整,也会发生这种情况。请注意,在设置 PEAR 后,您必须添加PHPUnit.de 频道才能获得最新的包。

回答by Marcelo

In my case, I solved it by adding /usr/share/php/PEARto the include_path.

就我而言,我通过添加/usr/share/php/PEARinclude_path.

I'm using Ubuntu 10.04.2.

我正在使用 Ubuntu 10.04.2。

回答by denz

If you have problems with accessing components try another way.

如果您在访问组件时遇到问题,请尝试另一种方式。

  1. Install pear

    sudo apt-get install php-pear
    
  2. Install phpunitby using pear.

    pear config-set auto_discover 1
    pear install pear.phpunit.de/PHPUnit
    
  3. Install phpunit/Selenium, but first you need to install curlmodule

    sudo apt-get install php5-curl 
    pear install phpunit/PHPUnit_Selenium
    
  1. 安装梨

    sudo apt-get install php-pear
    
  2. phpunit使用梨安装。

    pear config-set auto_discover 1
    pear install pear.phpunit.de/PHPUnit
    
  3. 安装phpunit/Selenium,但首先你需要安装curl模块

    sudo apt-get install php5-curl 
    pear install phpunit/PHPUnit_Selenium