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() == 0) {
75: echo "\nOK\n";
76: } else {
77: echo "FAILURES!!!\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:
101: public function paintHeader() {
102: $this->paintDocumentStart();
103: flush();
104: }
105:
106: 107: 108: 109: 110: 111:
112: public function paintException($exception) {
113: $message = 'Unexpected exception of type [' . get_class($exception) .
114: '] with message [' . $exception->getMessage() .
115: '] in [' . $exception->getFile() .
116: ' line ' . $exception->getLine() . ']';
117: echo $message . "\n\n";
118: }
119:
120: 121: 122: 123: 124: 125:
126: public function paintSkip($message) {
127: printf("Skip: %s\n", $message->getMessage());
128: }
129:
130: 131: 132: 133: 134: 135:
136: public function paintFormattedMessage($message) {
137: echo "$message\n";
138: flush();
139: }
140:
141: 142: 143: 144: 145: 146: 147:
148: public function testCaseList() {
149: $testCases = parent::testCaseList();
150: $app = $this->params['app'];
151: $plugin = $this->params['plugin'];
152:
153: $buffer = "Core Test Cases:\n";
154: $urlExtra = '';
155: if ($app) {
156: $buffer = "App Test Cases:\n";
157: $urlExtra = '&app=true';
158: } elseif ($plugin) {
159: $buffer = Inflector::humanize($plugin) . " Test Cases:\n";
160: $urlExtra = '&plugin=' . $plugin;
161: }
162:
163: if (1 > count($testCases)) {
164: $buffer .= "EMPTY";
165: echo $buffer;
166: }
167:
168: foreach ($testCases as $testCaseFile => $testCase) {
169: $buffer .= $_SERVER['SERVER_NAME'] . $this->baseUrl() . "?case=" . $testCase . "&output=text\n";
170: }
171:
172: $buffer .= "\n";
173: echo $buffer;
174: }
175:
176: 177: 178: 179: 180: 181:
182: public function paintCoverage($coverage) {
183: $reporter = new TextCoverageReport($coverage, $this);
184: echo $reporter->report();
185: }
186:
187: }
188: