| 1 |
lars |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* PHPUnit
|
|
|
4 |
*
|
|
|
5 |
* Copyright (c) 2002-2010, Sebastian Bergmann <sb@sebastian-bergmann.de>.
|
|
|
6 |
* All rights reserved.
|
|
|
7 |
*
|
|
|
8 |
* Redistribution and use in source and binary forms, with or without
|
|
|
9 |
* modification, are permitted provided that the following conditions
|
|
|
10 |
* are met:
|
|
|
11 |
*
|
|
|
12 |
* * Redistributions of source code must retain the above copyright
|
|
|
13 |
* notice, this list of conditions and the following disclaimer.
|
|
|
14 |
*
|
|
|
15 |
* * Redistributions in binary form must reproduce the above copyright
|
|
|
16 |
* notice, this list of conditions and the following disclaimer in
|
|
|
17 |
* the documentation and/or other materials provided with the
|
|
|
18 |
* distribution.
|
|
|
19 |
*
|
|
|
20 |
* * Neither the name of Sebastian Bergmann nor the names of his
|
|
|
21 |
* contributors may be used to endorse or promote products derived
|
|
|
22 |
* from this software without specific prior written permission.
|
|
|
23 |
*
|
|
|
24 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
25 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
26 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
27 |
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
28 |
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
29 |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
30 |
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
31 |
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
32 |
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
33 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
34 |
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
35 |
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
36 |
*
|
|
|
37 |
* @category Testing
|
|
|
38 |
* @package PHPUnit
|
|
|
39 |
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
|
|
|
40 |
* @copyright 2002-2010 Sebastian Bergmann <sb@sebastian-bergmann.de>
|
|
|
41 |
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
|
|
42 |
* @link http://www.phpunit.de/
|
|
|
43 |
* @since File available since Release 3.0.0
|
|
|
44 |
*/
|
|
|
45 |
|
|
|
46 |
require_once 'PHPUnit/Framework.php';
|
|
|
47 |
require_once 'PHPUnit/Util/CodeCoverage.php';
|
|
|
48 |
require_once 'PHPUnit/Util/Filter.php';
|
|
|
49 |
require_once 'PHPUnit/Util/Filesystem.php';
|
|
|
50 |
require_once 'PHPUnit/Util/Report/Node/Directory.php';
|
|
|
51 |
require_once 'PHPUnit/Util/Report/Node/File.php';
|
|
|
52 |
|
|
|
53 |
PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT');
|
|
|
54 |
|
|
|
55 |
/**
|
|
|
56 |
*
|
|
|
57 |
*
|
|
|
58 |
* @category Testing
|
|
|
59 |
* @package PHPUnit
|
|
|
60 |
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
|
|
|
61 |
* @copyright 2002-2010 Sebastian Bergmann <sb@sebastian-bergmann.de>
|
|
|
62 |
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
|
|
63 |
* @version Release: 3.4.15
|
|
|
64 |
* @link http://www.phpunit.de/
|
|
|
65 |
* @since Class available since Release 3.0.0
|
|
|
66 |
*/
|
|
|
67 |
abstract class PHPUnit_Util_Report
|
|
|
68 |
{
|
|
|
69 |
public static $templatePath;
|
|
|
70 |
|
|
|
71 |
/**
|
|
|
72 |
* Renders the report.
|
|
|
73 |
*
|
|
|
74 |
* @param PHPUnit_Framework_TestResult $result
|
|
|
75 |
* @param string $title
|
|
|
76 |
* @param string $target
|
|
|
77 |
* @param string $charset
|
|
|
78 |
* @param boolean $yui
|
|
|
79 |
* @param boolean $highlight
|
|
|
80 |
* @param integer $lowUpperBound
|
|
|
81 |
* @param integer $highLowerBound
|
|
|
82 |
*/
|
|
|
83 |
public static function render(PHPUnit_Framework_TestResult $result, $target, $title = '', $charset = 'ISO-8859-1', $yui = TRUE, $highlight = FALSE, $lowUpperBound = 35, $highLowerBound = 70)
|
|
|
84 |
{
|
|
|
85 |
$target = PHPUnit_Util_Filesystem::getDirectory($target);
|
|
|
86 |
|
|
|
87 |
self::$templatePath = sprintf(
|
|
|
88 |
'%s%sReport%sTemplate%s',
|
|
|
89 |
|
|
|
90 |
dirname(__FILE__),
|
|
|
91 |
DIRECTORY_SEPARATOR,
|
|
|
92 |
DIRECTORY_SEPARATOR,
|
|
|
93 |
DIRECTORY_SEPARATOR
|
|
|
94 |
);
|
|
|
95 |
|
|
|
96 |
$codeCoverageInformation = $result->getCodeCoverageInformation();
|
|
|
97 |
$files = PHPUnit_Util_CodeCoverage::getSummary(
|
|
|
98 |
$codeCoverageInformation
|
|
|
99 |
);
|
|
|
100 |
$commonPath = PHPUnit_Util_Filesystem::reducePaths($files);
|
|
|
101 |
$items = self::buildDirectoryStructure($files);
|
|
|
102 |
|
|
|
103 |
unset($codeCoverageInformation);
|
|
|
104 |
|
|
|
105 |
if ($title == '') {
|
|
|
106 |
$topTestSuite = $result->topTestSuite();
|
|
|
107 |
|
|
|
108 |
if ($topTestSuite instanceof PHPUnit_Framework_TestSuite) {
|
|
|
109 |
$title = $topTestSuite->getName();
|
|
|
110 |
}
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
unset($result);
|
|
|
114 |
|
|
|
115 |
$root = new PHPUnit_Util_Report_Node_Directory($commonPath, NULL);
|
|
|
116 |
|
|
|
117 |
self::addItems($root, $items, $files, $yui, $highlight);
|
|
|
118 |
self::copyFiles($target);
|
|
|
119 |
|
|
|
120 |
PHPUnit_Util_CodeCoverage::clearSummary();
|
|
|
121 |
|
|
|
122 |
$root->render(
|
|
|
123 |
$target,
|
|
|
124 |
$title,
|
|
|
125 |
$charset,
|
|
|
126 |
$lowUpperBound,
|
|
|
127 |
$highLowerBound
|
|
|
128 |
);
|
|
|
129 |
}
|
|
|
130 |
|
|
|
131 |
/**
|
|
|
132 |
* @param PHPUnit_Util_Report_Node_Directory $root
|
|
|
133 |
* @param array $items
|
|
|
134 |
* @param array $files
|
|
|
135 |
* @param boolean $yui
|
|
|
136 |
* @param boolean $highlight
|
|
|
137 |
*/
|
|
|
138 |
protected static function addItems(PHPUnit_Util_Report_Node_Directory $root, array $items, array $files, $yui, $highlight)
|
|
|
139 |
{
|
|
|
140 |
foreach ($items as $key => $value) {
|
|
|
141 |
if (substr($key, -2) == '/f') {
|
|
|
142 |
try {
|
|
|
143 |
$file = $root->addFile(
|
|
|
144 |
substr($key, 0, -2), $value, $yui, $highlight
|
|
|
145 |
);
|
|
|
146 |
}
|
|
|
147 |
|
|
|
148 |
catch (RuntimeException $e) {
|
|
|
149 |
continue;
|
|
|
150 |
}
|
|
|
151 |
} else {
|
|
|
152 |
$child = $root->addDirectory($key);
|
|
|
153 |
self::addItems($child, $value, $files, $yui, $highlight);
|
|
|
154 |
}
|
|
|
155 |
}
|
|
|
156 |
}
|
|
|
157 |
|
|
|
158 |
/**
|
|
|
159 |
* Builds an array representation of the directory structure.
|
|
|
160 |
*
|
|
|
161 |
* For instance,
|
|
|
162 |
*
|
|
|
163 |
* <code>
|
|
|
164 |
* Array
|
|
|
165 |
* (
|
|
|
166 |
* [Money.php] => Array
|
|
|
167 |
* (
|
|
|
168 |
* ...
|
|
|
169 |
* )
|
|
|
170 |
*
|
|
|
171 |
* [MoneyBag.php] => Array
|
|
|
172 |
* (
|
|
|
173 |
* ...
|
|
|
174 |
* )
|
|
|
175 |
* )
|
|
|
176 |
* </code>
|
|
|
177 |
*
|
|
|
178 |
* is transformed into
|
|
|
179 |
*
|
|
|
180 |
* <code>
|
|
|
181 |
* Array
|
|
|
182 |
* (
|
|
|
183 |
* [.] => Array
|
|
|
184 |
* (
|
|
|
185 |
* [Money.php] => Array
|
|
|
186 |
* (
|
|
|
187 |
* ...
|
|
|
188 |
* )
|
|
|
189 |
*
|
|
|
190 |
* [MoneyBag.php] => Array
|
|
|
191 |
* (
|
|
|
192 |
* ...
|
|
|
193 |
* )
|
|
|
194 |
* )
|
|
|
195 |
* )
|
|
|
196 |
* </code>
|
|
|
197 |
*
|
|
|
198 |
* @param array $files
|
|
|
199 |
* @return array
|
|
|
200 |
*/
|
|
|
201 |
protected static function buildDirectoryStructure($files)
|
|
|
202 |
{
|
|
|
203 |
$result = array();
|
|
|
204 |
|
|
|
205 |
foreach ($files as $path => $file) {
|
|
|
206 |
$path = explode('/', $path);
|
|
|
207 |
$pointer = &$result;
|
|
|
208 |
$max = count($path);
|
|
|
209 |
|
|
|
210 |
for ($i = 0; $i < $max; $i++) {
|
|
|
211 |
if ($i == ($max - 1)) {
|
|
|
212 |
$type = '/f';
|
|
|
213 |
} else {
|
|
|
214 |
$type = '';
|
|
|
215 |
}
|
|
|
216 |
|
|
|
217 |
$pointer = &$pointer[$path[$i] . $type];
|
|
|
218 |
}
|
|
|
219 |
|
|
|
220 |
$pointer = $file;
|
|
|
221 |
}
|
|
|
222 |
|
|
|
223 |
return $result;
|
|
|
224 |
}
|
|
|
225 |
|
|
|
226 |
/**
|
|
|
227 |
* @param string $target
|
|
|
228 |
*/
|
|
|
229 |
protected static function copyFiles($target)
|
|
|
230 |
{
|
|
|
231 |
$files = array(
|
|
|
232 |
'butter.png',
|
|
|
233 |
'chameleon.png',
|
|
|
234 |
'close12_1.gif',
|
|
|
235 |
'container.css',
|
|
|
236 |
'container-min.js',
|
|
|
237 |
'glass.png',
|
|
|
238 |
'scarlet_red.png',
|
|
|
239 |
'snow.png',
|
|
|
240 |
'style.css',
|
|
|
241 |
'yahoo-dom-event.js'
|
|
|
242 |
);
|
|
|
243 |
|
|
|
244 |
foreach ($files as $file) {
|
|
|
245 |
copy(self::$templatePath . $file, $target . $file);
|
|
|
246 |
}
|
|
|
247 |
}
|
|
|
248 |
}
|
|
|
249 |
?>
|