Skip to content

Commit e37481d

Browse files
committed
Merge pull request #7 from martinssipenko/master
Ability to provide clover.xml location as input argument
2 parents ccda2c9 + 25cd586 commit e37481d

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

composer/bin/test-reporter

100644100755
File mode changed.

src/CodeClimate/Bundle/TestReporterBundle/Command/TestReporterCommand.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ protected function configure()
3535
null,
3636
InputOption::VALUE_NONE,
3737
'Do not upload, print JSON payload to stdout'
38+
)
39+
->addOption(
40+
'coverage-report',
41+
null,
42+
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
43+
'Location of clover style CodeCoverage report, as produced by PHPUnit\'s --coverage-clover option.',
44+
array('build/logs/clover.xml')
3845
);
3946
}
4047

@@ -46,7 +53,7 @@ protected function configure()
4653
protected function execute(InputInterface $input, OutputInterface $output)
4754
{
4855
$ret = 0;
49-
$collector = new CoverageCollector();
56+
$collector = new CoverageCollector($input->getOption('coverage-report'));
5057
$json = $collector->collectAsJson();
5158

5259
if ($input->getOption('stdout')) {

src/CodeClimate/Bundle/TestReporterBundle/CoverageCollector.php

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,48 @@
88

99
class CoverageCollector
1010
{
11-
const RELATIVE_PATH = 'build/logs/clover.xml';
12-
1311
protected $api;
1412

15-
public function __construct()
13+
/**
14+
* Array that holds list of relative paths to Clover XML files
15+
* @var array
16+
*/
17+
protected $cloverPaths = array();
18+
19+
public function __construct($paths)
1620
{
1721
$rootDir = getcwd();
1822
$config = new Configuration();
1923
$config->setSrcDir($rootDir);
20-
$config->addCloverXmlPath($rootDir . DIRECTORY_SEPARATOR . static::RELATIVE_PATH);
24+
$this->setCloverPaths($paths);
25+
foreach ($this->getCloverPaths() as $path) {
26+
if (file_exists($path)) {
27+
$config->addCloverXmlPath($path);
28+
} else {
29+
$config->addCloverXmlPath($rootDir . DIRECTORY_SEPARATOR . $path);
30+
}
31+
}
2132

2233
$this->api = new Jobs($config);
2334
}
2435

36+
/**
37+
* Set a list of Clover XML paths
38+
* @param array $paths Array of relative paths to Clovers XML files
39+
*/
40+
public function setCloverPaths($paths)
41+
{
42+
$this->cloverPaths = $paths;
43+
}
44+
45+
/**
46+
* Get a list of Clover XML paths
47+
* @return array Array of relative Clover XML file locations
48+
*/
49+
public function getCloverPaths()
50+
{
51+
return $this->cloverPaths;
52+
}
2553
public function collectAsJson()
2654
{
2755
$cloverJsonFile = $this->api->collectCloverXml()->getJsonFile();

0 commit comments

Comments
 (0)