Merge branch 'improve-pdepend'

This commit is contained in:
Dmitry Khomutov 2018-01-24 20:16:24 +07:00
commit eb1aa43ae3
No known key found for this signature in database
GPG key ID: EC19426474B37AAC
10 changed files with 96 additions and 36 deletions

2
.gitignore vendored
View file

@ -3,3 +3,5 @@
/runtime
/app/config.yml
/public/assets/vendor
/public/artifacts
!/public/artifacts/.gitkeep

View file

@ -8,4 +8,11 @@ Configuration
### Options
* **directory** - Required - Directory in which to run PDepend.
* **directory** [string, optional] - Directory in which to run PDepend (default: `%BUILD_PATH%`).
### Examples
```yaml
pdepend:
directory: ./src
```

View file

@ -15,7 +15,7 @@ Configuration
### Examples
```
```yaml
phar:
directory: /path/to/directory
filename: foobar.phar

View file

@ -8,7 +8,7 @@ Configuration
### Options
* **path** - Optional - Path in which to run PHP Copy/Paste Detector (default: build root).
* **path** - Optional - Path in which to run PHP Copy/Paste Detector (default: `%BUILD_PATH%`).
* **ignore** - Optional - A list of files / paths to ignore (default: build_settings > ignore).
### Examples

View file

@ -35,6 +35,7 @@ test:
config:
- "path/to/phpunit.xml"
path: "app/tests/"
coverage: true
```
Troubleshooting

View file

View file

@ -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);
}
/*

View file

@ -8,13 +8,18 @@ use PHPCensor\Plugin;
/**
* Pdepend Plugin - Allows Pdepend report
*
*
* @author Johan van der Heide <info@japaveh.nl>
*/
class Pdepend extends Plugin
{
protected $args;
/**
* @var string
*/
protected $buildDirectory;
/**
* @var string Directory which needs to be scanned
*/
@ -56,13 +61,16 @@ class Pdepend extends Plugin
{
parent::__construct($builder, $build, $options);
$this->directory = isset($options['directory']) ? $options['directory'] : $this->builder->buildPath;
$this->directory = isset($options['directory'])
? $options['directory']
: $this->builder->buildPath;
$title = $this->builder->getBuildProjectTitle();
$this->summary = $title . '-summary.xml';
$this->pyramid = $title . '-pyramid.svg';
$this->chart = $title . '-chart.svg';
$this->location = $this->builder->buildPath . '..' . DIRECTORY_SEPARATOR . 'pdepend';
$this->summary = 'summary.xml';
$this->pyramid = 'pyramid.svg';
$this->chart = 'chart.svg';
$this->buildDirectory = $build->getProjectId() . '/' . $build->getId();
$this->location = PUBLIC_DIR . 'artifacts/pdepend/' . $this->buildDirectory;
}
/**
@ -71,7 +79,7 @@ class Pdepend extends Plugin
public function execute()
{
if (!file_exists($this->location)) {
mkdir($this->location);
mkdir($this->location, 0777, true);
}
if (!is_writable($this->location)) {
throw new \Exception(sprintf('The location %s is not writable or does not exist.', $this->location));
@ -104,12 +112,10 @@ class Pdepend extends Plugin
if ($success) {
$this->builder->logSuccess(
sprintf(
"Pdepend successful. You can use %s\n, ![Chart](%s \"Pdepend Chart\")\n
and ![Pyramid](%s \"Pdepend Pyramid\")\n
for inclusion in the readme.md file",
$config['url'] . '/build/pdepend/' . $this->summary,
$config['url'] . '/build/pdepend/' . $this->chart,
$config['url'] . '/build/pdepend/' . $this->pyramid
"\nPdepend successful.\nYou can use: %s,\n![Chart](%s \"Pdepend Chart\") and\n![Pyramid](%s \"Pdepend Pyramid\")\nfor inclusion in the readme.md file",
$config['url'] . '/artifacts/pdepend/' . $this->buildDirectory . '/' . $this->summary,
$config['url'] . '/artifacts/pdepend/' . $this->buildDirectory . '/' . $this->chart,
$config['url'] . '/artifacts/pdepend/' . $this->buildDirectory . '/' . $this->pyramid
)
);
}

View file

@ -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;
}

View file

@ -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());