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/2.0/en/development/testing.html>
8: * Copyright 2005-2012, 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-2012, 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: * Does nothing yet. The first output will
45: * be sent on the first test start.
46: *
47: * ### Params
48: *
49: * - show_passes - Should passes be shown
50: * - plugin - Plugin test being run?
51: * - core - Core test being run.
52: * - case - The case being run
53: * - codeCoverage - Whether the case/group being run is being code covered.
54: *
55: * @param string $charset The character set to output with. Defaults to UTF-8
56: * @param array $params Array of request parameters the reporter should use. See above.
57: */
58: public function __construct($charset = 'utf-8', $params = array()) {
59: if (!$charset) {
60: $charset = 'utf-8';
61: }
62: $this->_characterSet = $charset;
63: $this->params = $params;
64: }
65:
66: /**
67: * Retrieves a list of test cases from the active Manager class,
68: * displaying it in the correct format for the reporter subclass
69: *
70: * @return mixed
71: */
72: public function testCaseList() {
73: $testList = CakeTestLoader::generateTestList($this->params);
74: return $testList;
75: }
76:
77: /**
78: * Paints the start of the response from the test suite.
79: * Used to paint things like head elements in an html page.
80: *
81: * @return void
82: */
83: public function paintDocumentStart() {
84: }
85:
86: /**
87: * Paints the end of the response from the test suite.
88: * Used to paint things like </body> in an html page.
89: *
90: * @return void
91: */
92: public function paintDocumentEnd() {
93: }
94:
95: /**
96: * Paint a list of test sets, core, app, and plugin test sets
97: * available.
98: *
99: * @return void
100: */
101: public function paintTestMenu() {
102: }
103:
104: /**
105: * Get the baseUrl if one is available.
106: *
107: * @return string The base url for the request.
108: */
109: public function baseUrl() {
110: if (!empty($_SERVER['PHP_SELF'])) {
111: return $_SERVER['PHP_SELF'];
112: }
113: return '';
114: }
115:
116: public function printResult(PHPUnit_Framework_TestResult $result) {
117: $this->paintFooter($result);
118: }
119:
120: public function paintResult(PHPUnit_Framework_TestResult $result) {
121: $this->paintFooter($result);
122: }
123:
124: /**
125: * An error occurred.
126: *
127: * @param PHPUnit_Framework_Test $test
128: * @param Exception $e
129: * @param float $time
130: */
131: public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) {
132: $this->paintException($e, $test);
133: }
134:
135: /**
136: * A failure occurred.
137: *
138: * @param PHPUnit_Framework_Test $test
139: * @param PHPUnit_Framework_AssertionFailedError $e
140: * @param float $time
141: */
142: public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) {
143: $this->paintFail($e, $test);
144: }
145:
146: /**
147: * Incomplete test.
148: *
149: * @param PHPUnit_Framework_Test $test
150: * @param Exception $e
151: * @param float $time
152: */
153: public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) {
154: $this->paintSkip($e, $test);
155: }
156:
157: /**
158: * Skipped test.
159: *
160: * @param PHPUnit_Framework_Test $test
161: * @param Exception $e
162: * @param float $time
163: */
164: public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) {
165: $this->paintSkip($e, $test);
166: }
167:
168: /**
169: * A test suite started.
170: *
171: * @param PHPUnit_Framework_TestSuite $suite
172: */
173: public function startTestSuite(PHPUnit_Framework_TestSuite $suite) {
174: if (!$this->_headerSent) {
175: echo $this->paintHeader();
176: }
177: echo __d('cake_dev', 'Running %s', $suite->getName()) . "\n";
178: }
179:
180: /**
181: * A test suite ended.
182: *
183: * @param PHPUnit_Framework_TestSuite $suite
184: */
185: public function endTestSuite(PHPUnit_Framework_TestSuite $suite) {
186: }
187:
188: /**
189: * A test started.
190: *
191: * @param PHPUnit_Framework_Test $test
192: */
193: public function startTest(PHPUnit_Framework_Test $test) {
194: }
195:
196: /**
197: * A test ended.
198: *
199: * @param PHPUnit_Framework_Test $test
200: * @param float $time
201: */
202: public function endTest(PHPUnit_Framework_Test $test, $time) {
203: $this->numAssertions += $test->getNumAssertions();
204: $this->paintPass($test, $time);
205: }
206:
207: }
208: