Skip to content

Commit

Permalink
OPENEUROPA-1739: Fix code after review.
Browse files Browse the repository at this point in the history
  • Loading branch information
D Vargas committed Sep 9, 2019
1 parent e2b74ce commit 22a76ff
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
5 changes: 1 addition & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,12 @@
"gitonomy/gitlib": "^1.0",
"nuvoleweb/robo-config": "^0.2.1",
"jakeasmith/http_build_url": "^1.0.1",
"symfony/yaml": ">3.1.0"
"symfony/yaml": "^3.1||4"
},
"require-dev": {
"openeuropa/code-review": "~1.0.0-beta3",
"phpunit/phpunit": "~5.5||~6.0"
},
"_readme": [
"We need require a version of 'symfony/yaml' higher then '3.1' since versions before 3.1.0 don't have dumper 'DUMP' constants available and 3.1.0 breaks permissions setup in tests."
],
"autoload": {
"psr-4": {
"OpenEuropa\\TaskRunner\\": "./src/"
Expand Down
19 changes: 15 additions & 4 deletions src/Commands/AbstractDrupalCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ public function drushSetup(array $options = [
])
{
$config = $this->getConfig();
$yaml = Yaml::dump($config->get('drupal.drush'));
$yaml = $this->dumpYaml($config->get('drupal.drush'));

return $this->collectionBuilder()->addTaskList([
$this->taskWriteConfiguration($options['root'].'/sites/default/drushrc.php', $config)->setConfigKey('drupal.drush'),
Expand Down Expand Up @@ -340,14 +340,13 @@ public function servicesSetup(array $options = [
{
// Read given parameters.
$service_parameters['parameters'] = $this->getConfig()->get('drupal.service_parameters', []);
$dumper = new Dumper(2);
$yaml = $dumper->dump($service_parameters, PHP_INT_MAX, 0, Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE);
$yaml = $this->dumpYaml($service_parameters);

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

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

Expand Down Expand Up @@ -476,4 +475,16 @@ protected function processPrePostInstallCommands(array &$commands, array $tokens
}
}
}

/**
* Dump Yaml into file using same format as in Drupal.
*
* @param $yaml
* @return string
*/
protected function dumpYaml($yaml)
{
$dumper = new Dumper(2);
return $dumper->dump($yaml, PHP_INT_MAX, 0, Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE);
}
}
11 changes: 4 additions & 7 deletions tests/Commands/DrupalCommandsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,11 @@ public function testServicesSetup(array $configs, array $expected)
$services_destination_dir = $this->getSandboxRoot() . '/sites/' . $sites_subdir;
$services_destination_file = $services_destination_dir . '/services.yml';

// Process information for force option.
$force = '';
if (isset($configs['force'])) {
$force = isset($configs['force'])? ' --force' : '';

if (isset($configs['services_file_content'])) {
mkdir($services_destination_dir, 0777, true);
file_put_contents($services_destination_file, 'parameters: false');
if ($configs['force']) {
$force = ' --force';
}
file_put_contents($services_destination_file, $configs['services_file_content']);
}

// Run the command.
Expand Down
3 changes: 2 additions & 1 deletion tests/fixtures/commands/drupal-services-setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
foo: bar
- config:
force: true
services_file_content: "parameters: false"
runner: |
my_settings:
foo: bar
Expand All @@ -26,7 +27,7 @@
settings:
foo: bar
- config:
force: false
services_file_content: "parameters: false"
runner: |
my_settings:
foo: bar
Expand Down

0 comments on commit 22a76ff

Please sign in to comment.