Added code coverage report for PHPUnit plugin. Issue #86.
This commit is contained in:
parent
cf7fb7a551
commit
7db036e956
|
@ -35,6 +35,7 @@ test:
|
|||
config:
|
||||
- "path/to/phpunit.xml"
|
||||
path: "app/tests/"
|
||||
coverage: true
|
||||
```
|
||||
|
||||
Troubleshooting
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,32 +25,30 @@ class PhpUnitOptionsTest extends \PHPUnit\Framework\TestCase
|
|||
'configuration' => 'tests/phpunit.xml',
|
||||
],
|
||||
],
|
||||
[
|
||||
[
|
||||
'coverage' => '',
|
||||
],
|
||||
[],
|
||||
],
|
||||
[
|
||||
[
|
||||
'coverage' => '/path/to/coverage2/',
|
||||
'args' => [
|
||||
'coverage-html' => '/path/to/coverage1/',
|
||||
],
|
||||
],
|
||||
[
|
||||
'coverage-html' => [
|
||||
'/path/to/coverage1/',
|
||||
'/path/to/coverage2/',
|
||||
],
|
||||
'coverage-html' => '/location',
|
||||
],
|
||||
],
|
||||
[
|
||||
[
|
||||
'coverage' => true,
|
||||
'directory' => [
|
||||
'/path/to/test1/',
|
||||
'/path/to/test2/',
|
||||
],
|
||||
'args' => [
|
||||
'coverage-html' => '/path/to/coverage1/',
|
||||
],
|
||||
],
|
||||
[
|
||||
'coverage-html' => '/path/to/coverage1/',
|
||||
'coverage-html' => '/location',
|
||||
],
|
||||
],
|
||||
[
|
||||
|
@ -97,7 +95,7 @@ class PhpUnitOptionsTest extends \PHPUnit\Framework\TestCase
|
|||
*/
|
||||
public function testCommandArguments($rawOptions, $parsedArguments)
|
||||
{
|
||||
$options = new PhpUnitOptions($rawOptions);
|
||||
$options = new PhpUnitOptions($rawOptions, '/location');
|
||||
$this->assertSame($parsedArguments, $options->getCommandArguments());
|
||||
}
|
||||
|
||||
|
@ -107,7 +105,8 @@ class PhpUnitOptionsTest extends \PHPUnit\Framework\TestCase
|
|||
[
|
||||
'run_from' => '/path/to/run/from',
|
||||
'path' => 'subTest',
|
||||
]
|
||||
],
|
||||
'/location'
|
||||
);
|
||||
|
||||
$this->assertEquals('/path/to/run/from', $options->getRunFrom());
|
||||
|
|
Loading…
Reference in a new issue