From 193926626ef8059740b40d35bb3f3480a5fe1f2d Mon Sep 17 00:00:00 2001 From: Antonio De Marco Date: Tue, 3 Sep 2019 09:55:04 +0200 Subject: [PATCH] OPENEUROPA-1739: Improve dumped YAML format and tests. --- src/Commands/AbstractDrupalCommands.php | 4 +- tests/Commands/DrupalCommandsTest.php | 6 +-- .../commands/drupal-services-setup.yml | 42 ++++--------------- 3 files changed, 14 insertions(+), 38 deletions(-) diff --git a/src/Commands/AbstractDrupalCommands.php b/src/Commands/AbstractDrupalCommands.php index 4a996487..6e96b7c2 100644 --- a/src/Commands/AbstractDrupalCommands.php +++ b/src/Commands/AbstractDrupalCommands.php @@ -9,6 +9,7 @@ use OpenEuropa\TaskRunner\Traits as TaskRunnerTraits; use Symfony\Component\Console\Event\ConsoleCommandEvent; use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Yaml\Dumper; use Symfony\Component\Yaml\Yaml; /** @@ -339,7 +340,8 @@ public function servicesSetup(array $options = [ { // Read given parameters. $service_parameters['parameters'] = $this->getConfig()->get('drupal.service_parameters'); - $yaml = Yaml::dump($service_parameters); + $dumper = new Dumper(2); + $yaml = $dumper->dump($service_parameters, PHP_INT_MAX, 0, Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE); // Set the destination file. $services_destination_file = $options['root'] . '/sites/' . $options['sites-subdir'] . '/services.yml'; diff --git a/tests/Commands/DrupalCommandsTest.php b/tests/Commands/DrupalCommandsTest.php index d48f0909..863d3379 100644 --- a/tests/Commands/DrupalCommandsTest.php +++ b/tests/Commands/DrupalCommandsTest.php @@ -71,15 +71,15 @@ public function testPermissions(array $config, $command, $expected_error, $expec /** * Test the services file setup. * - * @param array $config + * @param string $config * @param array $expected * * @dataProvider servicesSetupDataProvider */ - public function testServicesSetup(array $config, array $expected) + public function testServicesSetup($config, array $expected) { $configFile = $this->getSandboxFilepath('runner.yml'); - file_put_contents($configFile, Yaml::dump($config)); + file_put_contents($configFile, $config); $command = 'drupal:services-setup --root=' . $this->getSandboxRoot() . ' --working-dir=' . $this->getSandboxRoot(); $input = new StringInput($command); diff --git a/tests/fixtures/commands/drupal-services-setup.yml b/tests/fixtures/commands/drupal-services-setup.yml index 785d5ea9..a342f70f 100644 --- a/tests/fixtures/commands/drupal-services-setup.yml +++ b/tests/fixtures/commands/drupal-services-setup.yml @@ -1,38 +1,12 @@ -- config: +- config: | my_settings: - cors: - on: false + foo: bar drupal: service_parameters: - cors_config: - enabled: ${my_settings.cors.on} + settings: + foo: ${my_settings.foo} expected: - - contains: "parameters:" - - contains: "cors_config:" - - contains: "enabled: ''" - -- config: - my_settings: - cors: - on: true - drupal: - service_parameters: - cors_config: - enabled: ${my_settings.cors.on} - expected: - - contains: "parameters:" - - contains: "cors_config:" - - contains: "enabled: '1'" - -- config: - my_settings: - cors: - on: ok - drupal: - service_parameters: - cors_config: - enabled: ${my_settings.cors.on} - expected: - - contains: "parameters:" - - contains: "cors_config:" - - contains: "enabled: ok" + - contains: | + parameters: + settings: + foo: bar