나는 요리 책에서 몇 가지 예를 찾고있다하지만 난 그것을 얻을 해달라고 : http://book.cakephp.org/2.0/en/development/testing.html#a-more-complex-example테스트 리디렉션 CakePHP는 2.0
이 어떻게 이와 같은 삭제 작업에 리디렉션을 테스트 할 수 있습니다 ?
public function delete($id = null){
$this->Comment->id = $id;
if (!$this->Comment->exists()) {
throw new NotFoundException(__('Invalid comment'));
}
if ($this->Comment->delete()) {
$this->Session->setFlash(__('Comment deleted'));
return $this->redirect(array('controller' => 'posts', 'action' => 'view', $idPost));
}
$this->Session->setFlash(__('Comment was not deleted'));
return $this->redirect(array('controller' => 'posts', 'action' => 'view', $idPost));
}
}
테스트는 리디렉션 호출 후에 중지, 그래서 심지어이 에코 인쇄되지 않습니다 에코 인쇄되지 않을
public function testDelete(){
$result = $this->testAction("/comments/delete/1");
echo "this is not printed";
print_r($this->headers);
}
빈 뷰 오류가 발생하는지 궁금합니다. 이 경우 컨트롤러에서'render' 함수를 조롱 해 볼 수 있습니다. 어쨌든 삭제보기가 없기 때문입니다. – jeremyharris
조롱하는 것은 무엇을 의미합니까? 그리고 네, 아니, 리디렉션이 잘 작동하고보기 작업이 비어 있지 않습니다. – Alvaro
조롱은 특정 방법으로 원하는 것을 반환하도록 테스트하는 절차입니다. 예를 들어,'CakeRequest :: send()'는 조롱을 당했고 아무 것도하지 말라고 명령하고, 그래서 헤더를 보내지 않는다. 조롱 된 방법에 대해 무엇을 기대할 것인지 또는 어떻게 대응할 것인지를 알 수 있습니다 (http://www.phpunit.de/manual/3.0/en/mock-objects.html 참조). Cake를 쉽게 조롱하려면 http://book.cakephp.org/2.0/en/development/testing.html#using-mocks-with-testaction을 확인하십시오.'ControllerTestCase :: testAction()'은 이것을 자동으로 수행합니다. – jeremyharris