Added code coverage report for PHPUnit plugin. Issue #86.
This commit is contained in:
parent
cf7fb7a551
commit
7db036e956
4 changed files with 64 additions and 19 deletions
|
|
@ -9,12 +9,29 @@ namespace PHPCensor\Plugin\Option;
|
|||
*/
|
||||
class PhpUnitOptions
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $options;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $location;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $arguments = [];
|
||||
|
||||
public function __construct($options)
|
||||
/**
|
||||
* @param array $options
|
||||
* @param string $location
|
||||
*/
|
||||
public function __construct($options, $location)
|
||||
{
|
||||
$this->options = $options;
|
||||
$this->options = $options;
|
||||
$this->location = $location;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -102,8 +119,8 @@ class PhpUnitOptions
|
|||
/*
|
||||
* Handles command aliases outside of the args option
|
||||
*/
|
||||
if (isset($this->options['coverage'])) {
|
||||
$this->addArgument('coverage-html', $this->options['coverage']);
|
||||
if (isset($this->options['coverage']) && $this->options['coverage']) {
|
||||
$this->addArgument('coverage-html', $this->location);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -20,6 +20,16 @@ use PHPCensor\ZeroConfigPluginInterface;
|
|||
*/
|
||||
class PhpUnit extends Plugin implements ZeroConfigPluginInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $buildDirectory;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $location;
|
||||
|
||||
/** @var string[] Raw options from the config file */
|
||||
protected $options = [];
|
||||
|
||||
|
|
@ -30,7 +40,7 @@ class PhpUnit extends Plugin implements ZeroConfigPluginInterface
|
|||
{
|
||||
return 'php_unit';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Standard Constructor
|
||||
* $options['config'] Path to a PHPUnit XML configuration file.
|
||||
|
|
@ -47,7 +57,10 @@ class PhpUnit extends Plugin implements ZeroConfigPluginInterface
|
|||
{
|
||||
parent::__construct($builder, $build, $options);
|
||||
|
||||
$this->options = new PhpUnitOptions($options);
|
||||
$this->buildDirectory = $this->build->getProjectId() . '/' . $this->build->getId();
|
||||
$this->location = PUBLIC_DIR . 'artifacts/phpunit/' . $this->buildDirectory . '/coverage';
|
||||
|
||||
$this->options = new PhpUnitOptions($options, $this->location);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -134,12 +147,27 @@ class PhpUnit extends Plugin implements ZeroConfigPluginInterface
|
|||
$options->addArgument('configuration', $buildPath . $configFile);
|
||||
}
|
||||
|
||||
if (!file_exists($this->location) && $options->getOption('coverage')) {
|
||||
mkdir($this->location, 0777, true);
|
||||
}
|
||||
|
||||
$arguments = $this->builder->interpolate($options->buildArgumentString());
|
||||
$cmd = $this->findBinary('phpunit') . ' %s %s';
|
||||
$success = $this->builder->executeCommand($cmd, $arguments, $directory);
|
||||
|
||||
$this->processResults($logFile, $logFormat);
|
||||
|
||||
$config = $this->builder->getSystemConfig('php-censor');
|
||||
|
||||
if ($options->getOption('coverage')) {
|
||||
$this->builder->logSuccess(
|
||||
sprintf(
|
||||
"\nPHPUnit successful.\nYou can use coverage report: %s",
|
||||
$config['url'] . '/artifacts/phpunit/' . $this->buildDirectory . '/coverage/index.html'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return $success;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue