Mercurial > hg > Members > shoshi > webvirt
comparison cake/tests/lib/reporter/cake_text_reporter.php @ 0:261e66bd5a0c
hg init
author | Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 24 Jul 2011 21:08:31 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:261e66bd5a0c |
---|---|
1 <?php | |
2 /** | |
3 * CakeTextReporter contains reporting features used for plain text based output | |
4 * | |
5 * PHP versions 4 and 5 | |
6 * | |
7 * CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing> | |
8 * Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) | |
9 * | |
10 * Licensed under The Open Group Test Suite License | |
11 * Redistributions of files must retain the above copyright notice. | |
12 * | |
13 * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) | |
14 * @link http://cakephp.org CakePHP(tm) Project | |
15 * @package cake | |
16 * @subpackage cake.tests.libs.reporter | |
17 * @since CakePHP(tm) v 1.3 | |
18 * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License | |
19 */ | |
20 include_once dirname(__FILE__) . DS . 'cake_base_reporter.php'; | |
21 | |
22 /** | |
23 * CakeTextReporter contains reporting features used for plain text based output | |
24 * | |
25 * @package cake | |
26 * @subpackage cake.tests.lib | |
27 */ | |
28 class CakeTextReporter extends CakeBaseReporter { | |
29 | |
30 /** | |
31 * Sets the text/plain header if the test is not a CLI test. | |
32 * | |
33 * @return void | |
34 */ | |
35 function paintDocumentStart() { | |
36 if (!SimpleReporter::inCli()) { | |
37 header('Content-type: text/plain'); | |
38 } | |
39 } | |
40 | |
41 /** | |
42 * Paints the end of the test with a summary of | |
43 * the passes and failures. | |
44 * | |
45 * @param string $test_name Name class of test. | |
46 * @return void | |
47 * @access public | |
48 */ | |
49 function paintFooter($test_name) { | |
50 if ($this->getFailCount() + $this->getExceptionCount() == 0) { | |
51 echo "OK\n"; | |
52 } else { | |
53 echo "FAILURES!!!\n"; | |
54 } | |
55 echo "Test cases run: " . $this->getTestCaseProgress() . | |
56 "/" . $this->getTestCaseCount() . | |
57 ", Passes: " . $this->getPassCount() . | |
58 ", Failures: " . $this->getFailCount() . | |
59 ", Exceptions: " . $this->getExceptionCount() . "\n"; | |
60 | |
61 echo 'Time taken by tests (in seconds): ' . $this->_timeDuration . "\n"; | |
62 if (function_exists('memory_get_peak_usage')) { | |
63 echo 'Peak memory use: (in bytes): ' . number_format(memory_get_peak_usage()) . "\n"; | |
64 } | |
65 if ( | |
66 isset($this->params['codeCoverage']) && | |
67 $this->params['codeCoverage'] && | |
68 class_exists('CodeCoverageManager') | |
69 ) { | |
70 CodeCoverageManager::report(); | |
71 } | |
72 } | |
73 | |
74 /** | |
75 * Paints the title only. | |
76 * | |
77 * @param string $test_name Name class of test. | |
78 * @return void | |
79 * @access public | |
80 */ | |
81 function paintHeader($test_name) { | |
82 $this->paintDocumentStart(); | |
83 echo "$test_name\n"; | |
84 flush(); | |
85 } | |
86 | |
87 /** | |
88 * Paints the test failure as a stack trace. | |
89 * | |
90 * @param string $message Failure message displayed in | |
91 * the context of the other tests. | |
92 * @return void | |
93 * @access public | |
94 */ | |
95 function paintFail($message) { | |
96 parent::paintFail($message); | |
97 echo $this->getFailCount() . ") $message\n"; | |
98 $breadcrumb = $this->getTestList(); | |
99 array_shift($breadcrumb); | |
100 echo "\tin " . implode("\n\tin ", array_reverse($breadcrumb)); | |
101 echo "\n"; | |
102 } | |
103 | |
104 /** | |
105 * Paints a PHP error. | |
106 * | |
107 * @param string $message Message to be shown. | |
108 * @return void | |
109 * @access public | |
110 */ | |
111 function paintError($message) { | |
112 parent::paintError($message); | |
113 echo "Exception " . $this->getExceptionCount() . "!\n$message\n"; | |
114 $breadcrumb = $this->getTestList(); | |
115 array_shift($breadcrumb); | |
116 echo "\tin " . implode("\n\tin ", array_reverse($breadcrumb)); | |
117 echo "\n"; | |
118 } | |
119 | |
120 /** | |
121 * Paints a PHP exception. | |
122 * | |
123 * @param Exception $exception Exception to describe. | |
124 * @return void | |
125 * @access public | |
126 */ | |
127 function paintException($exception) { | |
128 parent::paintException($exception); | |
129 $message = 'Unexpected exception of type [' . get_class($exception) . | |
130 '] with message ['. $exception->getMessage() . | |
131 '] in ['. $exception->getFile() . | |
132 ' line ' . $exception->getLine() . ']'; | |
133 echo "Exception " . $this->getExceptionCount() . "!\n$message\n"; | |
134 $breadcrumb = $this->getTestList(); | |
135 array_shift($breadcrumb); | |
136 echo "\tin " . implode("\n\tin ", array_reverse($breadcrumb)); | |
137 echo "\n"; | |
138 } | |
139 | |
140 /** | |
141 * Prints the message for skipping tests. | |
142 * | |
143 * @param string $message Text of skip condition. | |
144 * @return void | |
145 * @access public | |
146 */ | |
147 function paintSkip($message) { | |
148 parent::paintSkip($message); | |
149 echo "Skip: $message\n"; | |
150 } | |
151 | |
152 /** | |
153 * Paints formatted text such as dumped variables. | |
154 * | |
155 * @param string $message Text to show. | |
156 * @return void | |
157 * @access public | |
158 */ | |
159 function paintFormattedMessage($message) { | |
160 echo "$message\n"; | |
161 flush(); | |
162 } | |
163 | |
164 /** | |
165 * Generate a test case list in plain text. | |
166 * Creates as series of url's for tests that can be run. | |
167 * One case per line. | |
168 * | |
169 * @return void | |
170 */ | |
171 function testCaseList() { | |
172 $testCases = parent::testCaseList(); | |
173 $app = $this->params['app']; | |
174 $plugin = $this->params['plugin']; | |
175 | |
176 $buffer = "Core Test Cases:\n"; | |
177 $urlExtra = ''; | |
178 if ($app) { | |
179 $buffer = "App Test Cases:\n"; | |
180 $urlExtra = '&app=true'; | |
181 } elseif ($plugin) { | |
182 $buffer = Inflector::humanize($plugin) . " Test Cases:\n"; | |
183 $urlExtra = '&plugin=' . $plugin; | |
184 } | |
185 | |
186 if (1 > count($testCases)) { | |
187 $buffer .= "EMPTY"; | |
188 echo $buffer; | |
189 } | |
190 | |
191 foreach ($testCases as $testCaseFile => $testCase) { | |
192 $buffer .= $_SERVER['SERVER_NAME'] . $this->baseUrl() ."?case=" . $testCase . "&output=text"."\n"; | |
193 } | |
194 | |
195 $buffer .= "\n"; | |
196 echo $buffer; | |
197 } | |
198 } |