Skip to content

Commit

Permalink
Issue #32: Add setup tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ademarco committed Jan 13, 2018
1 parent bfe82ca commit 215c8c9
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 35 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ Available commands:
help Displays help for a command
list Lists commands
changelog
changelog:generate [changelog:g|cg] Generate a changelog based on GitHub issues and pull requests.
changelog:generate Generate a changelog based on GitHub issues and pull requests.
drupal
drupal:component-setup [drupal:component-scaffold|drupal:cs|dcs] Scaffold Drupal component development.
drupal:site-install [drupal:si|dsi] Install target site.
drupal:site-post-install [drupal:spi|dspi] Run Drupal post-install commands.
drupal:site-setup [drupal:site-scaffold|drupal:ss|dss] Setup local Drupal site development copy.
drupal:drush-setup Write Drush configuration files to the specified directory.
drupal:settings-setup Write Drupal site configuration files to the specified directory.
drupal:site-install Install target site.
drupal:site-post-install Run Drupal post-install commands.
drupal:site-pre-install Run Drupal pre-install commands.
setup
setup:behat [setup:b|sb] Setup Behat.
setup:phpunit [setup:p|sp] Setup PHPUnit.
setup:replace [setup:r|sr] Replace configuration tokens in a text file.
setup:behat
setup:phpunit
```
16 changes: 2 additions & 14 deletions config/runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ runner:
drupal:
core: "8"
root: "build"

# The "root_absolute" is derived at runtime.
# @see \EC\OpenEuropa\TaskRunner\Commands\DrupalCommands::initializeDrupalRuntimeConfiguration()
# @see \EC\OpenEuropa\TaskRunner\Commands\DrupalCommands::setRuntimeConfig()
root_absolute: ~
base_url: "http://127.0.0.1:8888"

Expand Down Expand Up @@ -55,18 +54,6 @@ drupal:
- "vendor"
- "${drupal.root}"

# Filesystem tasks to be ran when setting up a site.
setup:
symlink:
- from: "custom/modules"
to: "modules/custom"
- from: "custom/themes"
to: "themes/custom"
- from: "custom/profiles"
to: "profiles/custom"
- from: "custom/libraries"
to: "libraries/custom"

# List of shell commands to be before and after the site installation.
# You can use same syntax as the "commands:" below or simply calling a shell command.
# Configuration token replacement is supported too.
Expand All @@ -79,6 +66,7 @@ github:
# GitHub OAuth token.
token: ~

# List of dynamically-defined commands.
commands:
setup:behat:
- { task: "process", source: "behat.yml.dist", destination: "behat.yml" }
Expand Down
7 changes: 3 additions & 4 deletions src/Commands/DrupalCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use EC\OpenEuropa\TaskRunner\Contract\ComposerAwareInterface;
use EC\OpenEuropa\TaskRunner\Contract\FilesystemAwareInterface;
use Robo\Exception\TaskException;
use Symfony\Component\Console\Event\ConsoleCommandEvent;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Yaml\Yaml;
Expand Down Expand Up @@ -41,7 +40,7 @@ public function getConfigurationFile()
*
* @hook command-event *
*/
public function initializeDrupalRuntimeConfiguration(ConsoleCommandEvent $event)
public function setRuntimeConfig(ConsoleCommandEvent $event)
{
$root = $this->getConfig()->get('drupal.root');
$rootFullPath = realpath($root);
Expand Down Expand Up @@ -175,7 +174,7 @@ public function sitePreInstall()
/**
* Write Drush configuration files to the specified directory.
*
* @command drupal:setup-drush
* @command drupal:drush-setup
*
* @option root Drupal root.
*
Expand All @@ -199,7 +198,7 @@ public function setupDrush(array $options = [
/**
* Write Drupal site configuration files to the specified directory.
*
* @command drupal:setup-settings
* @command drupal:settings-setup
*
* @option root Drupal root.
*
Expand Down
8 changes: 6 additions & 2 deletions src/Commands/DynamicCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

namespace EC\OpenEuropa\TaskRunner\Commands;

use EC\OpenEuropa\TaskRunner\Tasks\CollectionFactory\loadTasks;
use Consolidation\AnnotatedCommand\AnnotationData;
use Consolidation\AnnotatedCommand\CommandData;
use EC\OpenEuropa\TaskRunner\Tasks as TaskRunnerTasks;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Event\ConsoleCommandEvent;

/**
* Class DynamicCommands
Expand All @@ -11,7 +15,7 @@
*/
class DynamicCommands extends BaseCommands
{
use loadTasks;
use TaskRunnerTasks\CollectionFactory\loadTasks;

/**
* @return \EC\OpenEuropa\TaskRunner\Tasks\CollectionFactory\CollectionFactory
Expand Down
24 changes: 21 additions & 3 deletions src/Tasks/CollectionFactory/CollectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function run()
{
$collection = $this->collectionBuilder();

foreach ($this->tasks as $task) {
foreach ($this->getTasks() as $task) {
$collection->addTask($this->taskFactory($task));
}

Expand All @@ -61,15 +61,30 @@ public function run()
*/
public function simulate($context)
{
foreach ($this->tasks as $task) {
foreach ($this->getTasks() as $task) {
if (is_array($task)) {
$task = Yaml::dump($task, 0);
}

$this->printTaskInfo($task, $context);
}
}

/**
* @return array
*/
public function getTasks()
{
return isset($this->tasks['tasks']) ? $this->tasks['tasks'] : $this->tasks;
}

/**
* @return string
*/
public function getHelp()
{
return isset($this->tasks['help']) ? $this->tasks['help'] : "Dynamic command defined in runner.yml";
}

/**
* @param array|string $task
*
Expand Down Expand Up @@ -128,6 +143,9 @@ protected function taskFactory($task)
case "process":
return $this->taskProcessConfigFile($task['source'], $task['destination']);

case "run":
return $this->taskExec($this->getConfig()->get('runner.bin_dir').'/run')->arg($task['command']);

default:
throw new TaskException($this, "Task '{$task['task']}' not supported.");
}
Expand Down
33 changes: 29 additions & 4 deletions tests/fixtures/simulation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,28 +139,53 @@
- "[Simulator] { task: symlink, from: build/modules/custom, to: ../../custom/modules }"
- "[Simulator] { task: symlink, from: build/modules/custom, to: ../../custom/themes }"

- command: 'drupal:setup-drush'
- command: 'drupal:drush-setup'
configuration: []
composer: ''
contains:
- "WriteConfiguration('build/sites/default/drushrc.php'"
- "File\\Write('build/sites/default/drush.yml')"

- command: 'drupal:setup-drush --root=web'
- command: 'drupal:drush-setup --root=web'
configuration: []
composer: ''
contains:
- "WriteConfiguration('web/sites/default/drushrc.php'"
- "File\\Write('web/sites/default/drush.yml')"

- command: 'drupal:setup-settings'
- command: 'drupal:settings-setup'
configuration: []
composer: ''
contains:
- "AppendConfiguration('build/sites/default/default.settings.php'"

- command: 'drupal:setup-settings --root=web'
- command: 'drupal:settings-setup --root=web'
configuration: []
composer: ''
contains:
- "AppendConfiguration('web/sites/default/default.settings.php'"

- command: 'drupal:setup-dev'
configuration:
drupal:
root: "web"
commands:
drupal:setup-dev:
- { task: "chmod", file: "${drupal.root}/sites", permissions: '0775' }
- { task: "symlink", from: "${drupal.root}/modules/custom", to: "../../custom/modules" }
- { task: "symlink", from: "${drupal.root}/themes/custom", to: "../../custom/themes" }
- { task: "symlink", from: "${drupal.root}/profiles/custom", to: "../../custom/profiles" }
- { task: "run", command: "drupal:drush-setup" }
- { task: "run", command: "drupal:settings-setup" }
- { task: "run", command: "setup:behat" }
- { task: "run", command: "setup:phpunit" }
composer: ''
contains:
- "{ task: chmod, file: web/sites, permissions: '0775' }"
- "{ task: symlink, from: web/modules/custom, to: ../../custom/modules }"
- "{ task: symlink, from: web/themes/custom, to: ../../custom/themes }"
- "{ task: symlink, from: web/profiles/custom, to: ../../custom/profiles }"
- "{ task: run, command: 'drupal:drush-setup' }"
- "{ task: run, command: 'drupal:settings-setup' }"
- "{ task: run, command: 'setup:behat' }"
- "{ task: run, command: 'setup:phpunit' }"

0 comments on commit 215c8c9

Please sign in to comment.