【发布时间】:2011-01-04 15:01:38
【问题描述】:
我有一个 MacBook Pro,安装了 PEAR,安装了 PHPUnit,所以我可以在命令行输入 phpunit 并得到使用帮助。
现在我想进行测试,以便我可以从那里构建。
我有一个名为 index.php 的文件,其中包含以下内容:
<?php
require_once '?????';
class Product {
protected $id;
public function __construct($id)
{
$this->id = $id;
}
public function get_id()
{
return $this->id;
}
}
class ProductTest extends PHPUnit_Framework_TestCase
{
function testBasis()
{
$instance = new Product(1);
$this->assertInstanceOf('Product',$instance);
$this->assert($instance->get_id(), 1);
}
}
在命令行中,我想进入文件所在的目录并输入如下内容:
phpunit ?????
接下来的步骤是什么,以便我能够从命令行使用 PHPUnit 测试上述类?
【问题讨论】:
-
是的,这就是我正在阅读的文档(第 4 章),其中第 3 章展示了如何安装我所做的 pear/phpunit,第 4 章假设安装了其余部分,但是当我输入“ phpunit productTest”它找不到“./ProductTest.php”,当我输入“phpunit index.php”时,它说,“callt o undefined method ProductTest::assert()”,我需要一个基本的例子来工作我可以使用该文档。
-
因为 assert 未定义,请查看第 21 章以查看所有可用功能(例如,看起来您在真正需要时尝试使用 assert 是 assertEquals() ,还有 assertInstanceOf()需要替换为 isInstanceOf() )
标签: php unit-testing phpunit