2012-02-09 56 views
2

現在是2天,我一直試圖讓phpunit在我的OSX上工作。我從MAMP安裝中運行php。PHPUnit沒有找到Framework.php

我已經通過PEAR與所有依賴關係安裝了它。 PHPUnit的--version命令正在工作並顯示:

$ phpunit --version 
PHPUnit 3.6.10 by Sebastian Bergmann. 

但是當我運行在命令行測試它顯示:

Warning: require_once(/Applications/MAMP/bin/php/php5.3.6/lib/php/PHPUnit/Framework): failed to open stream: No such file or directory in /Users/magalie/Sites/HelloWorld/HelloWorldTest.php on line 3 

Call Stack: 
    0.0028  632128 1. {main}() /Applications/MAMP/bin/php/php5.3.6/bin/phpunit:0 
    0.0078 1161288 2. PHPUnit_TextUI_Command::main() /Applications/MAMP/bin/php/php5.3.6/bin/phpunit:46 
    0.0078 1162016 3. PHPUnit_TextUI_Command->run() /Applications/MAMP/bin/php/php5.3.6/lib/php/PHPUnit/TextUI/Command.php:130 
    0.1109 1793352 4. PHPUnit_Runner_BaseTestRunner->getTest() /Applications/MAMP/bin/php/php5.3.6/lib/php/PHPUnit/TextUI/Command.php:150 
    0.1109 1793352 5. PHPUnit_Runner_BaseTestRunner->loadSuiteClass() /Applications/MAMP/bin/php/php5.3.6/lib/php/PHPUnit/Runner/BaseTestRunner.php:104 
    0.1115 1837832 6. PHPUnit_Runner_StandardTestSuiteLoader->load() /Applications/MAMP/bin/php/php5.3.6/lib/php/PHPUnit/Runner/BaseTestRunner.php:168 
    0.1126 1983864 7. PHPUnit_Util_Fileloader::checkAndLoad() /Applications/MAMP/bin/php/php5.3.6/lib/php/PHPUnit/Runner/StandardTestSuiteLoader.php:78 
    0.1127 1983984 8. PHPUnit_Util_Fileloader::load() /Applications/MAMP/bin/php/php5.3.6/lib/php/PHPUnit/Util/Fileloader.php:79 
    0.1128 1994704 9. include_once('/Users/magalie/Sites/HelloWorld/HelloWorldTest.php') /Applications/MAMP/bin/php/php5.3.6/lib/php/PHPUnit/Util/Fileloader.php:95 


Fatal error: require_once(): Failed opening required 'PHPUnit/Framework' (include_path='.:/Applications/MAMP/bin/php/php5.3.6/lib/php:/Applications/MAMP/bin/php5.3/lib/php/PEAR:/usr/lib/php') in /Users/magalie/Sites/HelloWorld/HelloWorldTest.php on line 3 

Call Stack: 
    0.0028  632128 1. {main}() /Applications/MAMP/bin/php/php5.3.6/bin/phpunit:0 
    0.0078 1161288 2. PHPUnit_TextUI_Command::main() /Applications/MAMP/bin/php/php5.3.6/bin/phpunit:46 
    0.0078 1162016 3. PHPUnit_TextUI_Command->run() /Applications/MAMP/bin/php/php5.3.6/lib/php/PHPUnit/TextUI/Command.php:130 
    0.1109 1793352 4. PHPUnit_Runner_BaseTestRunner->getTest() /Applications/MAMP/bin/php/php5.3.6/lib/php/PHPUnit/TextUI/Command.php:150 
    0.1109 1793352 5. PHPUnit_Runner_BaseTestRunner->loadSuiteClass() /Applications/MAMP/bin/php/php5.3.6/lib/php/PHPUnit/Runner/BaseTestRunner.php:104 
    0.1115 1837832 6. PHPUnit_Runner_StandardTestSuiteLoader->load() /Applications/MAMP/bin/php/php5.3.6/lib/php/PHPUnit/Runner/BaseTestRunner.php:168 
    0.1126 1983864 7. PHPUnit_Util_Fileloader::checkAndLoad() /Applications/MAMP/bin/php/php5.3.6/lib/php/PHPUnit/Runner/StandardTestSuiteLoader.php:78 
    0.1127 1983984 8. PHPUnit_Util_Fileloader::load() /Applications/MAMP/bin/php/php5.3.6/lib/php/PHPUnit/Util/Fileloader.php:79 
    0.1128 1994704 9. include_once('/Users/magalie/Sites/HelloWorld/HelloWorldTest.php') /Applications/MAMP/bin/php/php5.3.6/lib/php/PHPUnit/Util/Fileloader.php:95 

