2017-02-02 14 views
0

프로젝트 시스템 아키텍처의 근본적인 변경 후, 필자는 "fake"구현을 만들어야 만했던 이 경우유닛 테스트 : 조롱/스터 빙을위한 적절한 용어 사용

/** 
* Display the template linked to the page. 
* 
* @param $newSmarty Smarty object to use to display the template. 
* 
* @param $parameters associative Array containing the values to pass to the template. 
*  The key is the name of the variable in the template and the value is the value of the variable. 
* 
* @param $account child class in the AccountManager hierarchy 
* 
* @param $partialview String name of the partial view we are working on 
*/ 
protected function displayPageTemplateSmarty(Smarty &$newSmarty, array $parameters = array(), AccountManager $account = NULL, string $partialview = "") 
{ 
    $this->smarty = $newSmarty; 

if (is_file(
    realpath(dirname(__FILE__)) . "/../../" . 
    Session::getInstance()->getCurrentDomain() . "/view/" . (
     !empty($partialview) ? 
     "partial_view/" . $partialview : 
     str_replace(
      array(".html", "/"), 
      array(".tpl", ""), 
      Session::getInstance()->getActivePage() 
     ) 
    ) 
)) { 

    $this->smarty->assign(
     'activeLanguage', 
     Session::getInstance()->getActiveLanguage() 
    ); 

    $this->smarty->assign('domain', Session::getInstance()->getCurrentDomain()); 

    $this->smarty->assign(
     'languages', 
     Languagecontroller::$supportedLanguages 
    ); 

    $this->smarty->assign(
     'title', 
     Languagecontroller::getFieldTranslation('PAGE_TITLE', '') 
    ); 

    $this->smarty->assign_by_ref('PageController', $this); 

    $htmlTagBuilder = HTMLTagBuilder::getInstance(); 

    $languageController = LanguageController::getInstance(); 

    $this->smarty->assign_by_ref('htmlTagBuilder', $htmlTagBuilder); 
    $this->smarty->assign_by_ref('languageController', $languageController); 

    if (!is_null($account)) { 

     $this->smarty->assign_by_ref('userAccount', $account); 
    } 

    if (!is_null($this->menuGenerator)) { 

     $this->smarty->assign_by_ref('menuGenerator', $this->menuGenerator); 
    } 

    foreach ($parameters as $key => $value) { 

     $this->smarty->assign($key, $value);  
    } 

    $this->smarty->display((!empty($partialview) ? 
     "partial_view/" . $partialview : 
     str_replace(
      array(".html", "/"), 
      array(".tpl", ""), 
      Session::getInstance()->getActivePage() 
     ) 
    )); 
} 
} 

, 컨트롤러에 직접 호출하는 데 사용되는 PageController 클래스를,하지만 지금은 더 이상 방법에 액세스 할 수있는 컨트롤러와 내 단위 테스트를 확장하지 않는 추상 클래스입니다 : 다음과 같이 공개.

또한 매우 구체적인 컨텍스트에서만 사용할 수있는 새 세션 래퍼 클래스에서이 메서드를 사용할 수 있으며이를 테스트하려면 가짜 페이지 구현을 만들어야합니다. 나는 몇 가지 기사를 읽고 있지만

/** 
* Add or update an entry to the page session array. 
* 
* Note: can only be updated by the PageController. 
* 
* @param $key String Key in the session array. 
* Will not be added if the key is not a string. 
* 
* @param $value The value to be added to the session array. 
* 
* @return Boolean 
*/ 
public function updatePageSession(string $key, $value) 
{ 
    $trace = debug_backtrace(); 

    $updated = false; 

    if (isset($trace[1]) and 
     isset($trace[1]['class']) and 
     $trace[1]['class'] === 'PageController' 
    ) { 

     $this->pageSession[$key] = $value; 

     $updated = true; 
    } 

    return $updated; 
} 

, 그것은 "심지어 가짜 그 가짜 클래스가"스텁 "또는"모의 "으로 간주해야하는지 여전히 내 마음 속에 아주 불분명하다 (또는 ","dummy "등).

내 상사가 (가까운 장래에) 해외 작업자 대부분에게 내 작업 부하를 위임하기를 기대하기 때문에 적절한 용어를 사용해야합니다.

자명하다면 테스트 목적으로 만 만든 위조 클래스 구현을 어떻게 부릅니까?

답변

2

Gerard Meszaros는 인형, 스텁, 스파이, 가짜 및 가짜의 용어를 설명합니다 here.

PHP 세계 here에서 예제를 찾을 수 있습니다.

+0

감사합니다. Sebastian. 보호 된 메소드를 오버라이드하고 데이터를 주입하기 위해'PageController'를 확장 했으므로, 그것은 스텁이 될 것이다. 우리의 주요 소프트웨어 (캐나다에서 개발 된 100 %)가 단일 유닛 테스트를 가지고 있지 않다는 것을 고려할 때, 단순함을 위해 하나의 명칭을 사용해야 할 것입니다. 모로코 개발자들에 대한 나의 기대를 저주 할 것입니다. 보스가 고용되었습니다 ... –