2011-10-12 9 views
0

CakePHP 2.0의 기본 저장 메소드 테스트 케이스에 필요한 어설 션을 도와 줄 사람이 있습니까? 기본 "Save/Submit"모델 테스트 케이스에는 어떤 주장/테스트가 필요합니까?

I 제품, 사용자 및 뉴스 모델, 내가 News 모델의 submit 방법에 대한 테스트 케이스를 작성 찾고 있어요 난 그냥 궁금 해서요 포함하는 많은 방법/가지가 무엇을 실제로 필요한 어떤 ISN '티. 모든 모델에 기본 조명기 설정이 있습니다.

내가 테스트를 효과적으로이 될 것입니다 해요 방법 :

class News extends AppModel { 
    public submit($productId, $userId, $newsData) { 
     // Logic which checks for user and products existence, saves and returns submitted row 
    } 
} 

테스트 케이스

public function testSubmit() { 

    // Save News 
    $newsData = array(
     'News' => array(
      'title' => 'Here is the title of the news', 
      'body' => 'Here is the news body', 
      'source' => 'News came from here' 
     ) 
    ); 

    $news = $this->News->submit('product-1', 'user-1', $newsData); 

    // Now what? 
} 

답변

1

단순히 배열이 배열과 동일한 것으로, 그 $ 뉴스 배열, 객체 인 주장을 예상 할 수있는 것은 무엇이든, 메소드를 구현하기 전에 (테스트 주도 개발), phpunit assert 메소드 중 하나 이상을 사용하여 결과를 선언 할 수 있어야합니다.

$ this-> assertTrue ($ news); 모든 어설 션에 대한 설명서를 확인하십시오. http://www.phpunit.de/manual/current/en/

또한 CakePHP 핵심 테스트를 통해 테스트하는 방법에 대한 아이디어를 얻으실 수 있습니다. https://github.com/CakeDC/tags/blob/2.0/Test/Case/Model/TaggedTest.php 또는 https://github.com/CakeDC/users/blob/2.0/Test/Case/Model/UserTest.php

같은 일부 오픈 소스 플러그인 exmaples에서

또는보고