PHPUnit - 路径错误

7
有人知道我做错了什么吗?我已经安装了phpunit,当我在/opt/local/PEAR目录下时一切正常,所以如果我进入/opt/local/PEAR目录并运行phpunit,则会得到以下结果:PHPUnit 3.5.11 by Sebastian Bergmann。用法: phpunit [switches] UnitTest [UnitTest.php] phpunit [switches] blablabla,但是如果我在其他路径上,我会得到以下错误信息:Warning: require_once(PHP/CodeCoverage/Filter.php): failed to open stream: No such file or directory in /usr/local/bin/phpunit on line 38 Fatal error: require_once(): Failed opening required 'PHP/CodeCoverage/Filter.php' (include_path='.:/usr/lib/php') in /usr/local/bin/phpunit on line 38。我知道我的PATH出了问题。我该如何解决?
5个回答

8
尝试将 /opt/local/PEAR 添加到您的 php.ini 文件 include_path 中。
//Before:
include_path='.:/usr/lib/php'
//After:
include_path='.:/usr/lib/php:/opt/local/PEAR'

更改生效后,您可能还需要重新启动 Web 服务器。

正如 RobertPitt 的评论所述,即使没有访问 php.ini 文件的权限,也可以在运行时执行此操作。

<?php
$path = '/opt/local/PEAR';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
?>

1
你也可以在运行时执行这个操作,我认为你应该将它添加到你的答案中。 - RobertPitt
1
+1,旁注:由于PHPUnit是从命令行执行的,因此如果用户正在运行Web服务器,则无需重新启动它。 - edorian

7

用于分发PHPUnit的PEAR渠道(pear.phpunit.de)需要在本地PEAR环境中进行注册。此外,PHPUnit依赖的组件托管在其他PEAR渠道上。

pear channel-discover pear.phpunit.de
pear channel-discover components.ez.no
pear channel-discover pear.symfony-project.com

这只需要做一次。现在,PEAR Installer 可以用于从 PHPUnit 渠道安装包:

pear install phpunit/PHPUnit

1
这对我有用。我必须先卸载它,添加发现频道,然后再安装它。 - akohout

5
在Ubuntu上,我使用了
pear config-set auto_discover 1
pear install pear.phpunit.de/PHP_CodeCoverage

1

对于Ubuntu,编辑此php.ini文件以用于CLI:

 /usr/local/lib/php.ini

将 /usr/local/lib/php/ 添加到您的 include 行中

include_path= "/opt/zend/library/:/var/www/library/:/usr/local/bin/pear/:/usr/local/lib/php/"

花了我一天的时间才弄明白。终于成功了。

如果这个方法不行,试试这个,它会给你一个提示,告诉你你的PHP库在哪里。

$ locate PHP_CodeCoverage

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接