2009-04-16 63 views
2

在Zend公司,模型添加到視圖設置:單元測試Zend的控制器 - 我怎麼考什麼已經在視圖

//In a controller 
public function indexAction() { 
    //Do some work and get a model 
    $this->view->model = $model;  
} 

我們可以方便地查看「模型」視圖中的存在(我「M使用此SimpleTest的):

//In a unit test 
    public function testModelIsSetInView() { 
    //Call the controllers index action 
    $this->assertTrue(isset($this->controller->view->model)); 
    } 

然而,在測試 「價值」 不工作,以及:

//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')); 
    } 

如何獲取(或LEA st測試)控制器已經設置了一個有效的模型?

回答

0

所以,溶液(至少一個計劃在該時間)爲使實現Zend_View_Interface的一個可測試圖。這將包含一個返回傳遞給「__set」的對象的「get」方法。然後,我們將在測試引導過程中連接控制器以使用此視圖。

因爲這可能不是最佳方法,所以我仍然喜歡聽到其他有潛在解決方案的人的消息。