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 677f871 commit f8de9bd
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 29 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
60 changes: 31 additions & 29 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,45 +23,48 @@ 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.
*
* @hook init
*/
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';
parent::initialize();

$this->reportsDir = $this->getConfigValue('reports.localDir') . '/phpunit';
$this->reportFile = $this->reportsDir . '/results.xml';
$this->testsDir = $this->getConfigValue('repo.root') . '/tests/phpunit';
$this->phpunitConfig = $this->getConfigValue('phpunit');
}
}

/**
* Executes all PHPUnit tests.
*
* @command tests:phpunit
* @description Executes all PHPUnit tests.
*/
public function testsPhpUnit() {
$this->createLogs();
foreach ($this->testsDir as $dir) {
$task = $this->taskPHPUnit()
->dir($dir)
->xml($this->reportFile)
->arg('.')
->printOutput(TRUE)
->printMetadata(FALSE);
$task->run();
/**
* Executes all PHPUnit tests.
*
* @command tests:phpunit
* @description Executes all PHPUnit tests.
*/
public function testsPhpUnit() {
$this->createLogs();
foreach ($this->phpunitConfig as $test) {
$task = $this->taskPHPUnit()
->xml($this->reportFile)
->arg('.')
->printOutput(TRUE)
->printMetadata(FALSE);
if (isset($test['path'])) {
$task->dir($test['path']);
}
if (isset($test['config'])) {
$task->option('-c', $test['config']);
}
$task->run();
}
}
}

/**
* Creates empty log directory and log file for PHPUnit tests.
Expand Down

0 comments on commit f8de9bd

Please sign in to comment.