views:

473

answers:

2

In Zend, models are added to the view:

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

We can easily check that "model" exists in the view (I'm using simpletest for this):

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

However, testing the "value" doesn't work as well:

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

How do I get (or at least test) that the controller has set a valid model?

A: 

So, the solution (at least the planned one at this time) is make a testable view that implements Zend_View_Interface. This will include a "get" method that returns objects passed to "__set". Then we'll hook up the controller to use this view during the test bootstrapping process.

Since this may not be the optimal approach, I'd still love to hear from others who have potential solutions.

Todd R