5
* Copyright (c) 2002-2010, 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-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.2.0
46
require_once 'PHPUnit/Util/Filter.php';
47
require_once 'PHPUnit/Util/Filesystem.php';
48
require_once 'PHPUnit/Util/Template.php';
49
require_once 'PHPUnit/Util/Report/Node.php';
50
require_once 'PHPUnit/Util/Report/Node/File.php';
52
PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT');
55
* Represents a directory in the code coverage information tree.
59
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
60
* @copyright 2002-2010 Sebastian Bergmann <sb@sebastian-bergmann.de>
61
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
62
* @version Release: 3.4.14
63
* @link http://www.phpunit.de/
64
* @since Class available since Release 3.2.0
66
class PHPUnit_Util_Report_Node_Directory extends PHPUnit_Util_Report_Node
69
* @var PHPUnit_Util_Report_Node[]
71
protected $children = array();
74
* @var PHPUnit_Util_Report_Node_Directory[]
76
protected $directories = array();
79
* @var PHPUnit_Util_Report_Node_File[]
81
protected $files = array();
91
protected $numExecutableLines = -1;
96
protected $numExecutedLines = -1;
101
protected $numClasses = -1;
106
protected $numTestedClasses = -1;
111
protected $numMethods = -1;
116
protected $numTestedMethods = -1;
119
* Adds a new directory.
121
* @return PHPUnit_Util_Report_Node_Directory
123
public function addDirectory($name)
125
$directory = new PHPUnit_Util_Report_Node_Directory($name, $this);
127
$this->children[] = $directory;
128
$this->directories[] = &$this->children[count($this->children) - 1];
136
* @param string $name
137
* @param array $lines
138
* @param boolean $yui
139
* @param boolean $highlight
140
* @return PHPUnit_Util_Report_Node_File
141
* @throws RuntimeException
143
public function addFile($name, array $lines, $yui, $highlight)
145
$file = new PHPUnit_Util_Report_Node_File(
146
$name, $this, $lines, $yui, $highlight
149
$this->children[] = $file;
150
$this->files[] = &$this->children[count($this->children) - 1];
152
$this->numExecutableLines = -1;
153
$this->numExecutedLines = -1;
159
* Returns the directories in this directory.
163
public function getDirectories()
165
return $this->directories;
169
* Returns the files in this directory.
173
public function getFiles()
179
* Returns the classes of this node.
183
public function getClasses()
185
if ($this->classes === NULL) {
186
$this->classes = array();
188
foreach ($this->children as $child) {
189
$this->classes = array_merge($this->classes, $child->getClasses());
193
return $this->classes;
197
* Returns the number of executable lines.
201
public function getNumExecutableLines()
203
if ($this->numExecutableLines == -1) {
204
$this->numExecutableLines = 0;
206
foreach ($this->children as $child) {
207
$this->numExecutableLines += $child->getNumExecutableLines();
211
return $this->numExecutableLines;
215
* Returns the number of executed lines.
219
public function getNumExecutedLines()
221
if ($this->numExecutedLines == -1) {
222
$this->numExecutedLines = 0;
224
foreach ($this->children as $child) {
225
$this->numExecutedLines += $child->getNumExecutedLines();
229
return $this->numExecutedLines;
233
* Returns the number of classes.
237
public function getNumClasses()
239
if ($this->numClasses == -1) {
240
$this->numClasses = 0;
242
foreach ($this->children as $child) {
243
$this->numClasses += $child->getNumClasses();
247
return $this->numClasses;
251
* Returns the number of tested classes.
255
public function getNumTestedClasses()
257
if ($this->numTestedClasses == -1) {
258
$this->numTestedClasses = 0;
260
foreach ($this->children as $child) {
261
$this->numTestedClasses += $child->getNumTestedClasses();
265
return $this->numTestedClasses;
269
* Returns the number of methods.
273
public function getNumMethods()
275
if ($this->numMethods == -1) {
276
$this->numMethods = 0;
278
foreach ($this->children as $child) {
279
$this->numMethods += $child->getNumMethods();
283
return $this->numMethods;
287
* Returns the number of tested methods.
291
public function getNumTestedMethods()
293
if ($this->numTestedMethods == -1) {
294
$this->numTestedMethods = 0;
296
foreach ($this->children as $child) {
297
$this->numTestedMethods += $child->getNumTestedMethods();
301
return $this->numTestedMethods;
307
* @param string $target
308
* @param string $title
309
* @param string $charset
310
* @param integer $lowUpperBound
311
* @param integer $highLowerBound
313
public function render($target, $title, $charset = 'ISO-8859-1', $lowUpperBound = 35, $highLowerBound = 70)
316
$target, $title, $charset, $lowUpperBound, $highLowerBound
319
foreach ($this->children as $child) {
321
$target, $title, $charset, $lowUpperBound, $highLowerBound
325
$this->children = array();
329
* @param string $target
330
* @param string $title
331
* @param string $charset
332
* @param integer $lowUpperBound
333
* @param integer $highLowerBound
335
protected function doRender($target, $title, $charset, $lowUpperBound, $highLowerBound)
337
$cleanId = PHPUnit_Util_Filesystem::getSafeFilename($this->getId());
338
$file = $target . $cleanId . '.html';
340
$template = new PHPUnit_Util_Template(
341
PHPUnit_Util_Report::$templatePath . 'directory.html'
344
$this->setTemplateVars($template, $title, $charset);
348
'total_item' => $this->renderTotalItem($lowUpperBound, $highLowerBound),
349
'items' => $this->renderItems($lowUpperBound, $highLowerBound),
350
'low_upper_bound' => $lowUpperBound,
351
'high_lower_bound' => $highLowerBound
355
$template->renderTo($file);
357
$this->directories = array();
358
$this->files = array();
362
* @param float $lowUpperBound
363
* @param float $highLowerBound
366
protected function renderItems($lowUpperBound, $highLowerBound)
368
$items = $this->doRenderItems($this->directories, $lowUpperBound, $highLowerBound, 'coverDirectory');
369
$items .= $this->doRenderItems($this->files, $lowUpperBound, $highLowerBound, 'coverFile');
375
* @param array $items
376
* @param float $lowUpperBound
377
* @param float $highLowerBound
378
* @param string $itemClass
381
protected function doRenderItems(array $items, $lowUpperBound, $highLowerBound, $itemClass)
385
foreach ($items as $item) {
386
$result .= $this->doRenderItemObject($item, $lowUpperBound, $highLowerBound, NULL, $itemClass);
b'\\ No newline at end of file'