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/File.php';
48
require_once 'PHPUnit/Util/Filesystem.php';
49
require_once 'PHPUnit/Util/Template.php';
50
require_once 'PHPUnit/Util/Report/Node.php';
51
 
52
PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT');
53
 
54
/**
55
 *
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_File extends PHPUnit_Util_Report_Node
67
{
68
    /**
69
     * @var    array
70
     */
71
    protected $codeLines;
72
 
73
    /**
74
     * @var    array
75
     */
76
    protected $codeLinesFillup = array();
77
 
78
    /**
79
     * @var    array
80
     */
81
    protected $executedLines;
82
 
83
    /**
84
     * @var    boolean
85
     */
86
    protected $yui = TRUE;
87
 
88
    /**
89
     * @var    boolean
90
     */
91
    protected $highlight = FALSE;
92
 
93
    /**
94
     * @var    integer
95
     */
96
    protected $numExecutableLines = 0;
97
 
98
    /**
99
     * @var    integer
100
     */
101
    protected $numExecutedLines = 0;
102
 
103
    /**
104
     * @var    array
105
     */
106
    protected $classes = array();
107
 
108
    /**
109
     * @var    integer
110
     */
111
    protected $numClasses = 0;
112
 
113
    /**
114
     * @var    integer
115
     */
116
    protected $numTestedClasses = 0;
117
 
118
    /**
119
     * @var    integer
120
     */
121
    protected $numMethods = 0;
122
 
123
    /**
124
     * @var    integer
125
     */
126
    protected $numTestedMethods = 0;
127
 
128
    /**
129
     * @var    string
130
     */
131
    protected $yuiPanelJS = '';
132
 
133
    /**
134
     * @var    array
135
     */
136
    protected $startLines = array();
137
 
138
    /**
139
     * @var    array
140
     */
141
    protected $endLines = array();
142
 
143
    /**
144
     * Constructor.
145
     *
146
     * @param  string                   $name
147
     * @param  PHPUnit_Util_Report_Node $parent
148
     * @param  array                    $executedLines
149
     * @param  boolean                  $yui
150
     * @param  boolean                  $highlight
151
     * @throws RuntimeException
152
     */
153
    public function __construct($name, PHPUnit_Util_Report_Node $parent = NULL, array $executedLines, $yui = TRUE, $highlight = FALSE)
154
    {
155
        parent::__construct($name, $parent);
156
 
157
        $path = $this->getPath();
158
 
159
        if (!file_exists($path)) {
160
            throw new PHPUnit_Framework_Exception(
161
              sprintf('Path "%s" does not exist.', $path)
162
            );
163
        }
164
 
165
        $this->executedLines = $executedLines;
166
        $this->highlight     = $highlight;
167
        $this->yui           = $yui;
168
        $this->codeLines     = $this->loadFile($path);
169
 
170
        $this->calculateStatistics();
171
    }
172
 
173
    /**
174
     * Returns the classes of this node.
175
     *
176
     * @return array
177
     */
178
    public function getClasses()
179
    {
180
        return $this->classes;
181
    }
182
 
183
    /**
184
     * Returns the number of executable lines.
185
     *
186
     * @return integer
187
     */
188
    public function getNumExecutableLines()
189
    {
190
        return $this->numExecutableLines;
191
    }
192
 
193
    /**
194
     * Returns the number of executed lines.
195
     *
196
     * @return integer
197
     */
198
    public function getNumExecutedLines()
199
    {
200
        return $this->numExecutedLines;
201
    }
202
 
203
    /**
204
     * Returns the number of classes.
205
     *
206
     * @return integer
207
     */
208
    public function getNumClasses()
209
    {
210
        return $this->numClasses;
211
    }
212
 
213
    /**
214
     * Returns the number of tested classes.
215
     *
216
     * @return integer
217
     */
218
    public function getNumTestedClasses()
219
    {
220
        return $this->numTestedClasses;
221
    }
222
 
223
    /**
224
     * Returns the number of methods.
225
     *
226
     * @return integer
227
     */
228
    public function getNumMethods()
229
    {
230
        return $this->numMethods;
231
    }
232
 
233
    /**
234
     * Returns the number of tested methods.
235
     *
236
     * @return integer
237
     */
