5 * Copyright (c) 2002-2009, Sebastian Bergmann <sb@sebastian-bergmann.de>.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
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
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.
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.
39 * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
40 * @copyright 2002-2009 Sebastian Bergmann <sb@sebastian-bergmann.de>
41 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
43 * @link http://www.phpunit.de/
44 * @since File available since Release 3.0.0
47 require_once 'PHPUnit/Framework.php';
48 require_once 'PHPUnit/Util/CodeCoverage.php';
49 require_once 'PHPUnit/Util/Filter.php';
50 require_once 'PHPUnit/Util/Filesystem.php';
51 require_once 'PHPUnit/Util/Report/Node/Directory.php';
52 require_once 'PHPUnit/Util/Report/Node/File.php';
54 PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT');
61 * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
62 * @copyright 2002-2009 Sebastian Bergmann <sb@sebastian-bergmann.de>
63 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
64 * @version Release: 3.3.17
65 * @link http://www.phpunit.de/
66 * @since Class available since Release 3.0.0
69 abstract class PHPUnit_Util_Report
71 public static $templatePath;
76 * @param PHPUnit_Framework_TestResult $result
77 * @param string $target
78 * @param string $charset
80 * @param boolean $highlight
81 * @param integer $lowUpperBound
82 * @param integer $highLowerBound
84 public static function render(PHPUnit_Framework_TestResult $result, $target, $charset = 'ISO-8859-1', $yui = TRUE, $highlight = FALSE, $lowUpperBound = 35, $highLowerBound = 70)
86 $target = PHPUnit_Util_Filesystem::getDirectory($target);
88 self::$templatePath = sprintf(
89 '%s%sReport%sTemplate%s',
97 $codeCoverageInformation = $result->getCodeCoverageInformation();
98 $files = PHPUnit_Util_CodeCoverage::getSummary($codeCoverageInformation);
99 $commonPath = PHPUnit_Util_Filesystem::reducePaths($files);
100 $items = self::buildDirectoryStructure($files);
102 unset($codeCoverageInformation);
104 $topTestSuite = $result->topTestSuite();
106 if ($topTestSuite instanceof PHPUnit_Framework_TestSuite) {
107 $name = $topTestSuite->getName();
112 $root = new PHPUnit_Util_Report_Node_Directory($commonPath, NULL);
114 self::addItems($root, $items, $files, $yui, $highlight);
115 self::copyFiles($target);
117 PHPUnit_Util_CodeCoverage::clearSummary();
129 * @param PHPUnit_Util_Report_Node_Directory $root
130 * @param array $items
131 * @param array $files
132 * @param boolean $yui
133 * @param boolean $highlight
135 protected static function addItems(PHPUnit_Util_Report_Node_Directory $root, array $items, array $files, $yui, $highlight)
137 foreach ($items as $key => $value) {
138 if (substr($key, -2) == '/f') {
140 $file = $root->addFile(
141 substr($key, 0, -2), $value, $yui, $highlight
145 catch (RuntimeException $e) {
149 $child = $root->addDirectory($key);
150 self::addItems($child, $value, $files, $yui, $highlight);
156 * Builds an array representation of the directory structure.
163 * [Money.php] => Array
168 * [MoneyBag.php] => Array
175 * is transformed into
182 * [Money.php] => Array
187 * [MoneyBag.php] => Array
195 * @param array $files
198 protected static function buildDirectoryStructure($files)
202 foreach ($files as $path => $file) {
203 $path = explode('/', $path);
207 for ($i = 0; $i < $max; $i++) {
208 if ($i == ($max - 1)) {
214 $pointer = &$pointer[$path[$i] . $type];
224 * @param string $target
226 protected static function copyFiles($target)
241 foreach ($files as $file) {
242 copy(self::$templatePath . $file, $target . $file);