2011-02-16 119 views
7

有没有人知道我在做什么错? 我已经安装PHPUnit的,而且一切都很好,当我在/ opt /本地/ PEAR目录林,所以如果我去到/ opt /本地/ PEAR目录并运行PHPUnit的我得到:phpunit - 错误的路径

PHPUnit 3.5.11 by Sebastian Bergmann.
Usage: 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

我知道这是什么毛病我的道路。我该如何解决它?

回答

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 2011-02-16 22:41:17

+0

@RobertPitt已更新,谢谢 – 2011-02-16 22:44:47

1

对于Ubuntu的编辑本php.ini中的CLI:

/usr/local/lib/php.ini 

将/ usr/local/lib目录/ PHP /你包括线路

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

我花了一天想办法。答对了。

如果这不起作用,试试这个,它会给你提示你的PHP库位于何处。

$ locate PHP_CodeCoverage 
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安装程序可从PHPUnit的通道安装软件包:

5

在Ubuntu中,我用

pear config-set auto_discover 1 
pear install pear.phpunit.de/PHP_CodeCoverage