238
    public function getNumTestedMethods()
239
    {
240
        return $this->numTestedMethods;
241
    }
242
 
243
    /**
244
     * Renders this node.
245
     *
246
     * @param string  $target
247
     * @param string  $title
248
     * @param string  $charset
249
     * @param integer $lowUpperBound
250
     * @param integer $highLowerBound
251
     */
252
    public function render($target, $title, $charset = 'ISO-8859-1', $lowUpperBound = 35, $highLowerBound = 70)
253
    {
254
        if ($this->yui) {
255
            $template = new PHPUnit_Util_Template(
256
              PHPUnit_Util_Report::$templatePath . 'file.html'
257
            );
258
 
259
            $yuiTemplate = new PHPUnit_Util_Template(
260
              PHPUnit_Util_Report::$templatePath . 'yui_item.js'
261
            );
262
        } else {
263
            $template = new PHPUnit_Util_Template(
264
              PHPUnit_Util_Report::$templatePath . 'file_no_yui.html'
265
            );
266
        }
267
 
268
        $i      = 1;
269
        $lines  = '';
270
        $ignore = FALSE;
271
 
272
        foreach ($this->codeLines as $line) {
273
            if (strpos($line, '@codeCoverageIgnoreStart') !== FALSE) {
274
                $ignore = TRUE;
275
            }
276
 
277
            else if (strpos($line, '@codeCoverageIgnoreEnd') !== FALSE) {
278
                $ignore = FALSE;
279
            }
280
 
281
            $css = '';
282
 
283
            if (!$ignore && isset($this->executedLines[$i])) {
284
                $count = '';
285
 
286
                // Array: Line is executable and was executed.
287
                // count(Array) = Number of tests that hit this line.
288
                if (is_array($this->executedLines[$i])) {
289
                    $color    = 'lineCov';
290
                    $numTests = count($this->executedLines[$i]);
291
                    $count    = sprintf('%8d', $numTests);
292
 
293
                    if ($this->yui) {
294
                        $buffer  = '';
295
                        $testCSS = '';
296
 
297
                        foreach ($this->executedLines[$i] as $test) {
298
                            if (!isset($test->__liHtml)) {
299
                                $test->__liHtml = '';
300
 
301
                                if ($test instanceof PHPUnit_Framework_SelfDescribing) {
302
                                    $testName = $test->toString();
303
 
304
                                    if ($test instanceof PHPUnit_Framework_TestCase) {
305
                                        switch ($test->getStatus()) {
306
                                            case PHPUnit_Runner_BaseTestRunner::STATUS_PASSED: {
307
                                                $testCSS = ' class=\"testPassed\"';
308
                                            }
309
                                            break;
310
 
311
                                            case PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE: {
312
                                                $testCSS = ' class=\"testFailure\"';
313
                                            }
314
                                            break;
315
 
316
                                            case PHPUnit_Runner_BaseTestRunner::STATUS_ERROR: {
317
                                                $testCSS = ' class=\"testError\"';
318
                                            }
319
                                            break;
320
 
321
                                            case PHPUnit_Runner_BaseTestRunner::STATUS_INCOMPLETE:
322
                                            case PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED: {
323
                                                $testCSS = ' class=\"testIncomplete\"';
324
                                            }
325
                                            break;
326
 
327
                                            default: {
328
                                                $testCSS = '';
329
                                            }
330
                                        }
331
                                    }
332
                                }
333
 
334
                                $test->__liHtml .= sprintf(
335
                                  '<li%s>%s</li>',
336
 
337
                                  $testCSS,
338
                                  addslashes(htmlspecialchars($testName))
339
                                );
340
                            }
341
 
342
                            $buffer .= $test->__liHtml;
343
                        }
344
 
345
                        if ($numTests > 1) {
346
                            $header = $numTests . ' tests cover';
347
                        } else {
348
                            $header = '1 test covers';
349
                        }
350
 
351
                        $header .= ' line ' . $i;
352
 
353
                        $yuiTemplate->setVar(
354
                          array(
355
                            'line'   => $i,
356
                            'header' => $header,
357
                            'tests'  => $buffer
358
                          ),
359
                          FALSE
360
                        );
361
 
362
                        $this->yuiPanelJS .= $yuiTemplate->render();
363
                    }
364
                }
365
 
366
                // -1: Line is executable and was not executed.
367
                else if ($this->executedLines[$i] == -1) {
368
                    $color = 'lineNoCov';
369
                    $count = sprintf('%8d', 0);
370
                }
371
 
372
                // -2: Line is dead code.
373
                else {
374
                    $color = 'lineDeadCode';
375
                    $count = '        ';
376
                }
377
 
378
                $css = sprintf(
379
                  '<span class="%s">       %s : ',
380
 
381
                  $color,
382
                  $count
383
                );
384
            }
385
 
386
            $fillup = array_shift($this->codeLinesFillup);
387
 
388
            if ($fillup > 0) {
389
                $line .= str_repeat(' ', $fillup);
390
            }
391
 
392
            $lines .= sprintf(
393
              '<span class="lineNum" id="container%d"><a name="%d"></a><a href="#%d" id="line%d">%8d</a> </span>%s%s%s' . "\n",
394
 
395
              $i,
396
              $i,
397
              $i,
398
              $i,
399
              $i,
400
              !empty($css) ? $css : '                : ',
401
              !$this->highlight ? htmlspecialchars($line) : $line,
402
              !empty($css) ? '</span>' : ''
403
            );
404
 
405
            $i++;
406
        }
407
 
408
        $items = '';
409
 
410
        foreach ($this->classes as $className => $classData) {
411
            if ($classData['executedLines'] == $classData['executableLines']) {
412
                $numTestedClasses     = 1;
413
                $testedClassesPercent = 100;
414
            } else {
415
                $numTestedClasses     = 0;
416
                $testedClassesPercent = 0;
417
            }
418
 
419
            $numTestedMethods = 0;
420
            $numMethods       = count($classData['methods']);
421
 
422
            foreach ($classData['methods'] as $method) {
423
                if ($method['executedLines'] == $method['executableLines']) {
424
                    $numTestedMethods++;
425
                }
426
            }
427
 
428
            $items .= $this->doRenderItem(
429
              array(
430
                'name'                 => sprintf(
431
                  '<b><a href="#%d">%s</a></b>',
432
 
433
                  $classData['startLine'],
434
                  $className
435
                ),
436
                'numClasses'           => 1,
437
                'numTestedClasses'     => $numTestedClasses,
438
                'testedClassesPercent' => sprintf('%01.2f', $testedClassesPercent),
439
                'numMethods'           => $numMethods,
440
                'numTestedMethods'     => $numTestedMethods,
441
                'testedMethodsPercent' => $this->calculatePercent(
442
                  $numTestedMethods, $numMethods
443
                ),
444
                'numExecutableLines'   => $classData['executableLines'],
445
                'numExecutedLines'     => $classData['executedLines'],
446
                'executedLinesPercent' => $this->calculatePercent(
447
                  $classData['executedLines'], $classData['executableLines']
448
                )
449
              ),
450
              $lowUpperBound,
451
              $highLowerBound
452
            );
453
 
454
            foreach ($classData['methods'] as $methodName => $methodData) {
455
                if ($methodData['executedLines'] == $methodData['executableLines']) {
456
                    $numTestedMethods     = 1;
457
                    $testedMethodsPercent = 100;
458
                } else {
459
                    $numTestedMethods     = 0;
460
                    $testedMethodsPercent = 0;
461
                }
462
 
463
                $items .= $this->doRenderItem(
464
                  array(
465
                    'name'                 => sprintf(
466
                      '&nbsp;<a href="#%d">%s</a>',
467
 
468
                      $methodData['startLine'],
469
                      htmlspecialchars($methodData['signature'])
470
                    ),
471
                    'numClasses'           => '',
472
                    'numTestedClasses'     => '',
473
                    'testedClassesPercent' => '',
474
                    'numMethods'           => 1,
475
                    'numTestedMethods'     => $numTestedMethods,
476
                    'testedMethodsPercent' => sprintf('%01.2f', $testedMethodsPercent),
477
                    'numExecutableLines'   => $methodData['executableLines'],
478
                    'numExecutedLines'     => $methodData['executedLines'],
479
                    'executedLinesPercent' => $this->calculatePercent(
480
                      $methodData['executedLines'], $methodData['executableLines']
481
                    )
482
                  ),
483
                  $lowUpperBound,
484
                  $highLowerBound,
485
                  'method_item.html'
486
                );
487
            }
488
        }
489
 
490
        $this->setTemplateVars($template, $title, $charset);
491
 
492
        $template->setVar(
493
          array(
494
            'lines'      => $lines,
495
            'total_item' => $this->renderTotalItem($lowUpperBound, $highLowerBound, FALSE),
496
            'items'      => $items,
497
            'yuiPanelJS' => $this->yuiPanelJS
498
          )
499
        );
500
 
501
        $cleanId = PHPUnit_Util_Filesystem::getSafeFilename($this->getId());
502
        $template->renderTo($target . $cleanId . '.html');
503
 
504
        $this->yuiPanelJS    = '';
505
        $this->executedLines = array();
506
    }
