2013-08-02 75 views
0

我很難嘗試讓PHPUnit工作。我的目錄是用於php的是C:/wamp/bin/php/php5.4.3現在,我讀了PHPUnit不工作沒有PEAR,所以我得到了go-pear.phar文件,並將它放在C:/wamp/bin/php/php5.4.3/PEAR/上跑了go-pear.phar文件並安裝在系統上。第三,我PHPUnit的使用Git Bash並把它放在C:/wamp/www/local/unit-testing/(不知道是否該目錄是正確的)安裝和使用PHPUnit

現在安裝,我創建了一個簡單的UserTest文件

<?php 
require_once "phpunit/PHPUnit/Autoload.php"; 
require_once "User.php"; 
class UserTest extends PHPUnit_Framework_TestCase 
{ 
    protected $user; 

    // test the talk method 
    protected function setUp() { 
     $this->user = new User(); 
     $this->user->setName("Tom"); 
    } 

    protected function tearDown() { 
     unset($this->user); 
    } 

public function testTalk() { 
     $expected = "Hello world!"; 
     $actual = $this->user->talk(); 
     $this->assertEquals($expected, $actual); 
    } 

} 

並試圖要求該文件並運行它來自Windows中的命令行。但是,由於缺乏關於這些文件應該在哪裏的說明,我似乎無法運行它。

截至目前的問題是命令行不能識別PEAR命令。儘管如此,我運行了PEAR_ENV.reg文件來將PATH變量添加到文件中。

其次,我不確定PEAR & PHPUnit應該安裝在我當前的結構中。我將所有的php頁面/項目保存在C:/wamp/www/local/ < - 我需要測試這個目錄中的文件。

+0

如果我是你,我會安裝Linux作爲開發環境(例如作爲輔助系統),然後輸入幾條命令行來安裝pear,pecl,phpunit和所有其他工具。這可能比與Windows戰鬥的時間要少得多。 – takeshin

+0

您是否從任何人那裏獲得滿意的答覆,或者仍然存在這些建議的問題? –

回答

2

PHPUnit批處理文件應該位於您的路徑中。然後從命令行運行PHPUnit將在shell中完成,當前目錄是您安裝所有內容的位置,並假定您的User.php文件也在那裏。

我起訴一個bootstrap.php文件從我的源代碼目錄運行。

<?php 
/** 
* This file is used to configure the basic environment for testing in PHPUnit. 
*/ 

// PHP and Web server settings 
error_reporting(E_ALL | E_STRICT); 
date_default_timezone_set("America/Toronto");  // Set the default timezone 
$_SERVER['SERVER_NAME'] = 'http://xxx';  // Set Web Server name 

// Process the Include Path to allow the additional applications to be set. 
$IncludePaths = explode(PATH_SEPARATOR, get_include_path()); 
$NewIncludePaths = array_merge($IncludePaths, array(dirname(__FILE__))); 
set_include_path(implode(PATH_SEPARATOR, array_unique($NewIncludePaths))); // Update Include Path 

//define('PHPUNIT_RUNNING', 1); // Indicate to the code that Automated Testing is running. 
?> 

我能夠跟隨PEAR Installation Instructions for PHPUnit和得到的東西了,一旦其中存在PHPUnit.bat在我的DOS路徑的目錄中運行。