2011-02-16 122 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