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.2.0
47 require_once 'PHPUnit/Util/Filter.php';
48 require_once 'PHPUnit/Util/Filesystem.php';
49 require_once 'PHPUnit/Util/Template.php';
50 require_once 'PHPUnit/Util/Report/Node.php';
51 require_once 'PHPUnit/Util/Report/Node/File.php';
53 PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT');
56 * Represents a directory in the code coverage information tree.
60 * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
61 * @copyright 2002-2009 Sebastian Bergmann <sb@sebastian-bergmann.de>
62 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
63 * @version Release: 3.3.17
64 * @link http://www.phpunit.de/
65 * @since Class available since Release 3.2.0
67 class PHPUnit_Util_Report_Node_Directory extends PHPUnit_Util_Report_Node
70 * @var PHPUnit_Util_Report_Node[]
72 protected $children = array();
75 * @var PHPUnit_Util_Report_Node_Directory[]
77 protected $directories = array();
80 * @var PHPUnit_Util_Report_Node_File[]
82 protected $files = array();
92 protected $numExecutableLines = -1;
97 protected $numExecutedLines = -1;
102 protected $numClasses = -1;
107 protected $numCalledClasses = -1;
112 protected $numMethods = -1;
117 protected $numCalledMethods = -1;
120 * Adds a new directory.
122 * @return PHPUnit_Util_Report_Node_Directory
124 public function addDirectory($name)
126 $directory = new PHPUnit_Util_Report_Node_Directory($name, $this);
128 $this->children[] = $directory;
129 $this->directories[] = &$this->children[count($this->children) - 1];
137 * @param string $name
138 * @param array $lines
139 * @param boolean $yui
140 * @param boolean $highlight
141 * @return PHPUnit_Util_Report_Node_File
142 * @throws RuntimeException
144 public function addFile($name, array $lines, $yui, $highlight)
146 $file = new PHPUnit_Util_Report_Node_File(
147 $name, $this, $lines, $yui, $highlight
150 $this->children[] = $file;
151 $this->files[] = &$this->children[count($this->children) - 1];
153 $this->numExecutableLines = -1;
154 $this->numExecutedLines = -1;
160 * Returns the directories in this directory.
164 public function getDirectories()
166 return $this->directories;
170 * Returns the files in this directory.
174 public function getFiles()
180 * Returns the classes of this node.
184 public function getClasses()
186 if ($this->classes === NULL) {
187 $this->classes = array();
189 foreach ($this->children as $child) {
190 $this->classes = array_merge($this->classes, $child->getClasses());
194 return $this->classes;
198 * Returns the number of executable lines.
202 public function getNumExecutableLines()
204 if ($this->numExecutableLines == -1) {
205 $this->numExecutableLines = 0;
207 foreach ($this->children as $child) {
208 $this->numExecutableLines += $child->getNumExecutableLines();
212 return $this->numExecutableLines;
216 * Returns the number of executed lines.
220 public function getNumExecutedLines()
222 if ($this->numExecutedLines == -1) {
223 $this->numExecutedLines = 0;
225 foreach ($this->children as $child) {
226 $this->numExecutedLines += $child->getNumExecutedLines();
230 return $this->numExecutedLines;
234 * Returns the number of classes.
238 public function getNumClasses()
240 if ($this->numClasses == -1) {
241 $this->numClasses = 0;
243 foreach ($this->children as $child) {
244 $this->numClasses += $child->getNumClasses();
248 return $this->numClasses;
252 * Returns the number of classes of which at least one method
253 * has been called at least once.
257 public function getNumCalledClasses()
259 if ($this->numCalledClasses == -1) {
260 $this->numCalledClasses = 0;
262 foreach ($this->children as $child) {
263 $this->numCalledClasses += $child->getNumCalledClasses();
267 return $this->numCalledClasses;
271 * Returns the number of methods.
275 public function getNumMethods()
277 if ($this->numMethods == -1) {
278 $this->numMethods = 0;
280 foreach ($this->children as $child) {
281 $this->numMethods += $child->getNumMethods();
285 return $this->numMethods;
289 * Returns the number of methods that has been called at least once.
293 public function getNumCalledMethods()
295 if ($this->numCalledMethods == -1) {
296 $this->numCalledMethods = 0;
298 foreach ($this->children as $child) {
299 $this->numCalledMethods += $child->getNumCalledMethods();
303 return $this->numCalledMethods;
309 * @param string $target
310 * @param string $title
311 * @param string $charset
312 * @param integer $lowUpperBound
313 * @param integer $highLowerBound
315 public function render($target, $title, $charset = 'ISO-8859-1', $lowUpperBound = 35, $highLowerBound = 70)
318 $target, $title, $charset, $lowUpperBound, $highLowerBound
321 foreach ($this->children as $child) {
323 $target, $title, $charset, $lowUpperBound, $highLowerBound
327 $this->children = array();
331 * @param string $target
332 * @param string $title
333 * @param string $charset
334 * @param integer $lowUpperBound
335 * @param integer $highLowerBound
337 protected function doRender($target, $title, $charset, $lowUpperBound, $highLowerBound)
339 $cleanId = PHPUnit_Util_Filesystem::getSafeFilename($this->getId());
340 $file = $target . $cleanId . '.html';
342 $template = new PHPUnit_Util_Template(
343 PHPUnit_Util_Report::$templatePath . 'directory.html'
346 $this->setTemplateVars($template, $title, $charset);
350 'total_item' => $this->renderTotalItem($lowUpperBound, $highLowerBound),
351 'items' => $this->renderItems($lowUpperBound, $highLowerBound),
352 'low_upper_bound' => $lowUpperBound,
353 'high_lower_bound' => $highLowerBound
357 $template->renderTo($file);
359 $this->directories = array();
360 $this->files = array();
364 * @param float $lowUpperBound
365 * @param float $highLowerBound
368 protected function renderItems($lowUpperBound, $highLowerBound)
370 $items = $this->doRenderItems($this->directories, $lowUpperBound, $highLowerBound, 'coverDirectory');
371 $items .= $this->doRenderItems($this->files, $lowUpperBound, $highLowerBound, 'coverFile');
377 * @param array $items
378 * @param float $lowUpperBound
379 * @param float $highLowerBound
380 * @param string $itemClass
383 protected function doRenderItems(array $items, $lowUpperBound, $highLowerBound, $itemClass)
387 foreach ($items as $item) {
388 $result .= $this->doRenderItemObject($item, $lowUpperBound, $highLowerBound, NULL, $itemClass);