1: <?php
2: /**
3: * CakeBaseReporter contains common functionality to all cake test suite reporters.
4: *
5: * PHP 5
6: *
7: * CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
8: * Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
9: *
10: * Licensed under The MIT License
11: * Redistributions of files must retain the above copyright notice
12: *
13: * @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
14: * @link http://cakephp.org CakePHP(tm) Project
15: * @since CakePHP(tm) v 1.3
16: * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
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: protected $_headerSent = false;
28:
29: /**
30: * Array of request parameters. Usually parsed GET params.
31: *
32: * @var array
33: */
34: public $params = array();
35:
36: /**
37: * Character set for the output of test reporting.
38: *
39: * @var string
40: */
41: protected $_characterSet;
42:
43: /**
44: * The number of assertions done for a test suite
45: */
46: protected $numAssertions = 0;
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: * - app - App 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: 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: /**
93: * Paints the end of the response from the test suite.
94: * Used to paint things like </body> in an html page.
95: *
96: * @return void
97: */
98: public function paintDocumentEnd() {
99:
100: }
101:
102: /**
103: * Paint a list of test sets, core, app, and plugin test sets
104: * available.
105: *
106: * @return void
107: */
108: public function paintTestMenu() {
109:
110: }
111:
112: /**
113: * Get the baseUrl if one is available.
114: *
115: * @return string The base url for the request.
116: */
117: public function baseUrl() {
118: if (!empty($_SERVER['PHP_SELF'])) {
119: return $_SERVER['PHP_SELF'];
120: }
121: return '';
122: }
123:
124: public function printResult(PHPUnit_Framework_TestResult $result) {
125: $this->paintFooter($result);
126: }
127:
128: public function paintResult(PHPUnit_Framework_TestResult $result) {
129: $this->paintFooter($result);
130: }
131:
132: /**
133: * An error occurred.
134: *
135: * @param PHPUnit_Framework_Test $test
136: * @param Exception $e
137: * @param float $time
138: */
139: public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) {
140: $this->paintException($e, $test);
141: }
142:
143: /**
144: * A failure occurred.
145: *
146: * @param PHPUnit_Framework_Test $test
147: * @param PHPUnit_Framework_AssertionFailedError $e
148: * @param float $time
149: */
150: public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) {
151: $this->paintFail($e, $test);
152: }
153:
154: /**
155: * Incomplete test.
156: *
157: * @param PHPUnit_Framework_Test $test
158: * @param Exception $e
159: * @param float $time
160: */
161: public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) {
162: $this->paintSkip($e, $test);
163: }
164:
165: /**
166: * Skipped test.
167: *
168: * @param PHPUnit_Framework_Test $test
169: * @param Exception $e
170: * @param float $time
171: */
172: public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) {
173: $this->paintSkip($e, $test);
174: }
175:
176: /**
177: * A test suite started.
178: *
179: * @param PHPUnit_Framework_TestSuite $suite
180: */
181: public function startTestSuite(PHPUnit_Framework_TestSuite $suite) {
182: if (!$this->_headerSent) {
183: echo $this->paintHeader();
184: }
185: echo __d('cake_dev', 'Running %s', $suite->getName()) . "\n";
186: }
187:
188: /**
189: * A test suite ended.
190: *
191: * @param PHPUnit_Framework_TestSuite $suite
192: */
193: public function endTestSuite(PHPUnit_Framework_TestSuite $suite) {
194: }
195:
196: /**
197: * A test started.
198: *
199: * @param PHPUnit_Framework_Test $test
200: */
201: public function startTest(PHPUnit_Framework_Test $test) {
202: }
203:
204: /**
205: * A test ended.
206: *
207: * @param PHPUnit_Framework_Test $test
208: * @param float $time
209: */
210: public function endTest(PHPUnit_Framework_Test $test, $time) {
211: $this->numAssertions += $test->getNumAssertions();
212: $this->paintPass($test, $time);
213: }
214:
215: }
216: