Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified composer/bin/test-reporter
100644 → 100755
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ protected function configure()
null,
InputOption::VALUE_NONE,
'Do not upload, print JSON payload to stdout'
)
->addOption(
'coverage-report',
null,
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
'Location of clover style CodeCoverage report, as produced by PHPUnit\'s --coverage-clover option.',
array('build/logs/clover.xml')
);
}

Expand All @@ -46,7 +53,7 @@ protected function configure()
protected function execute(InputInterface $input, OutputInterface $output)
{
$ret = 0;
$collector = new CoverageCollector();
$collector = new CoverageCollector($input->getOption('coverage-report'));
$json = $collector->collectAsJson();

if ($input->getOption('stdout')) {
Expand Down
36 changes: 32 additions & 4 deletions src/CodeClimate/Bundle/TestReporterBundle/CoverageCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,48 @@

class CoverageCollector
{
const RELATIVE_PATH = 'build/logs/clover.xml';

protected $api;

public function __construct()
/**
* Array that holds list of relative paths to Clover XML files
* @var array
*/
protected $cloverPaths = array();

public function __construct($paths)
{
$rootDir = getcwd();
$config = new Configuration();
$config->setSrcDir($rootDir);
$config->addCloverXmlPath($rootDir . DIRECTORY_SEPARATOR . static::RELATIVE_PATH);
$this->setCloverPaths($paths);
foreach ($this->getCloverPaths() as $path) {
if (file_exists($path)) {
$config->addCloverXmlPath($path);
} else {
$config->addCloverXmlPath($rootDir . DIRECTORY_SEPARATOR . $path);
}
}

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

/**
* Set a list of Clover XML paths
* @param array $paths Array of relative paths to Clovers XML files
*/
public function setCloverPaths($paths)
{
$this->cloverPaths = $paths;
}

/**
* Get a list of Clover XML paths
* @return array Array of relative Clover XML file locations
*/
public function getCloverPaths()
{
return $this->cloverPaths;
}
public function collectAsJson()
{
$cloverJsonFile = $this->api->collectCloverXml()->getJsonFile();
Expand Down