507
 
508
    /**
509
     * Calculates coverage statistics for the file.
510
     *
511
     */
512
    protected function calculateStatistics()
513
    {
514
        $this->processClasses();
515
        $this->processFunctions();
516
 
517
        $ignoreStart = -1;
518
        $lineNumber  = 1;
519
 
520
        foreach ($this->codeLines as $line) {
521
            if (isset($this->startLines[$lineNumber])) {
522
                // Start line of a class.
523
                if (isset($this->startLines[$lineNumber]['methods'])) {
524
                    $currentClass = &$this->startLines[$lineNumber];
525
                }
526
 
527
                // Start line of a method.
528
                else {
529
                    $currentMethod = &$this->startLines[$lineNumber];
530
                }
531
            }
532
 
533
            if (strpos($line, '@codeCoverageIgnore') !== FALSE) {
534
                if (strpos($line, '@codeCoverageIgnoreStart') !== FALSE) {
535
                    $ignoreStart = $lineNumber;
536
                }
537
 
538
                else if (strpos($line, '@codeCoverageIgnoreEnd') !== FALSE) {
539
                    $ignoreStart = -1;
540
                }
541
            }
542
 
543
            if (isset($this->executedLines[$lineNumber])) {
544
                // Array: Line is executable and was executed.
545
                if (is_array($this->executedLines[$lineNumber])) {
546
                    if (isset($currentClass)) {
547
                        $currentClass['executableLines']++;
548
                        $currentClass['executedLines']++;
549
                    }
550
 
551
                    if (isset($currentMethod)) {
552
                        $currentMethod['executableLines']++;
553
                        $currentMethod['executedLines']++;
554
                    }
555
 
556
                    $this->numExecutableLines++;
557
                    $this->numExecutedLines++;
558
                }
559
 
560
                // -1: Line is executable and was not executed.
561
                else if ($this->executedLines[$lineNumber] == -1) {
562
                    if (isset($currentClass)) {
563
                        $currentClass['executableLines']++;
564
                    }
565
 
566
                    if (isset($currentMethod)) {
567
                        $currentMethod['executableLines']++;
568
                    }
569
 
570
                    $this->numExecutableLines++;
571
 
572
                    if ($ignoreStart != -1 && $lineNumber > $ignoreStart) {
573
                        if (isset($currentClass)) {
574
                            $currentClass['executedLines']++;
575
                        }
576
 
577
                        if (isset($currentMethod)) {
578
                            $currentMethod['executedLines']++;
579
                        }
580
 
581
                        $this->numExecutedLines++;
582
                    }
583
                }
584
            }
585
 
586
            if (isset($this->endLines[$lineNumber])) {
587
                // End line of a class.
588
                if (isset($this->endLines[$lineNumber]['methods'])) {
589
                    unset($currentClass);
590
                }
591
 
592
                // End line of a method.
593
                else {
594
                    unset($currentMethod);
595
                }
596
            }
597
 
598
            $lineNumber++;
599
        }
600
 
601
        foreach ($this->classes as $className => $class) {
602
            foreach ($class['methods'] as $method) {
603
                if ($method['executedLines'] == $method['executableLines']) {
604
                    $this->numTestedMethods++;
605
                }
606
            }
607
 
608
            if ($className != '*') {
609
                if ($class['executedLines'] == $class['executableLines']) {
610
                    $this->numTestedClasses++;
611
                }
612
            }
613
        }
614
    }
