Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
13532 anikendra 1
<?php
2
/**
3
 * CakeBaseReporter contains common functionality to all cake test suite reporters.
4
 *
5
 * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
6
 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
7
 *
8
 * Licensed under The MIT License
9
 * For full copyright and license information, please see the LICENSE.txt
10
 * Redistributions of files must retain the above copyright notice
11
 *
12
 * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
13
 * @link          http://cakephp.org CakePHP(tm) Project
14
 * @since         CakePHP(tm) v 1.3
15
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
16
 */
17
 
18
require_once 'PHPUnit/TextUI/ResultPrinter.php';
19
 
20
/**
21
 * CakeBaseReporter contains common reporting features used in the CakePHP Test suite
22
 *
23
 * @package       Cake.TestSuite.Reporter
24
 */
25
class CakeBaseReporter extends PHPUnit_TextUI_ResultPrinter {
26
 
27
/**
28
 * Headers sent
29
 *
30
 * @var boolean
31
 */
32
	protected $_headerSent = false;
33
 
34
/**
35
 * Array of request parameters. Usually parsed GET params.
36
 *
37
 * @var array
38
 */
39
	public $params = array();
40
 
41
/**
42
 * Character set for the output of test reporting.
43
 *
44
 * @var string
45
 */
46
	protected $_characterSet;
47
 
48
/**
49
 * Does nothing yet. The first output will
50
 * be sent on the first test start.
51
 *
52
 * ### Params
53
 *
54
 * - show_passes - Should passes be shown
55
 * - plugin - Plugin test being run?
56
 * - core - Core test being run.
57
 * - case - The case being run
58
 * - codeCoverage - Whether the case/group being run is being code covered.
59
 *
60
 * @param string $charset The character set to output with. Defaults to UTF-8
61
 * @param array $params Array of request parameters the reporter should use. See above.
62
 */
63
	public function __construct($charset = 'utf-8', $params = array()) {
64
		if (!$charset) {
65
			$charset = 'utf-8';
66
		}
67
		$this->_characterSet = $charset;
68
		$this->params = $params;
69
	}
70
 
71
/**
72
 * Retrieves a list of test cases from the active Manager class,
73
 * displaying it in the correct format for the reporter subclass
74
 *
75
 * @return mixed
76
 */
77
	public function testCaseList() {
78
		$testList = CakeTestLoader::generateTestList($this->params);
79
		return $testList;
80
	}
81
 
82
/**
83
 * Paints the start of the response from the test suite.
84
 * Used to paint things like head elements in an html page.
85
 *
86
 * @return void
87
 */
88
	public function paintDocumentStart() {
89
	}
90
 
91
/**
92
 * Paints the end of the response from the test suite.
93
 * Used to paint things like </body> in an html page.
94
 *
95
 * @return void
96
 */
97
	public function paintDocumentEnd() {
98
	}
99
 
100
/**
101
 * Paint a list of test sets, core, app, and plugin test sets
102
 * available.
103
 *
104
 * @return void
105
 */
106
	public function paintTestMenu() {
107
	}
108
 
109
/**
110
 * Get the baseUrl if one is available.
111
 *
112
 * @return string The base URL for the request.
113
 */
114
	public function baseUrl() {
115
		if (!empty($_SERVER['PHP_SELF'])) {
116
			return $_SERVER['PHP_SELF'];
117
		}
118
		return '';
119
	}
120
 
121
/**
122
 * Print result
123
 *
124
 * @param PHPUnit_Framework_TestResult $result
125
 */
126
	public function printResult(PHPUnit_Framework_TestResult $result) {
127
		$this->paintFooter($result);
128
	}
129
 
130
/**
131
 * Paint result
132
 *
133
 * @param PHPUnit_Framework_TestResult $result
134
 */
135
	public function paintResult(PHPUnit_Framework_TestResult $result) {
136
		$this->paintFooter($result);
137
	}
138
 
139
/**
140
 * An error occurred.
141
 *
142
 * @param  PHPUnit_Framework_Test $test
143
 * @param  Exception              $e
144
 * @param  float                  $time
145
 */
146
	public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) {
147
		$this->paintException($e, $test);
148
	}
149
 
150
/**
151
 * A failure occurred.
152
 *
153
 * @param  PHPUnit_Framework_Test $test
154
 * @param  PHPUnit_Framework_AssertionFailedError $e
155
 * @param  float $time
156
 */
157
	public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) {
158
		$this->paintFail($e, $test);
159
	}
160
 
161
/**
162
 * Incomplete test.
163
 *
164
 * @param  PHPUnit_Framework_Test $test
165
 * @param  Exception $e
166
 * @param  float $time
167
 */
168
	public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) {
169
		$this->paintSkip($e, $test);
170
	}
171
 
172
/**
173
 * Skipped test.
174
 *
175
 * @param  PHPUnit_Framework_Test $test
176
 * @param  Exception $e
177
 * @param  float $time
178
 */
179
	public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) {
180
		$this->paintSkip($e, $test);
181
	}
182
 
183
/**
184
 * A test suite started.
185
 *
186
 * @param  PHPUnit_Framework_TestSuite $suite
187
 */
188
	public function startTestSuite(PHPUnit_Framework_TestSuite $suite) {
189
		if (!$this->_headerSent) {
190
			echo $this->paintHeader();
191
		}
192
		echo __d('cake_dev', 'Running  %s', $suite->getName()) . "\n";
193
	}
194
 
195
/**
196
 * A test suite ended.
197
 *
198
 * @param  PHPUnit_Framework_TestSuite $suite
199
 */
200
	public function endTestSuite(PHPUnit_Framework_TestSuite $suite) {
201
	}
202
 
203
/**
204
 * A test started.
205
 *
206
 * @param  PHPUnit_Framework_Test $test
207
 */
208
	public function startTest(PHPUnit_Framework_Test $test) {
209
	}
210
 
211
/**
212
 * A test ended.
213
 *
214
 * @param  PHPUnit_Framework_Test $test
215
 * @param  float $time
216
 */
217
	public function endTest(PHPUnit_Framework_Test $test, $time) {
218
		$this->numAssertions += $test->getNumAssertions();
219
		if ($test->hasFailed()) {
220
			return;
221
		}
222
		$this->paintPass($test, $time);
223
	}
224
 
225
}