diff --git a/.gitignore b/.gitignore index a75df016..57a654d7 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ /runtime /app/config.yml /public/assets/vendor +/public/artifacts +!/public/artifacts/.gitkeep diff --git a/docs/en/plugins/pdepend.md b/docs/en/plugins/pdepend.md index 68610f64..90abd8c8 100644 --- a/docs/en/plugins/pdepend.md +++ b/docs/en/plugins/pdepend.md @@ -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 +``` diff --git a/docs/en/plugins/phar.md b/docs/en/plugins/phar.md index 5294b1ce..70d2af9c 100644 --- a/docs/en/plugins/phar.md +++ b/docs/en/plugins/phar.md @@ -15,7 +15,7 @@ Configuration ### Examples -``` +```yaml phar: directory: /path/to/directory filename: foobar.phar diff --git a/docs/en/plugins/php_cpd.md b/docs/en/plugins/php_cpd.md index 8371b1ac..032e01ad 100644 --- a/docs/en/plugins/php_cpd.md +++ b/docs/en/plugins/php_cpd.md @@ -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 diff --git a/docs/en/plugins/php_unit.md b/docs/en/plugins/php_unit.md index 4699a4cd..ee0ff69a 100644 --- a/docs/en/plugins/php_unit.md +++ b/docs/en/plugins/php_unit.md @@ -35,6 +35,7 @@ test: config: - "path/to/phpunit.xml" path: "app/tests/" + coverage: true ``` Troubleshooting diff --git a/public/artifacts/.gitkeep b/public/artifacts/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/src/PHPCensor/Plugin/Option/PhpUnitOptions.php b/src/PHPCensor/Plugin/Option/PhpUnitOptions.php index bb7cf6dc..5ca869de 100644 --- a/src/PHPCensor/Plugin/Option/PhpUnitOptions.php +++ b/src/PHPCensor/Plugin/Option/PhpUnitOptions.php @@ -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); } /* diff --git a/src/PHPCensor/Plugin/Pdepend.php b/src/PHPCensor/Plugin/Pdepend.php index 1b93588b..b8fe1bcd 100644 --- a/src/PHPCensor/Plugin/Pdepend.php +++ b/src/PHPCensor/Plugin/Pdepend.php @@ -8,13 +8,18 @@ use PHPCensor\Plugin; /** * Pdepend Plugin - Allows Pdepend report - * + * * @author Johan van der Heide */ 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 ) ); } diff --git a/src/PHPCensor/Plugin/PhpUnit.php b/src/PHPCensor/Plugin/PhpUnit.php index 72e362b4..77e3c8f2 100644 --- a/src/PHPCensor/Plugin/PhpUnit.php +++ b/src/PHPCensor/Plugin/PhpUnit.php @@ -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; } diff --git a/tests/PHPCensor/Plugin/Option/PhpUnitOptionsTest.php b/tests/PHPCensor/Plugin/Option/PhpUnitOptionsTest.php index 1bb696a0..378cbee2 100644 --- a/tests/PHPCensor/Plugin/Option/PhpUnitOptionsTest.php +++ b/tests/PHPCensor/Plugin/Option/PhpUnitOptionsTest.php @@ -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());