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