【发布时间】:2010-03-23 09:19:03
【问题描述】:
我正在使用 Zend_Test_PHPUnit_ControllerTestCase 来测试我的控制器。这个类提供了各种测试渲染输出的方法,但我不想让我的视图脚本参与进来。我想测试我的视图的变量。有没有办法访问 controllers view 对象?
这是一个例子,我正在尝试做的事情:
<?php
class Controller extends Zend_Controller_Action
{
public function indexAction()
{
$this-view->foo = 'bar';
}
}
class ControllerTest extends Zend_Test_PHPUnit_ControllerTestCase
{
public function testShowCallsServiceFind()
{
$this->dispatch('/controller');
//doesn't work, there is no such method:
$this->assertViewVar('foo', 'bar');
//doesn't work, end_Test_PHPUnit_ControllerTestCase has no getView method:
$this->assertEquals(
'bar',
$this->getView()->foo
);
}
}
【问题讨论】:
标签: php unit-testing zend-framework phpunit