615
 
616
    /**
617
     * @author Aidan Lister <aidan@php.net>
618
     * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
619
     * @param  string  $file
620
     * @return array
621
     */
622
    protected function loadFile($file)
623
    {
624
        $lines  = explode("\n", str_replace("\t", '    ', file_get_contents($file)));
625
        $result = array();
626
 
627
        if (count($lines) == 0) {
628
            return $result;
629
        }
630
 
631
        $lines       = array_map('rtrim', $lines);
632
        $linesLength = array_map('strlen', $lines);
633
        $width       = max($linesLength);
634
 
635
        foreach ($linesLength as $line => $length) {
636
            $this->codeLinesFillup[$line] = $width - $length;
637
        }
638
 
639
        if (!$this->highlight) {
640
            unset($lines[count($lines)-1]);
641
            return $lines;
642
        }
643
 
644
        $tokens     = token_get_all(file_get_contents($file));
645
        $stringFlag = FALSE;
646
        $i          = 0;
647
        $result[$i] = '';
648
 
649
        foreach ($tokens as $j => $token) {
650
            if (is_string($token)) {
651
                if ($token === '"' && $tokens[$j - 1] !== '\\') {
652
                    $result[$i] .= sprintf(
653
                      '<span class="string">%s</span>',
654
 
655
                      htmlspecialchars($token)
656
                    );
657
 
658
                    $stringFlag = !$stringFlag;
659
                } else {
660
                    $result[$i] .= sprintf(
661
                      '<span class="keyword">%s</span>',
662
 
663
                      htmlspecialchars($token)
664
                    );
665
                }
666
 
667
                continue;
668
            }
669
 
670
            list ($token, $value) = $token;
671
 
672
            $value = str_replace(
673
              array("\t", ' '),
674
              array('&nbsp;&nbsp;&nbsp;&nbsp;', '&nbsp;'),
675
              htmlspecialchars($value)
676
            );
677
 
678
            if ($value === "\n") {
679
                $result[++$i] = '';
680
            } else {
681
                $lines = explode("\n", $value);
682
 
683
                foreach ($lines as $jj => $line) {
684
                    $line = trim($line);
685
 
686
                    if ($line !== '') {
687
                        if ($stringFlag) {
688
                            $colour = 'string';
689
                        } else {
690
                            switch ($token) {
691
                                case T_INLINE_HTML: {
692
                                    $colour = 'html';
693
                                }
694
                                break;
695
 
696
                                case T_COMMENT:
697
                                case T_DOC_COMMENT: {
698
                                    $colour = 'comment';
699
                                }
700
                                break;
701
 
702
                                case T_ABSTRACT:
703
                                case T_ARRAY:
704
                                case T_ARRAY_CAST:
705
                                case T_AS:
706
                                case T_BOOLEAN_AND:
707
                                case T_BOOLEAN_OR:
708
                                case T_BOOL_CAST:
709
                                case T_BREAK:
710
                                case T_CASE:
711
                                case T_CATCH:
712
                                case T_CLASS:
713
                                case T_CLONE:
714
                                case T_CONCAT_EQUAL:
715
                                case T_CONTINUE:
716
                                case T_DEFAULT:
717
                                case T_DOUBLE_ARROW:
718
                                case T_DOUBLE_CAST:
719
                                case T_ECHO:
720
                                case T_ELSE:
721
                                case T_ELSEIF:
722
                                case T_EMPTY:
723
                                case T_ENDDECLARE:
724
                                case T_ENDFOR:
725
                                case T_ENDFOREACH:
726
                                case T_ENDIF:
727
                                case T_ENDSWITCH:
728
                                case T_ENDWHILE:
729
                                case T_END_HEREDOC:
730
                                case T_EXIT:
731
                                case T_EXTENDS:
732
                                case T_FINAL:
733
                                case T_FOREACH:
734
                                case T_FUNCTION:
735
                                case T_GLOBAL:
736
                                case T_IF:
737
                                case T_INC:
738
                                case T_INCLUDE:
739
                                case T_INCLUDE_ONCE:
740
                                case T_INSTANCEOF:
741
                                case T_INT_CAST:
742
                                case T_ISSET:
743
                                case T_IS_EQUAL:
744
                                case T_IS_IDENTICAL:
745
                                case T_IS_NOT_IDENTICAL:
746
                                case T_IS_SMALLER_OR_EQUAL:
747
                                case T_NEW:
748
                                case T_OBJECT_CAST:
749
                                case T_OBJECT_OPERATOR:
750
                                case T_PAAMAYIM_NEKUDOTAYIM:
751
                                case T_PRIVATE:
752
                                case T_PROTECTED:
753
                                case T_PUBLIC:
754
                                case T_REQUIRE:
755
                                case T_REQUIRE_ONCE:
756
                                case T_RETURN:
757
                                case T_SL:
758
                                case T_SL_EQUAL:
759
                                case T_SR:
760
                                case T_SR_EQUAL:
761
                                case T_START_HEREDOC:
762
                                case T_STATIC:
763
                                case T_STRING_CAST:
764
                                case T_THROW:
765
                                case T_TRY:
766
                                case T_UNSET_CAST:
767
                                case T_VAR:
768
                                case T_WHILE: {
769
                                    $colour = 'keyword';
770
                                }
771
                                break;
772
 
773
                                default: {
774
                                    $colour = 'default';
775
                                }
776
                            }
777
                        }
778
 
779
                        $result[$i] .= sprintf(
780
                          '<span class="%s">%s</span>',
781
 
782
                          $colour,
783
                          $line
784
                        );
785
                    }
786
 
787
                    if (isset($lines[$jj + 1])) {
788
                        $result[++$i] = '';
789
                    }
790
                }
791
            }
792
        }
793
 
794
        unset($result[count($result)-1]);
795
 
796
        return $result;
797
    }
