Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
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.2.0
44
 */
45
 
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';
51
 
52
PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT');
53
 
54
/**
55
 * Represents a directory in the code coverage information tree.
56
 *
57
 * @category   Testing
58
 * @package    PHPUnit
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.15
63
 * @link       http://www.phpunit.de/
64
 * @since      Class available since Release 3.2.0
65
 */
66
class PHPUnit_Util_Report_Node_Directory extends PHPUnit_Util_Report_Node
67
{
68
    /**
69
     * @var    PHPUnit_Util_Report_Node[]
70
     */
71
    protected $children = array();
72
 
73
    /**
74
     * @var    PHPUnit_Util_Report_Node_Directory[]
75
     */
76
    protected $directories = array();
77
 
78
    /**
79
     * @var    PHPUnit_Util_Report_Node_File[]
80
     */
81
    protected $files = array();
82
 
83
    /**
84
     * @var    array
85
     */
86
    protected $classes;
87
 
88
    /**
89
     * @var    integer
90
     */
91
    protected $numExecutableLines = -1;
92
 
93
    /**
94
     * @var    integer
95
     */
96
    protected $numExecutedLines = -1;
97
 
98
    /**
99
     * @var    integer
100
     */
101
    protected $numClasses = -1;
102
 
103
    /**
104
     * @var    integer
105
     */
106
    protected $numTestedClasses = -1;
107
 
108
    /**
109
     * @var    integer
110
     */
111
    protected $numMethods = -1;
112
 
113
    /**
114
     * @var    integer
115
     */
116
    protected $numTestedMethods = -1;
117
 
118
    /**
119
     * Adds a new directory.
120
     *
121
     * @return PHPUnit_Util_Report_Node_Directory
122
     */
123
    public function addDirectory($name)
124
    {
125
        $directory = new PHPUnit_Util_Report_Node_Directory($name, $this);
126
 
127
        $this->children[]    = $directory;
128
        $this->directories[] = &$this->children[count($this->children) - 1];
129
 
130
        return $directory;
131
    }
132
 
133
    /**
134
     * Adds a new file.
135
     *
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
142
     */
143
    public function addFile($name, array $lines, $yui, $highlight)
144
    {
145
        $file = new PHPUnit_Util_Report_Node_File(
146
          $name, $this, $lines, $yui, $highlight
147
        );
148
 
149
        $this->children[] = $file;
150
        $this->files[]    = &$this->children[count($this->children) - 1];
151
 
152
        $this->numExecutableLines = -1;
153
        $this->numExecutedLines   = -1;
154
 
155
        return $file;
156
    }
157
 
158
    /**
159
     * Returns the directories in this directory.
160
     *
161
     * @return array
162
     */
163
    public function getDirectories()
164
    {
165
        return $this->directories;
166
    }
167
 
168
    /**
169
     * Returns the files in this directory.
170
     *
171
     * @return array
172
     */
173
    public function getFiles()
174
    {
175
        return $this->files;
176
    }
177
 
178
    /**
179
     * Returns the classes of this node.
180
     *
181
     * @return array
182
     */
183
    public function getClasses()
184
    {
185
        if ($this->classes === NULL) {
186
            $this->classes = array();
187
 
188
            foreach ($this->children as $child) {
189
                $this->classes = array_merge($this->classes, $child->getClasses());
190
            }
191
        }
192
 
193
        return $this->classes;
194
    }
195
 
196
    /**
197
     * Returns the number of executable lines.
198
     *
199
     * @return integer
200
     */
201
    public function getNumExecutableLines()
202
    {
203
        if ($this->numExecutableLines == -1) {
204
            $this->numExecutableLines = 0;
205
 
206
            foreach ($this->children as $child) {
207
                $this->numExecutableLines += $child->getNumExecutableLines();
208
            }
209
        }
210
 
211
        return $this->numExecutableLines;
212
    }
213
 
214
    /**
215
     * Returns the number of executed lines.
216
     *
217
     * @return integer
218
     */
219
    public function getNumExecutedLines()
220
    {
221
        if ($this->numExecutedLines == -1) {
222
            $this->numExecutedLines = 0;
223
 
224
            foreach ($this->children as $child) {
225
                $this->numExecutedLines += $child->getNumExecutedLines();
226
            }
227
        }
228
 
229
        return $this->numExecutedLines;
230
    }
231
 
232
    /**
233
     * Returns the number of classes.
234
     *
235
     * @return integer
236
     */
237
    public function getNumClasses()
238
    {
239
        if ($this->numClasses == -1) {
240
            $this->numClasses = 0;
241
 
242
            foreach ($this->children as $child) {
243
                $this->numClasses += $child->getNumClasses();
244
            }
245
        }
246
 
247
        return $this->numClasses;
248
    }
249
 
250
    /**
251
     * Returns the number of tested classes.
252
     *
253
     * @return integer
254
     */
255
    public function getNumTestedClasses()
256
    {
257
        if ($this->numTestedClasses == -1) {
258
            $this->numTestedClasses = 0;
259
 
260
            foreach ($this->children as $child) {
261
                $this->numTestedClasses += $child->getNumTestedClasses();
262
            }
263
        }
264
 
265
        return $this->numTestedClasses;
266
    }
267
 
268
    /**
269
     * Returns the number of methods.
270
     *
271
     * @return integer
272
     */
273
    public function getNumMethods()
274
    {
275
        if ($this->numMethods == -1) {
276
            $this->numMethods = 0;
277
 
278
            foreach ($this->children as $child) {
279
                $this->numMethods += $child->getNumMethods();
280
            }
281
        }
282
 
283
        return $this->numMethods;
284
    }
285
 
286
    /**
287
     * Returns the number of tested methods.
288
     *
289
     * @return integer
290
     */
291
    public function getNumTestedMethods()
292
    {
293
        if ($this->numTestedMethods == -1) {
294
            $this->numTestedMethods = 0;
295
 
296
            foreach ($this->children as $child) {
297
                $this->numTestedMethods += $child->getNumTestedMethods();
298
            }
299
        }
300
 
301
        return $this->numTestedMethods;
302
    }
303
 
304
    /**
305
     * Renders this node.
306
     *
307
     * @param string  $target
308
     * @param string  $title
309
     * @param string  $charset
310
     * @param integer $lowUpperBound
311
     * @param integer $highLowerBound
312
     */
313
    public function render($target, $title, $charset = 'ISO-8859-1', $lowUpperBound = 35, $highLowerBound = 70)
314
    {
315
        $this->doRender(
316
          $target, $title, $charset, $lowUpperBound, $highLowerBound
317
        );
318
 
319
        foreach ($this->children as $child) {
320
            $child->render(
321
              $target, $title, $charset, $lowUpperBound, $highLowerBound
322
            );
323
        }
324
 
325
        $this->children = array();
326
    }
327
 
328
    /**
329
     * @param string  $target
330
     * @param string  $title
331
     * @param string  $charset
332
     * @param integer $lowUpperBound
333
     * @param integer $highLowerBound
334
     */
335
    protected function doRender($target, $title, $charset, $lowUpperBound, $highLowerBound)
336
    {
337
        $cleanId = PHPUnit_Util_Filesystem::getSafeFilename($this->getId());
338
        $file    = $target . $cleanId . '.html';
339
 
340
        $template = new PHPUnit_Util_Template(
341
          PHPUnit_Util_Report::$templatePath . 'directory.html'
342
        );
343
 
344
        $this->setTemplateVars($template, $title, $charset);
345
 
346
        $template->setVar(
347
          array(
348
            'total_item'       => $this->renderTotalItem($lowUpperBound, $highLowerBound),
349
            'items'            => $this->renderItems($lowUpperBound, $highLowerBound),
350
            'low_upper_bound'  => $lowUpperBound,
351
            'high_lower_bound' => $highLowerBound
352
          )
353
        );
354
 
355
        $template->renderTo($file);
356
 
357
        $this->directories = array();
358
        $this->files       = array();
359
    }
360
 
361
    /**
362
     * @param  float  $lowUpperBound
363
     * @param  float  $highLowerBound
364
     * @return string
365
     */
366
    protected function renderItems($lowUpperBound, $highLowerBound)
367
    {
368
        $items  = $this->doRenderItems($this->directories, $lowUpperBound, $highLowerBound, 'coverDirectory');
369
        $items .= $this->doRenderItems($this->files, $lowUpperBound, $highLowerBound, 'coverFile');
370
 
371
        return $items;
372
    }
373
 
374
    /**
375
     * @param  array  $items
376
     * @param  float  $lowUpperBound
377
     * @param  float  $highLowerBound
378
     * @param  string $itemClass
379
     * @return string
380
     */
381
    protected function doRenderItems(array $items, $lowUpperBound, $highLowerBound, $itemClass)
382
    {
383
        $result = '';
384
 
385
        foreach ($items as $item) {
386
            $result .= $this->doRenderItemObject($item, $lowUpperBound, $highLowerBound, NULL, $itemClass);
387
        }
388
 
389
        return $result;
390
    }
391
}
392
?>