下面是從梨配置

Configuration (channel pear.php.net): 
===================================== 
Auto-discover new Channels  auto_discover 1 
Default Channel    default_channel pear.php.net 
HTTP Proxy Server Address  http_proxy  <not set> 
PEAR server [DEPRECATED]  master_server pear.php.net 
Default Channel Mirror   preferred_mirror pear.php.net 
Remote Configuration File  remote_config <not set> 
PEAR executables directory  bin_dir   /Applications/MAMP/bin/php/php5.3.6/bin 
PEAR documentation directory doc_dir   /Applications/MAMP/bin/php/php5.3.6/lib/php/doc 
PHP extension directory  ext_dir   /Applications/MAMP/bin/php/php5.3.6/lib/php/extensions 
PEAR directory     php_dir   /Applications/MAMP/bin/php/php5.3.6/lib/php/ 
PEAR Installer cache directory cache_dir  /var/folders/qH/qHdMKNY5GsywPNMBPX-T7U+++TI/-Tmp-//pear/cache 
PEAR configuration file  cfg_dir   /Applications/MAMP/bin/php/php5.3.6/lib/php/cfg 
directory 
PEAR data directory   data_dir   /Applications/MAMP/bin/php/php5.3.6/lib/php/data 
PEAR Installer download  download_dir  /var/folders/qH/qHdMKNY5GsywPNMBPX-T7U+++TI/-Tmp-//pear/download 
directory 
PHP CLI/CGI binary    php_bin   /Applications/MAMP/bin/php/php5.3.6/bin/php 
php.ini location    php_ini   /Applications/MAMP/bin/php/php5.3.6/conf/php.ini 
--program-prefix passed to  php_prefix  <not set> 
PHP's ./configure 
--program-suffix passed to  php_suffix  <not set> 
PHP's ./configure 
PEAR Installer temp directory temp_dir   /var/folders/qH/qHdMKNY5GsywPNMBPX-T7U+++TI/-Tmp-//pear/temp 
PEAR test directory   test_dir   /Applications/MAMP/bin/php/php5.3.6/lib/php/tests 
PEAR www files directory  www_dir   /Applications/MAMP/bin/php/php5.3.6/lib/php/www 
Cache TimeToLive    cache_ttl  3600 
Preferred Package State  preferred_state stable 
Unix file mask     umask   22 
Debug Log Level    verbose   1 
PEAR password (for    password   <not set> 
maintainers) 
Signature Handling Program  sig_bin   /usr/local/bin/gpg 
Signature Key Directory  sig_keydir  /Applications/MAMP/bin/php/php5.3.6/pearkeys 
Signature Key Id    sig_keyid  <not set> 
Package Signature Type   sig_type   gpg 
PEAR username (for    username   <not set> 
maintainers) 
User Configuration File  Filename   /Users/magalie/.pearrc 
System Configuration File  Filename   /Applications/MAMP/bin/php/php5.3.6/conf/pear.conf 

和phpunit運行於/ usr/lib/php,它是$ PATH的一部分

這是我的HElloWorldTest.php文件的內容,我已經嘗試過或沒有php擴展到框架文件沒有成功。

<?php 
require_once 'HelloWorld.php'; 
require_once 'PHPUnit/Framework'; 
///Applications/MAMP/bin/php/php5.3.6/lib/php/ 

class HelloWorldTest extends PHPUnit_Framework_TestCase 
{ 
    public function test__construct() 
    { 
     $hw = new HelloWorld(); 
     $this->assertType('HelloWorld, $hw'); 
    } 

    public function testSayHello() 
    { 
     $hw = new HelloWorld(); 
     $string = $hw->sayHello(); 
     $this->asserEquals('Hello World!', $string); 
    } 
} 

我已經嘗試卸載並重新安裝phpunit,沒有運氣。並且查看PHPUnit目錄中沒有Framework.php文件。

SO我在做什麼錯? 有沒有人有同樣的問題?你是如何解決它的? 這讓我發瘋,而且我有印象跑在圈子裏...

感謝您的幫助。

回答

6

您不需要在測試中加載PHPUnit。可執行文件phpunit負責設置自己的自動加載器。刪除這一行:

require_once 'PHPUnit/Framework'; 
+1

非常感謝!這解決了我的問題 – user1200460 2012-02-20 17:51:32

0

你並不需要加載的PHPUnit在您的測試。 phpunit可執行文件負責設置其自己的自動加載器 。刪除該行:

require_once'PHPUnit/Framework';

這對我有效。另外,如果你有很多現有的測試,甚至可能不是你自己寫的,你可以創建一個名爲「Framework.php」的空文件並將它放在你的PHPUnit目錄中。