2

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

コントローラーが有効なモデルを設定したことをどのように取得 (または少なくともテスト) しますか?

4

2 に答える 2

1

http://www.contentwithstyle.co.uk/content/unit-testing-controllers-with-zend-framework

于 2009-04-16T14:56:42.430 に答える
0

したがって、解決策 (少なくとも現時点で計画されているもの) は、Zend_View_Interface を実装するテスト可能なビューを作成することです。これには、「__set」に渡されたオブジェクトを返す「get」メソッドが含まれます。次に、テスト ブートストラップ プロセス中にこのビューを使用するようにコントローラーを接続します。

これは最適なアプローチではない可能性があるため、潜在的な解決策を持っている他の人からの連絡をお待ちしています.

于 2009-04-16T15:31:06.347 に答える