【问题标题】:Installing and working with PHPUnit安装和使用 PHPUnit
【发布时间】:2013-08-03 16:19:18
【问题描述】:

我很难让 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/

【问题讨论】:

  • 如果我是你,我会安装 Linux 作为开发环境(例如作为辅助系统),然后键入几个命令行来安装 pear、pecl、phpunit 和所有其他工具。这可能比使用 Windows 花费的时间要少得多。
  • 您是否得到任何人的满意答复以接受,或者建议仍然存在问题?

标签: php phpunit pear


【解决方案1】:

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.bat 所在的目录位于我的 DOS 路径中,我就能够关注 PEAR Installation Instructions for PHPUnit 并启动并运行。

【讨论】:

    猜你喜欢
    • 2017-11-10
    • 2011-08-13
    • 2013-09-12
    • 2014-12-15
    • 1970-01-01
    • 2017-06-22
    • 2018-10-09
    • 2023-04-04
    • 1970-01-01
    相关资源
    最近更新 更多