1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
<?php
/**
* @package SimpleTest
* @subpackage Extensions
*/
/**#@+
* include additional coverage files
*/
require_once dirname(__FILE__) .'/coverage_calculator.php';
require_once dirname(__FILE__) .'/coverage_utils.php';
require_once dirname(__FILE__) .'/simple_coverage_writer.php';
/**#@-*/
/**
* Take aggregated coverage data and generate reports from it using smarty
* templates
* @package SimpleTest
* @subpackage Extensions
*/
class CoverageReporter {
var $coverage;
var $untouched;
var $reportDir;
var $title = 'Coverage';
var $writer;
var $calculator;
function __construct() {
$this->writer = new SimpleCoverageWriter();
$this->calculator = new CoverageCalculator();
}
function generateSummaryReport($out) {
$variables = $this->calculator->variables($this->coverage, $this->untouched);
$variables['title'] = $this->title;
$report = $this->writer->writeSummary($out, $variables);
fwrite($out, $report);
}
function generate() {
CoverageUtils::mkdir($this->reportDir);
$index = $this->reportDir .'/index.html';
$hnd = fopen($index, 'w');
$this->generateSummaryReport($hnd);
fclose($hnd);
foreach ($this->coverage as $file => $cov) {
$byFile = $this->reportDir .'/'. self::reportFilename($file);
$byFileHnd = fopen($byFile, 'w');
$this->generateCoverageByFile($byFileHnd, $file, $cov);
fclose($byFileHnd);
}
echo "generated report $index\n";
}
function generateCoverageByFile($out, $file, $cov) {
$variables = $this->calculator->coverageByFileVariables($file, $cov);
$variables['title'] = $this->title .' - '. $file;
$this->writer->writeByFile($out, $variables);
}
static function reportFilename($filename) {
return preg_replace('|[/\\\\]|', '_', $filename) . '.html';
}
}
?>
|