798
 
799
    protected function processClasses()
800
    {
801
        $classes = PHPUnit_Util_File::getClassesInFile($this->getPath());
802
 
803
        foreach ($classes as $className => $class) {
804
            $this->classes[$className] = array(
805
              'methods'         => array(),
806
              'startLine'       => $class['startLine'],
807
              'executableLines' => 0,
808
              'executedLines'   => 0
809
            );
810
 
811
            $this->startLines[$class['startLine']] = &$this->classes[$className];
812
            $this->endLines[$class['endLine']]     = &$this->classes[$className];
813
 
814
            foreach ($class['methods'] as $methodName => $method) {
815
                $this->classes[$className]['methods'][$methodName] = array(
816
                  'signature'       => $method['signature'],
817
                  'startLine'       => $method['startLine'],
818
                  'executableLines' => 0,
819
                  'executedLines'   => 0
820
                );
821
 
822
                $this->startLines[$method['startLine']] = &$this->classes[$className]['methods'][$methodName];
823
                $this->endLines[$method['endLine']]     = &$this->classes[$className]['methods'][$methodName];
824
 
825
                $this->numMethods++;
826
            }
827
 
828
            $this->numClasses++;
829
        }
830
    }
831
 
832
    protected function processFunctions()
833
    {
834
        $functions = PHPUnit_Util_File::getFunctionsInFile($this->getPath());
835
 
836
        if (count($functions) > 0 && !isset($this->classes['*'])) {
837
            $this->classes['*'] = array(
838
              'methods'         => array(),
839
              'startLine'       => 0,
840
              'executableLines' => 0,
841
              'executedLines'   => 0
842
            );
843
        }
844
 
845
        foreach ($functions as $functionName => $function) {
846
            $this->classes['*']['methods'][$functionName] = array(
847
              'signature'       => $function['signature'],
848
              'startLine'       => $function['startLine'],
849
              'executableLines' => 0,
850
              'executedLines'   => 0
851
            );
852
 
853
            $this->startLines[$function['startLine']] = &$this->classes['*']['methods'][$functionName];
854
            $this->endLines[$function['endLine']]     = &$this->classes['*']['methods'][$functionName];
855
 
856
            $this->numMethods++;
857
        }
858
    }
859
}
860
?>