Skip to content

Commit

Permalink
BLT-1047: updating PR to include work from 1048 and modifying config …
Browse files Browse the repository at this point in the history
…logic.
  • Loading branch information
mikemadison13 committed Apr 25, 2017
1 parent 1aeaf47 commit abbd1a3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
7 changes: 7 additions & 0 deletions phing/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/<your_module>/tests'
# config: '{$docroot}/core/phpunit.dist.xml'
project:
local:
uri: ${project.local.protocol}://${project.local.hostname}
Expand Down
4 changes: 1 addition & 3 deletions readme/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
25 changes: 13 additions & 12 deletions src/Robo/Commands/Tests/PhpUnitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*/
class PhpUnitCommand extends BltTasks {


/**
* Directory in which test logs and reports are generated.
*
Expand All @@ -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.
Expand All @@ -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');
}

/**
Expand All @@ -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();
}
}
Expand Down

0 comments on commit abbd1a3

Please sign in to comment.