/
CakeTextReporter.php
187 lines (167 loc) · 4.54 KB
/
CakeTextReporter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<?php
/**
* CakeTextReporter contains reporting features used for plain text based output
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @since CakePHP(tm) v 1.3
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('CakeBaseReporter', 'TestSuite/Reporter');
App::uses('TextCoverageReport', 'TestSuite/Coverage');
/**
* CakeTextReporter contains reporting features used for plain text based output
*
* @package Cake.TestSuite.Reporter
*/
class CakeTextReporter extends CakeBaseReporter {
/**
* Sets the text/plain header if the test is not a CLI test.
*
* @return void
*/
public function paintDocumentStart() {
if (!headers_sent()) {
header('Content-type: text/plain');
}
}
/**
* Paints a pass
*
* @return void
*/
public function paintPass() {
echo '.';
}
/**
* Paints a failing test.
*
* @param $message PHPUnit_Framework_AssertionFailedError $message Failure object displayed in
* the context of the other tests.
* @return void
*/
public function paintFail($message) {
$context = $message->getTrace();
$realContext = $context[3];
$context = $context[2];
printf(
"FAIL on line %s\n%s in\n%s %s()\n\n",
$context['line'], $message->toString(), $context['file'], $realContext['function']
);
}
/**
* Paints the end of the test with a summary of
* the passes and failures.
*
* @param PHPUnit_Framework_TestResult $result Result object
* @return void
*/
public function paintFooter($result) {
if ($result->failureCount() + $result->errorCount()) {
echo "FAILURES!!!\n";
} else {
echo "\nOK\n";
}
echo "Test cases run: " . $result->count() .
"/" . ($result->count() - $result->skippedCount()) .
', Passes: ' . $this->numAssertions .
', Failures: ' . $result->failureCount() .
', Exceptions: ' . $result->errorCount() . "\n";
echo 'Time: ' . $result->time() . " seconds\n";
echo 'Peak memory: ' . number_format(memory_get_peak_usage()) . " bytes\n";
if (isset($this->params['codeCoverage']) && $this->params['codeCoverage']) {
$coverage = $result->getCodeCoverage()->getSummary();
echo $this->paintCoverage($coverage);
}
}
/**
* Paints the title only.
*
* @param string $test_name Name class of test.
* @return void
*/
public function paintHeader() {
$this->paintDocumentStart();
flush();
}
/**
* Paints a PHP exception.
*
* @param Exception $exception Exception to describe.
* @return void
*/
public function paintException($exception) {
$message = 'Unexpected exception of type [' . get_class($exception) .
'] with message [' . $exception->getMessage() .
'] in [' . $exception->getFile() .
' line ' . $exception->getLine() . ']';
echo $message . "\n\n";
}
/**
* Prints the message for skipping tests.
*
* @param string $message Text of skip condition.
* @return void
*/
public function paintSkip($message) {
printf("Skip: %s\n", $message->getMessage());
}
/**
* Paints formatted text such as dumped variables.
*
* @param string $message Text to show.
* @return void
*/
public function paintFormattedMessage($message) {
echo "$message\n";
flush();
}
/**
* Generate a test case list in plain text.
* Creates as series of url's for tests that can be run.
* One case per line.
*
* @return void
*/
public function testCaseList() {
$testCases = parent::testCaseList();
$app = $this->params['app'];
$plugin = $this->params['plugin'];
$buffer = "Core Test Cases:\n";
$urlExtra = '';
if ($app) {
$buffer = "App Test Cases:\n";
$urlExtra = '&app=true';
} elseif ($plugin) {
$buffer = Inflector::humanize($plugin) . " Test Cases:\n";
$urlExtra = '&plugin=' . $plugin;
}
if (1 > count($testCases)) {
$buffer .= "EMPTY";
echo $buffer;
}
foreach ($testCases as $testCaseFile => $testCase) {
$buffer .= $_SERVER['SERVER_NAME'] . $this->baseUrl() . "?case=" . $testCase . "&output=text\n";
}
$buffer .= "\n";
echo $buffer;
}
/**
* Generates a Text summary of the coverage data.
*
* @param array $coverage Array of coverage data.
* @return string
*/
public function paintCoverage($coverage) {
$reporter = new TextCoverageReport($coverage, $this);
echo $reporter->report();
}
}