1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18:
19:
20: App::uses('CakeBaseReporter', 'TestSuite/Reporter');
21: App::uses('TextCoverageReport', 'TestSuite/Coverage');
22:
23: 24: 25: 26: 27:
28: class CakeTextReporter extends CakeBaseReporter {
29:
30: 31: 32: 33: 34:
35: public function paintDocumentStart() {
36: if (!headers_sent()) {
37: header('Content-type: text/plain');
38: }
39: }
40:
41: 42: 43: 44: 45:
46: public function paintPass() {
47: echo '.';
48: }
49:
50: 51: 52: 53: 54: 55: 56:
57: public function paintFail($message) {
58: $context = $message->getTrace();
59: $realContext = $context[3];
60: $context = $context[2];
61:
62: printf(
63: "FAIL on line %s\n%s in\n%s %s()\n\n",
64: $context['line'], $message->toString(), $context['file'], $realContext['function']
65: );
66: }
67:
68: 69: 70: 71: 72: 73: 74:
75: public function paintFooter($result) {
76: if ($result->failureCount() + $result->errorCount()) {
77: echo "FAILURES!!!\n";
78: } else {
79: echo "\nOK\n";
80: }
81:
82: echo "Test cases run: " . $result->count() .
83: "/" . ($result->count() - $result->skippedCount()) .
84: ', Passes: ' . $this->numAssertions .
85: ', Failures: ' . $result->failureCount() .
86: ', Exceptions: ' . $result->errorCount() . "\n";
87:
88: echo 'Time: ' . $result->time() . " seconds\n";
89: echo 'Peak memory: ' . number_format(memory_get_peak_usage()) . " bytes\n";
90:
91: if (isset($this->params['codeCoverage']) && $this->params['codeCoverage']) {
92: $coverage = $result->getCodeCoverage()->getSummary();
93: echo $this->paintCoverage($coverage);
94: }
95: }
96:
97: 98: 99: 100: 101:
102: public function paintHeader() {
103: $this->paintDocumentStart();
104: flush();
105: }
106:
107: 108: 109: 110: 111: 112:
113: public function paintException($exception) {
114: $message = 'Unexpected exception of type [' . get_class($exception) .
115: '] with message [' . $exception->getMessage() .
116: '] in [' . $exception->getFile() .
117: ' line ' . $exception->getLine() . ']';
118: echo $message . "\n\n";
119: }
120:
121: 122: 123: 124: 125: 126:
127: public function paintSkip($message) {
128: printf("Skip: %s\n", $message->getMessage());
129: }
130:
131: 132: 133: 134: 135: 136:
137: public function paintFormattedMessage($message) {
138: echo "$message\n";
139: flush();
140: }
141:
142: 143: 144: 145: 146: 147: 148:
149: public function testCaseList() {
150: $testCases = parent::testCaseList();
151: $app = $this->params['app'];
152: $plugin = $this->params['plugin'];
153:
154: $buffer = "Core Test Cases:\n";
155: $urlExtra = '';
156: if ($app) {
157: $buffer = "App Test Cases:\n";
158: $urlExtra = '&app=true';
159: } elseif ($plugin) {
160: $buffer = Inflector::humanize($plugin) . " Test Cases:\n";
161: $urlExtra = '&plugin=' . $plugin;
162: }
163:
164: if (1 > count($testCases)) {
165: $buffer .= 'EMPTY';
166: echo $buffer;
167: }
168:
169: foreach ($testCases as $testCase) {
170: $buffer .= $_SERVER['SERVER_NAME'] . $this->baseUrl() . "?case=" . $testCase . "&output=text\n";
171: }
172:
173: $buffer .= "\n";
174: echo $buffer;
175: }
176:
177: 178: 179: 180: 181: 182:
183: public function paintCoverage($coverage) {
184: $reporter = new TextCoverageReport($coverage, $this);
185: echo $reporter->report();
186: }
187:
188: }
189: