我很难让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
文件并安装在系统上。第三,我使用Git Bash
安装了PHPUnit,并将其放入C:/wamp/www/local/unit-testing/
(不确定目录是否正确)
现在,我创建了一个简单的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/
<--我需要测试这个目录中的文件。
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.
?>
我能够按照PHPUnit的PEAR安装说明进行操作,一旦PHPUnit.bat所在的目录在我的DOS路径中,就可以启动并运行它。