PHPUnit致命错误和include_path


PHPUnit fatal error and include_path

我刚刚使用MacPorts在Mac OSX上安装了PHP和PEAR,然后使用PEAR安装了PHPUnit。当我尝试运行 PHPUnit 时,我收到以下错误消息:

$ phpunit StackTest.php
PHP Warning:  require_once(File/Iterator/Autoload.php): failed to open stream: No such file or directory in /opt/local/lib/php/PHPUnit/Autoload.php on line 45
Warning: require_once(File/Iterator/Autoload.php): failed to open stream: No such file or directory in /opt/local/lib/php/PHPUnit/Autoload.php on line 45
PHP Fatal error:  require_once(): Failed opening required 'File/Iterator/Autoload.php' (include_path='.:/php/includes:/usr/local/php5/lib/php:/opt/local/lib/php/pear') in /opt/local/lib/php/PHPUnit/Autoload.php on line 45
Fatal error: require_once(): Failed opening required 'File/Iterator/Autoload.php' (include_path='.:/php/includes:/usr/local/php5/lib/php:/opt/local/lib/php/pear') in /opt/local/lib/php/PHPUnit/Autoload.php on line 45

好的,所以文件File/Iterator/Autoload.php不在我的include_path中,所以我尝试了

$ ls -l /opt/local/lib/php/File/Iterator/Autoload.php
-rw-r--r--  1 root  admin  2682 May 23 14:38 /opt/local/lib/php/File/Iterator/Autoload.php
$ phpunit --include-path /opt/local/lib/php StackTest.php
PHP Warning:  require_once(File/Iterator/Autoload.php): failed to open stream: No such file or directory in /opt/local/lib/php/PHPUnit/Autoload.php on line 45
Warning: require_once(File/Iterator/Autoload.php): failed to open stream: No such file or directory in /opt/local/lib/php/PHPUnit/Autoload.php on line 45
PHP Fatal error:  require_once(): Failed opening required 'File/Iterator/Autoload.php' (include_path='.:/php/includes:/usr/local/php5/lib/php:/opt/local/lib/php/pear') in /opt/local/lib/php/PHPUnit/Autoload.php on line 45
Fatal error: require_once(): Failed opening required 'File/Iterator/Autoload.php' (include_path='.:/php/includes:/usr/local/php5/lib/php:/opt/local/lib/php/pear') in /opt/local/lib/php/PHPUnit/Autoload.php on line 45

仍然不起作用,并且它不包括它应该成为的新路径。有人知道我能做些什么吗?(如果我能帮助它,我宁愿不修改我的php.ini文件,因为它是只读的,而且我对 PHP 相当陌生,不想以我不理解的方式破坏它。谢谢。

仍然没有答案为什么命令行上的--include-path不起作用,所以这是我所做的:

$ which phpunit
/opt/local/bin/phpunit
$ sudo emacs /opt/local/bin/phpunit

计划是修改php.ini文件,所以首先我必须弄清楚哪个php.ini正在初始化phpunit。如果有人有更好的方法来做到这一点,我很高兴听到它。我在phpunit代码中添加了以下行,紧跟在<?php开始标记之后:

echo php_ini_loaded_file();

现在,当我运行phpunit时,我得到了以下(此处截断(输出:

/opt/local/etc/php5/php.iniPHP Warning:  require_once(File/Iterator/Autoload.php): failed to open stream: No such file or directory in /opt/local/lib/php/PHPUnit/Autoload.php on line 45...

然后:

$ sudo emacs /opt/local/etc/php5/php.ini

我搜索了include_path指令,并将:/opt/local/lib/php附加到末尾。所以现在,phpunit工作了,尽管我不知道我是否破坏了我的设置方面的其他任何东西。

我在安装Windows时遇到了类似的问题,但我不确定它在OSX上是否是相同的问题。 我发现PEAR安装在用于启动程序的批处理文件中创建了错误的路径。

标准安装会导致已安装的批处理文件出现错误。pear.bat 批处理文件的最后一个脚本行需要将include_path括在单引号中("include_path='%VARIABLE%'"(。

我所做的更改是:

"%PHP_PEAR_PHP_BIN%" -C -d memory_limit="-1" -d safe_mode=0 -d register_argc_argv="On" -d auto_prepend_file="" -d auto_append_file="" -d variables_order=EGPCS -d open_basedir="" -d output_buffering=1 -d "include_path='%PHP_PEAR_INSTALL_DIR%'" -f "%PHP_PEAR_INSTALL_DIR%'pearcmd.php" -- %1 %2 %3 %4 %5 %6 %7 %8 %9

我不确定您是否遇到与上述安装类似的问题。

如果做不到这一点,我在 Windows 7 上的 PHPUnit 批处理文件是

if "%PHPBIN%" == "" set PHPBIN=C:'Program Files (x86)'PHP'php.exe
if not exist "%PHPBIN%" if "%PHP_PEAR_PHP_BIN%" neq "" goto USE_PEAR_PATH
GOTO RUN
:USE_PEAR_PATH
set PHPBIN=%PHP_PEAR_PHP_BIN%
:RUN
"%PHPBIN%" "C:'Program Files (x86)'PHP'phpunit" %*

一种侵入性较小的方法(永久不更改 php.ini(是在失败的脚本中包含以下行: set_include_path("/opt/local/lib/php/");您包含的位置可能略有不同。如果这不起作用,请搜索一个名为 Autoload 的文件.php该文件位于如下所示的文件夹结构中:File/Iterator/Autoload.php并使用 File 的路径作为 set_include_path() 中的路径。