OSDN Git Service

- ETHNA_UTF8_BRANCH followed r519 in trunk.
[ethna/ethna.git] / class / Ethna_UnitTestReporter.php
1 <?php
2 /**
3  *  Ethna_UnitTestReporter.php
4  *
5  *  @author     Takuya Ookubo <sfio@sakura.ai.to>
6  *  @license    http://www.opensource.org/licenses/bsd-license.php The BSD License
7  *  @package    Ethna
8  *  @version    $Id$
9  */
10
11 require_once 'simpletest/scorer.php';
12
13 /**
14  *  Ethnaマネージャクラス
15  *
16  *  @author     Takuya Ookubo <sfio@sakura.ai.to>
17  *  @access     public
18  *  @package    Ethna
19  */
20 class Ethna_UnitTestReporter extends SimpleReporter {
21     
22     var $_character_set;
23
24     var $report;
25     var $result;
26
27     /**
28      *  Ethna_UnitTestReporterのコンストラクタ
29      *
30      *  @access public
31      *  @param  string  $character_set  キャラクタセット
32      */
33     function Ethna_UnitTestReporter($character_set = 'UTF-8')
34     {
35         $this->SimpleReporter();
36         $this->_character_set = $character_set;
37         $this->report= array();
38         $this->result= array();
39     }
40
41     /**
42      *  結果
43      *
44      *  @access public
45      *  @param string   $test_name  テスト名称
46      */
47     function paintFooter($test_name)
48     {
49         $colour = ($this->getFailCount() + $this->getExceptionCount() > 0 ? "red" : "green");
50         $this->result = array(
51             'TestCaseProgress' => $this->getTestCaseProgress(),
52             'TestCaseCount' => $this->getTestCaseCount(),
53             'PassCount' => $this->getPassCount(),
54             'FailCount' => $this->getFailCount(),
55             'ExceptionCount' => $this->getExceptionCount(),
56         );
57     }
58
59     /**
60      *  パス
61      *
62      *  @access public
63      * @param string   $message    メッセージ
64      */
65     function paintPass($message)
66     {
67         parent::paintPass($message);
68             
69         $test_list = $this->getTestList();
70         $this->report[] = array(
71             'type' => 'Pass',
72             'test' => $test_list[2],
73             'message' => $message,
74         );
75     }
76
77     /**
78      *  失敗
79      *
80      *  @access public
81      * @param string   $message    メッセージ
82      */
83     function paintFail($message)
84     {
85         parent::paintFail($message);
86
87         $test_list = $this->getTestList();
88         $this->report[] = array(
89             'type' => 'Fail',
90             'test' => $test_list[2],
91             'message' => $message,
92         );
93     }
94
95     /**
96      *  例外
97      *
98      *  @access public
99      * @param string   $message    メッセージ
100      */
101     function paintException($message)
102     {
103         parent::paintException($message);
104
105         $breadcrumb = $this->getTestList();
106         $test = $breadcrumb[2];
107         array_shift($breadcrumb);
108         $this->report[] = array(
109             'type' => 'Exception',
110             'test' => $test,
111             'breadcrumb' => $breadcrumb,
112             'message' => $message,
113         );
114     }
115
116     /**
117      *  テストケース開始
118      *
119      *  @access public
120      *  @param string   $test_name  テスト名称
121      */
122     function paintCaseStart($test_name)
123     {
124         parent::paintCaseStart($test_name);
125
126         $this->report[] = array(
127             'type' => 'CaseStart',
128             'test_name' => $test_name,
129         );
130     }
131
132     /**
133      *  テストケース終了
134      *
135      *  @access public
136      *  @param string   $test_name  テスト名称
137      */
138     function paintCaseEnd($test_name)
139     {
140         parent::paintCaseEnd($test_name);
141
142         $this->report[] = array(
143             'type' => 'CaseEnd',
144         );
145     }
146
147     /**
148      *  フォーマット済みメッセージ
149      *
150      *  @access public
151      * @param string   $message    メッセージ
152      */
153     function paintFormattedMessage($message)
154     {
155         $this->report[] = array(
156             'type' => 'FormattedMessage',
157             'message' => $this->_htmlEntities($message),
158         );
159     }
160
161     /**
162      *  HTMLエンティティ変換
163      *
164      * @access protected
165      * @param string   $message    プレーンテキスト
166      * @return string              HTMLエンティティ変換済みメッセージ
167      */
168     function _htmlEntities($message)
169     {
170         return htmlentities($message, ENT_COMPAT, $this->_character_set);
171     }
172 }
173 ?>