运行 phpunit 时找不到致命错误“文件/迭代器/Autoload.php”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8700642/
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-26 05:18:36  来源:igfitidea点击:

fatal error 'File/Iterator/Autoload.php' not found when running phpunit

phpunit-testingphpunit

提问by pearlsoft

I am getting this error while i tried to run testclass in phpunit.

当我尝试在 phpunit 中运行 testclass 时出现此错误。

C:\xampp\htdocs\unittest>phpunit UnitTest usertest.php
PHP Warning:  require_once(File/Iterator/Autoload.php): failed to open stream No such file or directory in C:\xampp\php\pear\PHPUnit\Autoload.php on line 45
PHP Stack trace:
PHP   1. {main}() C:\xampp\php\phpunit:0
PHP   2. require() C:\xampp\php\phpunit:41

Warning: require_once(File/Iterator/Autoload.php): failed to open stream: No such file or directory in C:\xampp\php\pear\PHPUnit\Autoload.php on line 45

Call Stack:
    0.0004     325352   1. {main}() C:\xampp\php\phpunit:0
    0.0026     366520   2. require('C:\xampp\php\pear\PHPUnit\Autoload.php')xampp\php\phpunit:41

PHP Fatal error:  require_once(): Failed opening required 'File/Iterator/Autoload.php' (include_path='.;C:\php\pear') in C:\xampp\php\pear\PHPUnit\Autoload.php on line 45
PHP Stack trace:
PHP   1. {main}() C:\xampp\php\phpunit:0'

could anyone give solution to this ??

谁能解决这个问题??

Note: i am using windows 7.

注意:我使用的是 Windows 7。

Thanks,

谢谢,

回答by Syntaqx

A possible reason that this might happen is that your php include_path is not set correctly. Please make sure you have the appropriate path to PEAR available. For my WAMP installation it would be:

可能发生这种情况的一个可能原因是您的 php include_path 设置不正确。请确保您有适当的 PEAR 路径可用。对于我的 WAMP 安装,它将是:

include_path=".;C:\wamp\bin\php\php5.3.8\PEAR\PEAR"

However, it will most likely be different on your system.

但是,它很可能在您的系统上有所不同。

A side note, you will want to update both your apache php.ini, as well as your php.ini located in your PHP installation folder. CLI the default php.ini, and web requests (and often times other software that you might be using PEAR packages for) will use the apache php.ini.

附带说明,您需要更新 apache php.ini 以及位于 PHP 安装文件夹中的 php.ini。CLI 使用默认的 php.ini,而 Web 请求(通常还有您可能使用 PEAR 包的其他软件)将使用 apache php.ini。

Hope this helps.

希望这可以帮助。

回答by edorian

Your phpunit installation is broken. The easiest fix for this is

您的 phpunit 安装已损坏。最简单的解决方法是

pear install --force --alldeps phpunit/phpunit

and see if what worked out.

看看是否成功。

You will need the most current pear version 1.9.4. If you don't have that version install it using the go-pear.phar. If you are running from xammp for something don't try to fix the pear installation they ship. Usually it's a LOT easier to reinstall it.

您将需要最新的梨形版本1.9.4。如果您没有该版本,请使用go-pear.phar. 如果您正在从 xammp 运行某些东西,请不要尝试修复他们提供的梨安装。通常重新安装它要容易得多。

If you want to you can try to just install the missing package too:

如果你愿意,你也可以尝试只安装缺少的包:

pear install phpunit/File_Iterator

(add a --forceif pear tells you that it is already installed)

(加一个--forceif梨告诉你已经安装好了)

回答by d g

Checking pear config helped me find this quicky:

检查梨配置帮助我快速找到了这个:

bash-3.2# pear config-show | grep php_dir
PEAR directory                 php_dir          /usr/local/pear/share/pear

bash-3.2# vi /etc/php.ini
include_path = ".:/php/includes:/usr/local/pear/share/pear"

回答by Teo

After 2 days of post reading, finally i've solved with guides:

经过 2 天的阅读后,我终于用指南解决了:

Clean pc by hold/corrupted installation of Phpunit LINK

通过保留/损坏安装 Phpunit LINK 来清洁 pc

and reinstalled with this guide LINK

并使用本指南LINK重新安装

回答by jreuter

For me the fix was simple (Ubuntu 12.04). First I did a search to make sure the file existed and where it was located:

对我来说,修复很简单(Ubuntu 12.04)。首先,我进行了搜索以确保该文件存在以及它所在的位置:

locate Autoload.php

Which should return results similar to this:

应该返回与此类似的结果:

