Source for file Test.php

Documentation is available at Test.php

  1. <?php
  2. // vim: foldmethod=marker
  3. /**
  4.  * Ethna_Plugin_Generator_Test.php
  5.  * 
  6.  * @author BoBpp <bobpp@users.sourceforge.jp>
  7.  * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
  8.  * @package Ethna
  9.  * @version $Id: 07caabdfdb80f0ef3450dffd3aab24634d9000d4 $
  10.  */
  11.  
  12. // {{{ Ethna_Plugin_Generator_Test
  13. /**
  14.  * Normal Test Case Generator.
  15.  * 
  16.  * @author BoBpp <bobpp@users.sourceforge.jp>
  17.  * @package Ethna
  18.  */
  19. {
  20.     /**
  21.      * ファイル生成を行う
  22.      * 
  23.      * @access public
  24.      * @param string $skelfile スケルトンファイル名
  25.      * @param string $name     テストケース名
  26.      * @return mixed TRUE; OK
  27.      *                Ethna_Error: エラー発生
  28.      */
  29.     function generate($skelfile$name)
  30.     {
  31.         // Controllerを取得
  32.         $ctl $this->ctl;
  33.         
  34.         // テストを生成するディレクトリがあるか?
  35.         // なければ app/test がデフォルト。
  36.         $dir $ctl->getDirectory('test');
  37.         if ($dir === null{
  38.             $dir $ctl->getDirectory('app'"/" "test";
  39.         }
  40.         
  41.         // ファイル名生成
  42.         $file preg_replace('/_(.)/e'"'/' . strtoupper('\$1')"ucfirst($name)) "Test.php";
  43.         $generatePath "$dir/$file";
  44.         
  45.         // スケルトン決定
  46.         $skelton (!empty($skelfile))
  47.                  ? $skelfile
  48.                  : "skel.test.php";
  49.         
  50.         // マクロ生成
  51.         $macro array();
  52.         $macro['project_id'ucfirst($ctl->getAppId());
  53.         $macro['file_path'$file;
  54.         $macro['name'preg_replace('/_(.)/e'"strtoupper('\$1')"ucfirst($name));
  55.         
  56.         $userMacro $this->_getUserMacro();
  57.         $macro array_merge($macro$userMacro);
  58.         
  59.         // 生成
  60.         Ethna_Util::mkdir(dirname($generatePath)0755);
  61.         if (file_exists($generatePath)) {
  62.             printf("file [%s] already exists -> skip\n"$generatePath);
  63.         else if ($this->_generateFile($skelton$generatePath$macro== false{
  64.             printf("[warning] file creation failed [%s]\n"$generatePath);
  65.         else {
  66.             printf("test script(s) successfully created [%s]\n"$generatePath);
  67.         }
  68.  
  69.         $true true;
  70.         return $true;
  71.     }
  72. }
  73. // }}}

Documentation generated on Fri, 11 Nov 2011 03:59:09 +0900 by phpDocumentor 1.4.3