Skip to content

Commit e331535

Browse files
author
D Vargas
committed
OPENEUROPA-1739: Adapt to allow parameters to be set in runner file.
1 parent be67dca commit e331535

File tree

5 files changed

+24
-57
lines changed

5 files changed

+24
-57
lines changed

config/commands/drupal.yml

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ command:
3232
config-dir: ${drupal.root}/drush
3333
services-setup:
3434
options:
35-
service-parameters: ${drupal.service_parameters}
3635
sites-subdir: ${drupal.site.sites_subdir}
3736
force: ${drupal.site.force}
3837
settings-setup:

src/Commands/AbstractDrupalCommands.php

+10-16
Original file line numberDiff line numberDiff line change
@@ -318,42 +318,36 @@ public function drushSetup(array $options = [
318318
/**
319319
* Setup Drupal services file.
320320
*
321-
* This command will copy the content of the file given in service-parameters to "services.yml" file in
322-
* the site directory.
323-
*
324-
* The services file name can be set in the Task Runner
325-
* configuration by setting the "drupal.service_parameters" property.
321+
* This command will add the configuration under service_parameters present in
322+
* runner.yml into "services.yml" file in the site directory.
326323
*
327324
* @command drupal:services-setup
328325
*
329-
* @option service-parameters Drupal services filename.
330326
* @option root Drupal root.
331327
* @option sites-subdir Drupal site subdirectory.
332328
* @option force Drupal force generation of a new services.yml.
333329
*
334330
* @param array $options
335331
*
336332
* @return \Robo\Collection\CollectionBuilder
337-
* @throws \Exception
338333
*/
339334
public function servicesSetup(array $options = [
340-
'service-parameters' => InputOption::VALUE_REQUIRED,
341335
'root' => InputOption::VALUE_REQUIRED,
342336
'sites-subdir' => InputOption::VALUE_REQUIRED,
343337
'force' => false,
344338
])
345339
{
346-
$services_runner_file = $this->getConfig()->get('drupal.service_parameters');
347-
$services_options_file = $options['service-parameters'];
348-
$services_source_file = empty($services_options_file)? $services_runner_file : $services_options_file;
349-
350-
if (!file_exists($services_source_file)) {
351-
throw new \Exception(sprintf('Services file %s not found.', $services_source_file));
352-
}
340+
// Read given parameters.
341+
$service_parameters['parameters'] = $this->getConfig()->get('drupal.service_parameters');
342+
$yaml = Yaml::dump($service_parameters);
353343

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

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

358352
return $this->collectionBuilder()->addTaskList($collection);
359353
}

tests/Commands/DrupalCommandsTest.php

+2-16
Original file line numberDiff line numberDiff line change
@@ -72,30 +72,16 @@ public function testPermissions(array $config, $command, $expected_error, $expec
7272
* Test the services file setup.
7373
*
7474
* @param array $config
75-
* @param array $data
7675
* @param array $expected
7776
*
7877
* @dataProvider servicesSetupDataProvider
7978
*/
80-
public function testServicesSetup(array $config, array $data, array $expected)
79+
public function testServicesSetup(array $config, array $expected)
8180
{
8281
$configFile = $this->getSandboxFilepath('runner.yml');
8382
file_put_contents($configFile, Yaml::dump($config));
8483

85-
// Prepare data for assertions depending if service filename is given in
86-
// command or in runner Yaml file.
87-
if (!empty($data['service-parameter'])) {
88-
$services_source_file = $this->getSandboxFilepath($data['service-parameter']);
89-
$service_parameter = ' --service-parameters=' . $data['service-parameter'];
90-
} else {
91-
$services_source_file = $this->getSandboxFilepath($config['drupal']['service_parameters']);
92-
$service_parameter = '';
93-
}
94-
95-
touch($services_source_file);
96-
file_put_contents($services_source_file, $data['services']['content']);
97-
98-
$command = 'drupal:services-setup' . $service_parameter . ' --root=' . $this->getSandboxRoot() . ' --working-dir=' . $this->getSandboxRoot();
84+
$command = 'drupal:services-setup --root=' . $this->getSandboxRoot() . ' --working-dir=' . $this->getSandboxRoot();
9985
$input = new StringInput($command);
10086
$runner = new TaskRunner($input, new BufferedOutput(), $this->getClassLoader());
10187
$exit_code = $runner->run();
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,9 @@
11
- config:
22
drupal:
3-
site:
4-
sites_subdir: 'site1'
5-
service_parameters: "default.services.yml"
6-
data:
7-
services:
8-
content: >
9-
parameters:
10-
http.response.debug_cacheability_headers: false
3+
service_parameters:
4+
cors.config:
5+
enabled: false
116
expected:
127
- contains: "parameters:"
13-
- contains: "http.response.debug_cacheability_headers: false"
14-
15-
- config:
16-
drupal: []
17-
data:
18-
service-parameter: "default.services.yml"
19-
services:
20-
content: >
21-
parameters:
22-
http.response.debug_cacheability_headers: true
23-
expected:
24-
- contains: "parameters:"
25-
- contains: "http.response.debug_cacheability_headers: true"
8+
- contains: "cors.config:"
9+
- contains: "enabled: false"

tests/fixtures/simulation.yml

+7-3
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,15 @@
260260
- "WriteConfiguration('web/sites/default/drushrc.php'"
261261
- "File\\Write('./drush/drush.yml')"
262262

263-
- command: 'drupal:services-setup --service-parameters=runner.yml'
264-
configuration: []
263+
- command: 'drupal:services-setup'
264+
configuration:
265+
drupal:
266+
service_parameters:
267+
cors.config: false
268+
265269
composer: ''
266270
contains:
267-
- "Filesystem\\FilesystemStack()\n ->copy('runner.yml', 'build/sites/default/services.yml'"
271+
- "File\\Write('build/sites/default/services.yml'"
268272

269273
- command: 'drupal:settings-setup'
270274
configuration: []

0 commit comments

Comments
 (0)