Skip to content

Commit 849efd8

Browse files
committed
work in progress (Report Factory and wrappers)
1 parent 6d1b3f2 commit 849efd8

9 files changed

Lines changed: 568 additions & 0 deletions

File tree

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
/**
3+
* Code Coverage Clover Report
4+
*
5+
* @copyright 2013 Anthon Pang
6+
* @license BSD-3-Clause
7+
*/
8+
9+
namespace VIPSoft\CodeCoverageCommon\Report;
10+
11+
use VIPSoft\CodeCoverageCommon\ReportInterface;
12+
13+
/**
14+
* Clover report
15+
*
16+
* @author Anthon Pang <apang@softwaredevelopment.ca>
17+
*/
18+
class Clover implements ReportInterface
19+
{
20+
/**
21+
* @var \PHP_CodeCoverage_Report_Clover
22+
*/
23+
private $report;
24+
25+
/**
26+
* @var array
27+
*/
28+
private $options;
29+
30+
/**
31+
* {@inheritdoc}
32+
*/
33+
public function __construct(array $options)
34+
{
35+
if ( ! isset($options['target'])) {
36+
$options['target'] = null;
37+
}
38+
39+
if ( ! isset($options['name'])) {
40+
$options['name'] = null;
41+
}
42+
43+
$this->report = new \PHP_CodeCoverage_Report_Clover();
44+
$this->options = $options;
45+
}
46+
47+
/**
48+
* {@inheritdoc}
49+
*/
50+
public function process(\PHP_CodeCoverage $coverage)
51+
{
52+
return $this->report(
53+
$coverage,
54+
$options['target'],
55+
$options['name']
56+
);
57+
}
58+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
/**
3+
* Code Coverage Crap4j Report
4+
*
5+
* @copyright 2013 Anthon Pang
6+
* @license BSD-3-Clause
7+
*/
8+
9+
namespace VIPSoft\CodeCoverageCommon\Report;
10+
11+
use VIPSoft\CodeCoverageCommon\ReportInterface;
12+
13+
/**
14+
* Crap4j report
15+
*
16+
* @author Anthon Pang <apang@softwaredevelopment.ca>
17+
*/
18+
class Crap4j implements ReportInterface
19+
{
20+
/**
21+
* @var \PHP_CodeCoverage_Report_Crap4j
22+
*/
23+
private $report;
24+
25+
/**
26+
* @var array
27+
*/
28+
private $options;
29+
30+
/**
31+
* {@inheritdoc}
32+
*/
33+
public function __construct(array $options)
34+
{
35+
if ( ! class_exists('\PHP_CodeCoverage_Report_Crap4j')) {
36+
throw new \Exception('Crap4j requires PHP_CodeCoverage 1.3+');
37+
}
38+
39+
if ( ! isset($options['target'])) {
40+
$options['target'] = null;
41+
}
42+
43+
if ( ! isset($options['name'])) {
44+
$options['name'] = null;
45+
}
46+
47+
$this->report = new \PHP_CodeCoverage_Report_Crap4j();
48+
$this->options = $options;
49+
}
50+
51+
/**
52+
* {@inheritdoc}
53+
*/
54+
public function process(\PHP_CodeCoverage $coverage)
55+
{
56+
return $this->report(
57+
$coverage,
58+
$options['target'],
59+
$options['name']
60+
);
61+
}
62+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
/**
3+
* Code Coverage Report Factory
4+
*
5+
* @copyright 2013 Anthon Pang
6+
* @license BSD-3-Clause
7+
*/
8+
9+
namespace VIPSoft\CodeCoverageCommon\Report;
10+
11+
/**
12+
* Code coverage report factory
13+
*
14+
* @author Anthon Pang <apang@softwaredevelopment.ca>
15+
*/
16+
class Factory
17+
{
18+
/**
19+
* Creation method
20+
*
21+
* @param string $reportType
22+
* @param array $options
23+
*
24+
* @return \VIPSoft\CodeCoverageCommon\ReportInterface|null
25+
*/
26+
public function create($reportType, $options)
27+
{
28+
if (in_array($reportType, array('clover', 'crap4j', 'html', 'php', 'text', 'xml'))) {
29+
$className = '\VIPSoft\CodeCoverageCommon\Report\\' . ucfirst($reportType);
30+
31+
return new $className($options);
32+
}
33+
34+
return null;
35+
}
36+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
/**
3+
* Code Coverage HTML Report
4+
*
5+
* @copyright 2013 Anthon Pang
6+
* @license BSD-3-Clause
7+
*/
8+
9+
namespace VIPSoft\CodeCoverageCommon\Report;
10+
11+
use VIPSoft\CodeCoverageCommon\ReportInterface;
12+
13+
/**
14+
* HTML report
15+
*
16+
* @author Anthon Pang <apang@softwaredevelopment.ca>
17+
*/
18+
class Html implements ReportInterface
19+
{
20+
/**
21+
* @var \PHP_CodeCoverage_Report_HTML
22+
*/
23+
private $report;
24+
25+
/**
26+
* @var array
27+
*/
28+
private $options;
29+
30+
/**
31+
* {@inheritdoc}
32+
*/
33+
public function __construct(array $options)
34+
{
35+
if ( ! isset($options['target'])) {
36+
$options['target'] = null;
37+
}
38+
39+
if ( ! isset($options['charset'])) {
40+
$options['charset'] = 'UTF-8';
41+
}
42+
43+
if ( ! isset($options['highlight'])) {
44+
$options['highlight'] = false;
45+
}
46+
47+
if ( ! isset($options['lowUpperBound'])) {
48+
$options['lowUpperBound'] = 35;
49+
}
50+
51+
if ( ! isset($options['highUpperBound'])) {
52+
$options['highUpperBound'] = 70;
53+
}
54+
55+
if ( ! isset($options['generator'])) {
56+
$options['generator'] = '';
57+
}
58+
59+
$this->report = new \PHP_CodeCoverage_Report_HTML(
60+
$options['charset'],
61+
$options['highlight'],
62+
$options['lowUpperBound'],
63+
$options['highUpperBound'],
64+
$options['generator']
65+
);
66+
67+
$this->options = $options;
68+
}
69+
70+
/**
71+
* {@inheritdoc}
72+
*/
73+
public function process(\PHP_CodeCoverage $coverage)
74+
{
75+
return $this->report(
76+
$coverage,
77+
$options['target']
78+
);
79+
}
80+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
/**
3+
* Code Coverage PHP Report
4+
*
5+
* @copyright 2013 Anthon Pang
6+
* @license BSD-3-Clause
7+
*/
8+
9+
namespace VIPSoft\CodeCoverageCommon\Report;
10+
11+
use VIPSoft\CodeCoverageCommon\ReportInterface;
12+
13+
/**
14+
* PHP report
15+
*
16+
* @author Anthon Pang <apang@softwaredevelopment.ca>
17+
*/
18+
class Php implements ReportInterface
19+
{
20+
/**
21+
* @var \PHP_CodeCoverage_Report_Clover
22+
*/
23+
private $report;
24+
25+
/**
26+
* @var array
27+
*/
28+
private $options;
29+
30+
/**
31+
* {@inheritdoc}
32+
*/
33+
public function __construct(array $options)
34+
{
35+
if ( ! isset($options['target'])) {
36+
$options['target'] = null;
37+
}
38+
39+
$this->report = new \PHP_CodeCoverage_Report_PHP();
40+
$this->options = $options;
41+
}
42+
43+
/**
44+
* {@inheritdoc}
45+
*/
46+
public function process(\PHP_CodeCoverage $coverage)
47+
{
48+
return $this->report(
49+
$coverage,
50+
$options['target']
51+
);
52+
}
53+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?php
2+
/**
3+
* Code Coverage Text Report
4+
*
5+
* @copyright 2013 Anthon Pang
6+
* @license BSD-3-Clause
7+
*/
8+
9+
namespace VIPSoft\CodeCoverageCommon\Report;
10+
11+
use VIPSoft\CodeCoverageCommon\ReportInterface;
12+
13+
/**
14+
* Text report
15+
*
16+
* @author Anthon Pang <apang@softwaredevelopment.ca>
17+
*/
18+
class Text implements ReportInterface
19+
{
20+
/**
21+
* @var \PHP_CodeCoverage_Report_Text
22+
*/
23+
private $report;
24+
25+
/**
26+
* @var array
27+
*/
28+
private $options;
29+
30+
/**
31+
* {@inheritdoc}
32+
*/
33+
public function __construct(array $options)
34+
{
35+
if ( ! isset($options['showColors'])) {
36+
$options['showColors'] = false;
37+
}
38+
39+
if ( ! isset($options['printer'])) {
40+
$options['printer'] = null;
41+
}
42+
43+
if ( ! isset($options['lowUpperBound'])) {
44+
$options['lowUpperBound'] = 35;
45+
}
46+
47+
if ( ! isset($options['highUpperBound'])) {
48+
$options['highUpperBound'] = 70;
49+
}
50+
51+
if ( ! isset($options['showUncoveredFiles'])) {
52+
$options['showUncoveredFiles'] = false;
53+
}
54+
55+
if ($this->getVersion() === '1.2') {
56+
$outputStream = new \PHPUnit_Util_Printer($options['printer']);
57+
58+
$this->report = new \PHP_CodeCoverage_Report_Text(
59+
$outputStream,
60+
$options['lowUpperBound'],
61+
$options['highUpperBound'],
62+
$options['showUncoveredFiles']
63+
);
64+
} else {
65+
if ( ! isset($options['showOnlySummary'])) {
66+
$options['showOnlySummary'] = false;
67+
}
68+
69+
$this->report = new \PHP_CodeCoverage_Report_Text(
70+
$options['lowUpperBound'],
71+
$options['highUpperBound'],
72+
$options['showUncoveredFiles'],
73+
$options['showOnlySummary']
74+
);
75+
}
76+
77+
$this->options = $options;
78+
}
79+
80+
/**
81+
* {@inheritdoc}
82+
*/
83+
public function process(\PHP_CodeCoverage $coverage)
84+
{
85+
return $this->report(
86+
$coverage,
87+
$options['showColors']
88+
);
89+
}
90+
91+
private function getVersion()
92+
{
93+
$reflectionMethod = new \ReflectionMethod('PHP_CodeCoverage_Report_Text', '__construct');
94+
$parameters = $reflectionMethod->getParameters();
95+
96+
if (reset($parameters)->name === 'outputStream') {
97+
return '1.2';
98+
}
99+
100+
return '1.3';
101+
}
102+
}

0 commit comments

Comments
 (0)