diff --git a/composer.json b/composer.json index 757395f0..ded59312 100644 --- a/composer.json +++ b/composer.json @@ -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.4||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/" diff --git a/src/Commands/AbstractDrupalCommands.php b/src/Commands/AbstractDrupalCommands.php index cbd590fe..b565673f 100644 --- a/src/Commands/AbstractDrupalCommands.php +++ b/src/Commands/AbstractDrupalCommands.php @@ -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'), @@ -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); } @@ -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); + } } diff --git a/tests/Commands/DrupalCommandsTest.php b/tests/Commands/DrupalCommandsTest.php index df271395..0452b85e 100644 --- a/tests/Commands/DrupalCommandsTest.php +++ b/tests/Commands/DrupalCommandsTest.php @@ -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. diff --git a/tests/fixtures/commands/drupal-services-setup.yml b/tests/fixtures/commands/drupal-services-setup.yml index 3dd53ab0..4416b786 100644 --- a/tests/fixtures/commands/drupal-services-setup.yml +++ b/tests/fixtures/commands/drupal-services-setup.yml @@ -13,6 +13,7 @@ foo: bar - config: force: true + services_file_content: "parameters: false" runner: | my_settings: foo: bar @@ -26,7 +27,7 @@ settings: foo: bar - config: - force: false + services_file_content: "parameters: false" runner: | my_settings: foo: bar