Skip to content

Commit

Permalink
OPENEUROPA-1739: Adapt to allow parameters to be set in runner file.
Browse files Browse the repository at this point in the history
  • Loading branch information
D Vargas committed Aug 29, 2019
1 parent be67dca commit e331535
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 57 deletions.
1 change: 0 additions & 1 deletion config/commands/drupal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ command:
config-dir: ${drupal.root}/drush
services-setup:
options:
service-parameters: ${drupal.service_parameters}
sites-subdir: ${drupal.site.sites_subdir}
force: ${drupal.site.force}
settings-setup:
Expand Down
26 changes: 10 additions & 16 deletions src/Commands/AbstractDrupalCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,42 +318,36 @@ public function drushSetup(array $options = [
/**
* Setup Drupal services file.
*
* This command will copy the content of the file given in service-parameters to "services.yml" file in
* the site directory.
*
* The services file name can be set in the Task Runner
* configuration by setting the "drupal.service_parameters" property.
* This command will add the configuration under service_parameters present in
* runner.yml into "services.yml" file in the site directory.
*
* @command drupal:services-setup
*
* @option service-parameters Drupal services filename.
* @option root Drupal root.
* @option sites-subdir Drupal site subdirectory.
* @option force Drupal force generation of a new services.yml.
*
* @param array $options
*
* @return \Robo\Collection\CollectionBuilder
* @throws \Exception
*/
public function servicesSetup(array $options = [
'service-parameters' => InputOption::VALUE_REQUIRED,
'root' => InputOption::VALUE_REQUIRED,
'sites-subdir' => InputOption::VALUE_REQUIRED,
'force' => false,
])
{
$services_runner_file = $this->getConfig()->get('drupal.service_parameters');
$services_options_file = $options['service-parameters'];
$services_source_file = empty($services_options_file)? $services_runner_file : $services_options_file;

if (!file_exists($services_source_file)) {
throw new \Exception(sprintf('Services file %s not found.', $services_source_file));
}
// Read given parameters.
$service_parameters['parameters'] = $this->getConfig()->get('drupal.service_parameters');
$yaml = Yaml::dump($service_parameters);

// Set the destination file.
$services_destination_file = $options['root'] . '/sites/' . $options['sites-subdir'] . '/services.yml';

$collection = [$this->taskFilesystemStack()->copy($services_source_file, $services_destination_file, (bool) $options['force'])];
$collection = [];
if (true === (bool) $options['force'] || !file_exists($services_destination_file)) {
$collection[] = $this->taskWriteToFile($services_destination_file)->append(false)->text($yaml);
}

return $this->collectionBuilder()->addTaskList($collection);
}
Expand Down
18 changes: 2 additions & 16 deletions tests/Commands/DrupalCommandsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,30 +72,16 @@ public function testPermissions(array $config, $command, $expected_error, $expec
* Test the services file setup.
*
* @param array $config
* @param array $data
* @param array $expected
*
* @dataProvider servicesSetupDataProvider
*/
public function testServicesSetup(array $config, array $data, array $expected)
public function testServicesSetup(array $config, array $expected)
{
$configFile = $this->getSandboxFilepath('runner.yml');
file_put_contents($configFile, Yaml::dump($config));

// Prepare data for assertions depending if service filename is given in
// command or in runner Yaml file.
if (!empty($data['service-parameter'])) {
$services_source_file = $this->getSandboxFilepath($data['service-parameter']);
$service_parameter = ' --service-parameters=' . $data['service-parameter'];
} else {
$services_source_file = $this->getSandboxFilepath($config['drupal']['service_parameters']);
$service_parameter = '';
}

touch($services_source_file);
file_put_contents($services_source_file, $data['services']['content']);

$command = 'drupal:services-setup' . $service_parameter . ' --root=' . $this->getSandboxRoot() . ' --working-dir=' . $this->getSandboxRoot();
$command = 'drupal:services-setup --root=' . $this->getSandboxRoot() . ' --working-dir=' . $this->getSandboxRoot();
$input = new StringInput($command);
$runner = new TaskRunner($input, new BufferedOutput(), $this->getClassLoader());
$exit_code = $runner->run();
Expand Down
26 changes: 5 additions & 21 deletions tests/fixtures/commands/drupal-services-setup.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,9 @@
- config:
drupal:
site:
sites_subdir: 'site1'
service_parameters: "default.services.yml"
data:
services:
content: >
parameters:
http.response.debug_cacheability_headers: false
service_parameters:
cors.config:
enabled: false
expected:
- contains: "parameters:"
- contains: "http.response.debug_cacheability_headers: false"

- config:
drupal: []
data:
service-parameter: "default.services.yml"
services:
content: >
parameters:
http.response.debug_cacheability_headers: true
expected:
- contains: "parameters:"
- contains: "http.response.debug_cacheability_headers: true"
- contains: "cors.config:"
- contains: "enabled: false"
10 changes: 7 additions & 3 deletions tests/fixtures/simulation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,15 @@
- "WriteConfiguration('web/sites/default/drushrc.php'"
- "File\\Write('./drush/drush.yml')"

- command: 'drupal:services-setup --service-parameters=runner.yml'
configuration: []
- command: 'drupal:services-setup'
configuration:
drupal:
service_parameters:
cors.config: false

composer: ''
contains:
- "Filesystem\\FilesystemStack()\n ->copy('runner.yml', 'build/sites/default/services.yml'"
- "File\\Write('build/sites/default/services.yml'"

- command: 'drupal:settings-setup'
configuration: []
Expand Down

0 comments on commit e331535

Please sign in to comment.