2013-08-02 79 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路径的目录中运行。