From d5971ae2ada55fec45cd3b7117c80e366422ecf2 Mon Sep 17 00:00:00 2001 From: Mike Madison Date: Tue, 25 Apr 2017 15:42:20 -0400 Subject: [PATCH] BLT-1047: updating PR to include work from 1048 and modifying config logic. --- phing/build.yml | 7 ++++++ readme/testing.md | 4 +--- src/Robo/Commands/Tests/PhpUnitCommand.php | 25 +++++++++++----------- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/phing/build.yml b/phing/build.yml index e30f6b345d..f6cd60f6c0 100644 --- a/phing/build.yml +++ b/phing/build.yml @@ -127,6 +127,13 @@ phpcbf: - files.php.custom.themes - files.frontend.custom.themes +phpunit: + - path: '{$repo.root}/tests/phpunit}' + config: null + # Customization for one or more custom phpunit test locations + # and if the core (or custom) config file should be included as a -c parameter. + # - path: '{$docroot}/custom/modules//tests' + # config: '{$docroot}/core/phpunit.dist.xml' project: local: uri: ${project.local.protocol}://${project.local.hostname} diff --git a/readme/testing.md b/readme/testing.md index 9e0cf4bd01..02906f3a51 100644 --- a/readme/testing.md +++ b/readme/testing.md @@ -172,9 +172,7 @@ Project level, functional PHPUnit tests are included in `tests/phpunit`. Any PHP ### Configuration -PHPunit's behavior(s) can be further customized via the project.yml file to provide additional levels of control on a per project basis. See [Extending BLT](extending-blt.md) for more information. - - The each index in the phpunit array in project.yml should contain a path (to a phpunit test or directory that contains at least one test) and a config path (if custom configuration or boostrapping of Drupal is required): +You can [customize the configuration values](extending-blt.md#modifying-blt-configuration) for the phpunit key. Each should containn a path (to a phpunit test or directory that contains at least one test) and a config path (if custom configuration or boostrapping of Drupal is required): * config: path to either the Core phpunit configuration file (docroot/core/phpunit.xml.dist) or a custom one. If left blank, no configuration will be loaded with the unit test. * path: the path to the custom phpunit test \ No newline at end of file diff --git a/src/Robo/Commands/Tests/PhpUnitCommand.php b/src/Robo/Commands/Tests/PhpUnitCommand.php index 6ede1e4e13..3a118d9909 100644 --- a/src/Robo/Commands/Tests/PhpUnitCommand.php +++ b/src/Robo/Commands/Tests/PhpUnitCommand.php @@ -10,7 +10,6 @@ */ class PhpUnitCommand extends BltTasks { - /** * Directory in which test logs and reports are generated. * @@ -24,10 +23,11 @@ class PhpUnitCommand extends BltTasks { protected $reportFile; /** - * The directory path containing PHPUnit tests. + * An array that contains configuration to override / + * customize phpunit commands. * - * @var string*/ - protected $testsDir; + * @var array*/ + protected $phpunitConfig; /** * This hook will fire for all commands in this command file. @@ -37,12 +37,8 @@ class PhpUnitCommand extends BltTasks { public function initialize() { $this->reportsDir = $this->getConfigValue('reports.localDir') . '/phpunit'; $this->reportFile = $this->reportsDir . '/results.xml'; - if (is_array($this->getConfigValue('phpunit.paths'))) { - $this->testsDir = $this->getConfigValue('phpunit.paths'); - } - else { - $this->testsDir[] = $this->getConfigValue('repo.root') . '/tests/phpunit'; - } + $this->testsDir = $this->getConfigValue('repo.root') . '/tests/phpunit'; + $this->phpunitConfig = $this->getConfigValue('phpunit'); } /** @@ -53,13 +49,18 @@ public function initialize() { */ public function testsPhpUnit() { $this->createLogs(); - foreach ($this->testsDir as $dir) { + foreach ($this->phpunitConfig as $test) { $task = $this->taskPHPUnit() - ->dir($dir) ->xml($this->reportFile) ->arg('.') ->printOutput(TRUE) ->printMetadata(FALSE); + if (isset($test['path'])) { + $task->dir($test['path']); + } + if (isset($test['config'])) { + $task->option('-configuration', $test['config']); + } $task->run(); } }