/usr/share/php/File/Iterator/Autoload.php
/usr/share/php/PHP/CodeCoverage/Autoload.php
/usr/share/php/PHP/Depend/Autoload.php
/usr/share/php/PHP/Invoker/Autoload.php
/usr/share/php/PHP/Timer/Autoload.php
/usr/share/php/PHP/Token/Stream/Autoload.php
/usr/share/php/PHPCPD/Autoload.php
/usr/share/php/PHPUnit/Autoload.php
/usr/share/php/PHPUnit/Framework/MockObject/Autoload.php
/usr/share/php/PHP_CodeBrowser/Autoload.php
/usr/share/php/Text/Template/Autoload.php

Then I checked my include_path, which was set correctly in /etc/php5/apache2/php.ini, but was still commented out in /etc/php5/cli/php.ini (the command line interface).

然后我检查了我的include_path,它在/etc/php5/apache2/php.ini 中设置正确,但在/etc/php5/cli/php.ini(命令行界面)中仍然被注释掉了。

Uncommenting this line worked for me:

取消注释这条线对我有用:

include_path = ".:/usr/share/php:/usr/include/php5"

Pretty basic I know, but it's always the little things when setting up a new machine ;-)

我知道很基本,但在设置新机器时总是小事;-)

回答by Harm

All kind of nice things I have read on this one. First check where the Autoload.php is located. Use:

我在这本书上读到了各种各样的好东西。首先检查 Autoload.php 所在的位置。用:

$ find . -name 'Autoload.php' -type f

I assume that your files are located in:

我假设您的文件位于:

/usr/local/pear/share/pear


I have Apple OSX 10.8.4 MAMP and MAMP-PRO installed and I have several other PHP installations.
For the last one I have done the following: First check if there is a php.iniin the directory: /private/etc
If not, do:


我安装了 Apple OSX 10.8.4 MAMP 和 MAMP-PRO,还有其他几个 PHP 安装。
对于最后一个我做了以下:首先检查目录中是否有php.ini/private/etc
如果没有,请执行:

$ sudo cp /private/etc/php.ini.default /private/etc/php.ini

Add the following lines at the bottom of the 'php.ini' file:

在“ php.ini”文件的底部添加以下几行:

; *** Added by <your-name> ****
include_path=".:/usr/local/pear/share/pear"
; *** Ended addition ****

Done.

完毕。

回答by DMCoding

I had the same problem using PhP 5.3 on OSX 10.6 using the built-in server configuration.

我在使用内置服务器配置的 OSX 10.6 上使用 PhP 5.3 时遇到了同样的问题。

I noticed that while PHPUnit was being successfully installed to /usr/lib/php, Autoload.php was trying (line 45) to load the File Iterator from its current directory (/usr/lib/php/PHPUnit) rather than the directory Pear was installing it to (/usr/lib/php/File). Could this be a bug in the Pear installer?

我注意到当 PHPUnit 成功安装到 /usr/lib/php 时,Autoload.php 试图(第 45 行)从其当前目录(/usr/lib/php/PHPUnit)而不是目录 Pear 加载文件迭代器正在将其安装到 (/usr/lib/php/File)。这可能是 Pear 安装程序中的错误吗?

A simple ln -s /usr/lib/php/File /usr/lib/php/PHPUnit/File solved the problem.

一个简单的 ln -s /usr/lib/php/File /usr/lib/php/PHPUnit/File 解决了这个问题。

回答by Stilgar

I am using Ubuntu 14.04and I installed phpunit via Ubuntu Software Center which didn't work.

我使用的是Ubuntu 14.04,我通过 Ubuntu 软件中心安装了 phpunit,但它不起作用。

Finally I remove it and I followed instructions from here

最后我将其删除并按照此处的说明进行操作

wget https://phar.phpunit.de/phpunit.phar  
chmod +x phpunit.phar  
sudo mv phpunit.phar /usr/local/bin/phpunit

回答by MuraliKrishna Gurunathan

I had the same issue with windows 7 and xampp(php 5.6.11), I tried all reinstalling pear and phpunit but it didn't work. When I checked the permission of the C:\xammp\php\peardirectory it was read-only, After I changed the permission it started working.

我在 windows 7 和 xampp(php 5.6.11) 上遇到了同样的问题,我尝试重新安装 pear 和 phpunit,但没有奏效。当我检查C:\xammp\php\pear目录的权限时,它是只读的,更改权限后它开始工作。

回答by Leap Hawk

Look at the error:

看错误:

 (include_path='.;C:\php\pear') in C:\xampp\php\pear\PHPUnit\Autoload.php

The Xampp is trying to locate that file in include_path .;C:\php\pearBut The path for the pear is .;C:\xampp\php\pear.

Xampp 试图在 include_path 中找到该文件,.;C:\php\pear但是梨的路径是.;C:\xampp\php\pear.

Set the right path for the pear and it will work. I just made it.

为梨设置正确的路径,它将起作用。我刚刚做到了。