Php 单元测试Zend控制器-如何测试视图中设置的内容
在Zend中,模型被添加到视图中:Php 单元测试Zend控制器-如何测试视图中设置的内容,php,unit-testing,zend-framework,simpletest,Php,Unit Testing,Zend Framework,Simpletest,在Zend中,模型被添加到视图中: //In a controller public function indexAction() { //Do some work and get a model $this->view->model = $model; } 我们可以很容易地检查视图中是否存在“模型”(我使用simpletest进行此操作): 但是,测试“值”也不起作用: //In a unit test public function testModelVal
//In a controller
public function indexAction() {
//Do some work and get a model
$this->view->model = $model;
}
我们可以很容易地检查视图中是否存在“模型”(我使用simpletest进行此操作):
但是,测试“值”也不起作用:
//In a unit test
public function testModelValue() {
//Call the controllers index action
//Both of these return null, though I'd like to access them!
$this->assertNull($this->controller->view->model);
$this->assertNull($this->controller->view->__get('model'));
}
如何获得(或至少测试)控制器已设置有效模型?因此,解决方案(至少是目前计划的解决方案)是创建一个实现Zend_view_接口的可测试视图。这将包括一个“get”方法,该方法返回传递给“\uu集”的对象。然后,我们将连接控制器,以便在测试引导过程中使用此视图
由于这可能不是最佳方法,我仍然希望听到其他有潜在解决方案的人的意见
//In a unit test
public function testModelValue() {
//Call the controllers index action
//Both of these return null, though I'd like to access them!
$this->assertNull($this->controller->view->model);
$this->assertNull($this->controller->view->__get('model'));
}