2017-02-02 7 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

ありがとう、セバスチャン。保護されたメソッドをオーバーライドしてデータを挿入するために 'PageController'を拡張するので、それはスタブします。 私たちの主なソフトウェア(カナダで開発された100%)が単体テストのテストを持っていないことを考慮すると、私はモロッコの開発者である私の期待を弱めるでしょう。ボスを雇った... –

関連する問題