OSDN Git Service

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