2009-04-16 7 views
2

이 모델은 뷰에 추가 된 뷰에 설정되어있는 것을 테스트하는 방법은 다음과 같습니다단위 테스트 젠드 컨트롤러 - 나는 젠드에서

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

우리는 쉽게 "모델은"보기에 있는지 (I를 확인하실 수 있습니다 뿐만 아니라 작동하지 않습니다 "값을"테스트, 그러나

//In a unit test 
    public function testModelIsSetInView() { 
    //Call the controllers index action 
    $this->assertTrue(isset($this->controller->view->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')); 
    } 

내가 어떻게합니까 (또는 숨기려 st 테스트) 컨트롤러가 유효한 모델을 설정 했습니까?

답변

0

그래서,이 솔루션 (이 시간에 적어도 계획 한) Zend_View_Interface를 구현하는 테스트 가능한 뷰를 만들 수 있습니다. 여기에는 "__set"에 전달 된 객체를 반환하는 "get"메서드가 포함됩니다. 그런 다음 컨트롤러를 연결하여 테스트 부트 스트랩 프로세스 중에이보기를 사용합니다.

이 방법이 최적의 방법이 아니기 때문에 잠재적 해결책이있는 다른 사람들의 의견을 듣고 싶습니다.

관련 문제