From 81da3e303cdedce9585d8679655c3d054533967f Mon Sep 17 00:00:00 2001 From: D Vargas Date: Thu, 22 Aug 2019 22:09:01 +0200 Subject: [PATCH 01/15] OPENEUROPA-1739: Add services setup command. --- config/commands/drupal.yml | 5 ++ src/Commands/AbstractDrupalCommands.php | 63 ++++++++++++++++++++++++- 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/config/commands/drupal.yml b/config/commands/drupal.yml index b70aa52b..6c8893f6 100644 --- a/config/commands/drupal.yml +++ b/config/commands/drupal.yml @@ -30,6 +30,11 @@ command: drush-setup: options: 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: options: sites-subdir: ${drupal.site.sites_subdir} diff --git a/src/Commands/AbstractDrupalCommands.php b/src/Commands/AbstractDrupalCommands.php index 28e1592d..ac6bfe2c 100644 --- a/src/Commands/AbstractDrupalCommands.php +++ b/src/Commands/AbstractDrupalCommands.php @@ -316,8 +316,69 @@ public function drushSetup(array $options = [ } /** - * Setup Drupal settings overrides. + * Setup Drupal services overrides. + * + * This command will: + * + * - Copy "default.settings.php" to "settings.php", which will be overridden if existing + * - Append to "settings.php" an include operation for a "settings.override.php" file + * - Write settings specified at "drupal.settings" in "settings.override.php" + * + * Default settings can be customized in your local runner.yml.dist/runner.yml + * as shown below: + * + * > drupal: + * > settings: + * > config_directories: + * > sync: '../config/sync' + * > prod: '../config/prod' + * + * The settings override file name can be changed in the Task Runner + * configuration by setting the "drupal.site.settings_override_file" property. + * + * @command drupal:services-setup + * + * @option root Drupal root. + * @option sites-subdir Drupal site subdirectory. + * @option service-parameters Drupal site settings override filename. + * @option force Drupal force generation of a new settings.php. + * @option skip-permissions-setup Drupal skip permissions setup. * + * @param array $options + * + * @return \Robo\Collection\CollectionBuilder + */ + public function servicesSetup(array $options = [ + 'root' => InputOption::VALUE_REQUIRED, + 'sites-subdir' => InputOption::VALUE_REQUIRED, + 'service-parameters' => InputOption::VALUE_REQUIRED, + 'force' => false, + 'skip-permissions-setup' => 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)); + } + + $services_destination_file = $options['root'] . '/sites/' . $options['sites-subdir'] . '/services.yml'; + + $collection = []; + $collection[] = $this->taskFilesystemStack()->copy($services_options_file, $services_destination_file, (bool) $options['force']); + + if (!$options['skip-permissions-setup']) { + $collection[] = $this->permissionsSetup($options); + } + + return $this->collectionBuilder()->addTaskList($collection); + } + + /** + * Setup Drupal settings overrides. + ** * This command will: * * - Copy "default.settings.php" to "settings.php", which will be overridden if existing From 0b01fddfbc72e18005475667e8ca438b897c4905 Mon Sep 17 00:00:00 2001 From: D Vargas Date: Fri, 23 Aug 2019 22:39:22 +0200 Subject: [PATCH 02/15] OPENEUROPA-1739: Add services setup tests. --- src/Commands/AbstractDrupalCommands.php | 26 +++------- tests/Commands/DrupalCommandsTest.php | 50 +++++++++++++++++++ .../commands/drupal-services-setup.yml | 25 ++++++++++ 3 files changed, 82 insertions(+), 19 deletions(-) create mode 100644 tests/fixtures/commands/drupal-services-setup.yml diff --git a/src/Commands/AbstractDrupalCommands.php b/src/Commands/AbstractDrupalCommands.php index ac6bfe2c..1d57e618 100644 --- a/src/Commands/AbstractDrupalCommands.php +++ b/src/Commands/AbstractDrupalCommands.php @@ -316,31 +316,19 @@ public function drushSetup(array $options = [ } /** - * Setup Drupal services overrides. + * Setup Drupal services file. * - * This command will: - * - * - Copy "default.settings.php" to "settings.php", which will be overridden if existing - * - Append to "settings.php" an include operation for a "settings.override.php" file - * - Write settings specified at "drupal.settings" in "settings.override.php" - * - * Default settings can be customized in your local runner.yml.dist/runner.yml - * as shown below: - * - * > drupal: - * > settings: - * > config_directories: - * > sync: '../config/sync' - * > prod: '../config/prod' + * This command will copy the content of the file given in service-parameters to "services.yml" file in + * the site directory. * - * The settings override file name can be changed in the Task Runner - * configuration by setting the "drupal.site.settings_override_file" property. + * The services file name can be set in the Task Runner + * configuration by setting the "drupal.service_parameters" property. * * @command drupal:services-setup * + * @option service-parameters Drupal services filename. * @option root Drupal root. * @option sites-subdir Drupal site subdirectory. - * @option service-parameters Drupal site settings override filename. * @option force Drupal force generation of a new settings.php. * @option skip-permissions-setup Drupal skip permissions setup. * @@ -349,9 +337,9 @@ public function drushSetup(array $options = [ * @return \Robo\Collection\CollectionBuilder */ public function servicesSetup(array $options = [ + 'service-parameters' => InputOption::VALUE_REQUIRED, 'root' => InputOption::VALUE_REQUIRED, 'sites-subdir' => InputOption::VALUE_REQUIRED, - 'service-parameters' => InputOption::VALUE_REQUIRED, 'force' => false, 'skip-permissions-setup' => false, ]) diff --git a/tests/Commands/DrupalCommandsTest.php b/tests/Commands/DrupalCommandsTest.php index 30beb9ae..adf1ac31 100644 --- a/tests/Commands/DrupalCommandsTest.php +++ b/tests/Commands/DrupalCommandsTest.php @@ -68,6 +68,48 @@ public function testPermissions(array $config, $command, $expected_error, $expec $this->assertEquals($expected_settings_file_permission, $siteSettingsPermissions); } + /** + * 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) + { + $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(); + $input = new StringInput($command); + $runner = new TaskRunner($input, new BufferedOutput(), $this->getClassLoader()); + $runner->run(); + + $sites_subdir = isset($config['drupal']['site']['sites_subdir']) ? $config['drupal']['site']['sites_subdir'] : 'default'; + $services_destination_dir = $this->getSandboxRoot() . '/sites/' . $sites_subdir; + $services_destination_file = $services_destination_dir . '/services.yml'; + + foreach ($expected as $row) { + $content = file_get_contents($services_destination_file); + $this->assertContains($row['contains'], $content); + } + } + /** * @return array */ @@ -75,4 +117,12 @@ public function drupalSettingsDataProvider() { return $this->getFixtureContent('commands/drupal-site-install.yml'); } + + /** + * @return array + */ + public function servicesSetupDataProvider() + { + return $this->getFixtureContent('commands/drupal-services-setup.yml'); + } } diff --git a/tests/fixtures/commands/drupal-services-setup.yml b/tests/fixtures/commands/drupal-services-setup.yml new file mode 100644 index 00000000..4aae13a2 --- /dev/null +++ b/tests/fixtures/commands/drupal-services-setup.yml @@ -0,0 +1,25 @@ +- config: + drupal: + site: + sites_subdir: 'site1' + service_parameters: "default.services.yml" + data: + services: + content: > + parameters: + http.response.debug_cacheability_headers: 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" From d1c58da8a3c359463e6b12a495c6a177c1239d2a Mon Sep 17 00:00:00 2001 From: D Vargas Date: Tue, 27 Aug 2019 13:09:59 +0200 Subject: [PATCH 03/15] OPENEUROPA-1739: Add simulating test. --- README.md | 1 + src/Commands/AbstractDrupalCommands.php | 8 +------- tests/fixtures/simulation.yml | 6 ++++++ 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 6edc2fe6..8ad73e13 100644 --- a/README.md +++ b/README.md @@ -125,6 +125,7 @@ The Task Runner comes with the following built-in commands: | `drupal:site-install` | Install a target Drupal site using default configuration values and/or CLI options | | `drupal:site-pre-install` | Run Drupal pre-install commands as listed under the `drupal.pre_install` property | | `drupal:site-post-install` | Run Drupal post-install commands as listed under the `drupal.post_install` property | +| `drupal:services-setup` | Create services file in site directory by copying given file (as parameter or in `drupal.service_parameters`) | | `drupal:settings-setup` | Setup default Drupal settings file by appending values specified at `drupal.settings` | | `drupal:drush-setup` | Setup Drush 8 and 9 configuration files | | `release:create-archive` | Create and archive a release for the current project | diff --git a/src/Commands/AbstractDrupalCommands.php b/src/Commands/AbstractDrupalCommands.php index 1d57e618..7ab9ccd6 100644 --- a/src/Commands/AbstractDrupalCommands.php +++ b/src/Commands/AbstractDrupalCommands.php @@ -329,8 +329,7 @@ public function drushSetup(array $options = [ * @option service-parameters Drupal services filename. * @option root Drupal root. * @option sites-subdir Drupal site subdirectory. - * @option force Drupal force generation of a new settings.php. - * @option skip-permissions-setup Drupal skip permissions setup. + * @option force Drupal force generation of a new services.yml. * * @param array $options * @@ -341,7 +340,6 @@ public function servicesSetup(array $options = [ 'root' => InputOption::VALUE_REQUIRED, 'sites-subdir' => InputOption::VALUE_REQUIRED, 'force' => false, - 'skip-permissions-setup' => false, ]) { $services_runner_file = $this->getConfig()->get('drupal.service_parameters'); @@ -357,10 +355,6 @@ public function servicesSetup(array $options = [ $collection = []; $collection[] = $this->taskFilesystemStack()->copy($services_options_file, $services_destination_file, (bool) $options['force']); - if (!$options['skip-permissions-setup']) { - $collection[] = $this->permissionsSetup($options); - } - return $this->collectionBuilder()->addTaskList($collection); } diff --git a/tests/fixtures/simulation.yml b/tests/fixtures/simulation.yml index 0d60fb4a..12aa9eaa 100644 --- a/tests/fixtures/simulation.yml +++ b/tests/fixtures/simulation.yml @@ -260,6 +260,12 @@ - "WriteConfiguration('web/sites/default/drushrc.php'" - "File\\Write('./drush/drush.yml')" +- command: 'drupal:services-setup --service-parameters=runner.yml' + configuration: [] + composer: '' + contains: + - "Filesystem\\FilesystemStack()\n ->copy('runner.yml', 'build/sites/default/services.yml'" + - command: 'drupal:settings-setup' configuration: [] composer: '' From c2a63f96e1ab0e3cc270a5046aab13b7e01731a5 Mon Sep 17 00:00:00 2001 From: D Vargas Date: Tue, 27 Aug 2019 15:01:40 +0200 Subject: [PATCH 04/15] OPENEUROPA-1739: Fix code after review. --- src/Commands/AbstractDrupalCommands.php | 4 ++-- tests/Commands/DrupalCommandsTest.php | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Commands/AbstractDrupalCommands.php b/src/Commands/AbstractDrupalCommands.php index 7ab9ccd6..b6610435 100644 --- a/src/Commands/AbstractDrupalCommands.php +++ b/src/Commands/AbstractDrupalCommands.php @@ -334,6 +334,7 @@ public function drushSetup(array $options = [ * @param array $options * * @return \Robo\Collection\CollectionBuilder + * @throws \Exception */ public function servicesSetup(array $options = [ 'service-parameters' => InputOption::VALUE_REQUIRED, @@ -352,8 +353,7 @@ public function servicesSetup(array $options = [ $services_destination_file = $options['root'] . '/sites/' . $options['sites-subdir'] . '/services.yml'; - $collection = []; - $collection[] = $this->taskFilesystemStack()->copy($services_options_file, $services_destination_file, (bool) $options['force']); + $collection = [$this->taskFilesystemStack()->copy($services_source_file, $services_destination_file, (bool) $options['force'])]; return $this->collectionBuilder()->addTaskList($collection); } diff --git a/tests/Commands/DrupalCommandsTest.php b/tests/Commands/DrupalCommandsTest.php index adf1ac31..22dd29bb 100644 --- a/tests/Commands/DrupalCommandsTest.php +++ b/tests/Commands/DrupalCommandsTest.php @@ -98,7 +98,9 @@ public function testServicesSetup(array $config, array $data, array $expected) $command = 'drupal:services-setup' . $service_parameter . ' --root=' . $this->getSandboxRoot() . ' --working-dir=' . $this->getSandboxRoot(); $input = new StringInput($command); $runner = new TaskRunner($input, new BufferedOutput(), $this->getClassLoader()); - $runner->run(); + $exit_code = $runner->run(); + + $this->assertEquals(0, $exit_code, 'Command run returned an error.'); $sites_subdir = isset($config['drupal']['site']['sites_subdir']) ? $config['drupal']['site']['sites_subdir'] : 'default'; $services_destination_dir = $this->getSandboxRoot() . '/sites/' . $sites_subdir; From e93ba775c7791dff323c8a66fec265d0fe1bfc02 Mon Sep 17 00:00:00 2001 From: D Vargas Date: Thu, 29 Aug 2019 16:12:15 +0200 Subject: [PATCH 05/15] OPENEUROPA-1739: Adapt to allow parameters to be set in runner file. --- config/commands/drupal.yml | 1 - src/Commands/AbstractDrupalCommands.php | 26 +++++++------------ tests/Commands/DrupalCommandsTest.php | 18 ++----------- .../commands/drupal-services-setup.yml | 26 ++++--------------- tests/fixtures/simulation.yml | 10 ++++--- 5 files changed, 24 insertions(+), 57 deletions(-) diff --git a/config/commands/drupal.yml b/config/commands/drupal.yml index 6c8893f6..a0669e32 100644 --- a/config/commands/drupal.yml +++ b/config/commands/drupal.yml @@ -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: diff --git a/src/Commands/AbstractDrupalCommands.php b/src/Commands/AbstractDrupalCommands.php index b6610435..4a996487 100644 --- a/src/Commands/AbstractDrupalCommands.php +++ b/src/Commands/AbstractDrupalCommands.php @@ -318,15 +318,11 @@ 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. @@ -334,26 +330,24 @@ public function drushSetup(array $options = [ * @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); } diff --git a/tests/Commands/DrupalCommandsTest.php b/tests/Commands/DrupalCommandsTest.php index 22dd29bb..d48f0909 100644 --- a/tests/Commands/DrupalCommandsTest.php +++ b/tests/Commands/DrupalCommandsTest.php @@ -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(); diff --git a/tests/fixtures/commands/drupal-services-setup.yml b/tests/fixtures/commands/drupal-services-setup.yml index 4aae13a2..906b6d3d 100644 --- a/tests/fixtures/commands/drupal-services-setup.yml +++ b/tests/fixtures/commands/drupal-services-setup.yml @@ -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" diff --git a/tests/fixtures/simulation.yml b/tests/fixtures/simulation.yml index 12aa9eaa..8dcd0dc5 100644 --- a/tests/fixtures/simulation.yml +++ b/tests/fixtures/simulation.yml @@ -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: [] From 648fe0cfe1767c225f0cd1d02ac49e213d076855 Mon Sep 17 00:00:00 2001 From: D Vargas Date: Thu, 29 Aug 2019 16:15:50 +0200 Subject: [PATCH 06/15] OPENEUROPA-1739: Adapt README file. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8ad73e13..96b33b23 100644 --- a/README.md +++ b/README.md @@ -125,7 +125,7 @@ The Task Runner comes with the following built-in commands: | `drupal:site-install` | Install a target Drupal site using default configuration values and/or CLI options | | `drupal:site-pre-install` | Run Drupal pre-install commands as listed under the `drupal.pre_install` property | | `drupal:site-post-install` | Run Drupal post-install commands as listed under the `drupal.post_install` property | -| `drupal:services-setup` | Create services file in site directory by copying given file (as parameter or in `drupal.service_parameters`) | +| `drupal:services-setup` | Create services file in site directory with parameters present in `drupal.service_parameters` | | `drupal:settings-setup` | Setup default Drupal settings file by appending values specified at `drupal.settings` | | `drupal:drush-setup` | Setup Drush 8 and 9 configuration files | | `release:create-archive` | Create and archive a release for the current project | From 19e698e73d4853bc37c5596ac3ca09c7bd94ff49 Mon Sep 17 00:00:00 2001 From: D Vargas Date: Thu, 29 Aug 2019 17:56:08 +0200 Subject: [PATCH 07/15] OPENEUROPA-1739: Add replacable parameters in test. --- tests/fixtures/commands/drupal-services-setup.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/fixtures/commands/drupal-services-setup.yml b/tests/fixtures/commands/drupal-services-setup.yml index 906b6d3d..3efefd59 100644 --- a/tests/fixtures/commands/drupal-services-setup.yml +++ b/tests/fixtures/commands/drupal-services-setup.yml @@ -1,9 +1,12 @@ - config: + my_settings: + cors: + on: false drupal: service_parameters: - cors.config: - enabled: false + cors_config: + enabled: ${my_settings.cors.on} expected: - contains: "parameters:" - - contains: "cors.config:" - - contains: "enabled: false" + - contains: "cors_config:" + - contains: "enabled: ''" From 88bc4064eac45afa09c393da338c26c83b5b217b Mon Sep 17 00:00:00 2001 From: D Vargas Date: Mon, 2 Sep 2019 19:20:35 +0200 Subject: [PATCH 08/15] OPENEUROPA-1739: Add more tests. --- .../commands/drupal-services-setup.yml | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/fixtures/commands/drupal-services-setup.yml b/tests/fixtures/commands/drupal-services-setup.yml index 3efefd59..785d5ea9 100644 --- a/tests/fixtures/commands/drupal-services-setup.yml +++ b/tests/fixtures/commands/drupal-services-setup.yml @@ -10,3 +10,29 @@ - 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" From 55eda9225a2cc3307453b31bab2550af09649877 Mon Sep 17 00:00:00 2001 From: Antonio De Marco Date: Tue, 3 Sep 2019 09:55:04 +0200 Subject: [PATCH 09/15] OPENEUROPA-1739: Improve dumped YAML format and tests. --- src/Commands/AbstractDrupalCommands.php | 10 +++-- tests/Commands/DrupalCommandsTest.php | 6 +-- .../commands/drupal-services-setup.yml | 42 ++++--------------- 3 files changed, 17 insertions(+), 41 deletions(-) diff --git a/src/Commands/AbstractDrupalCommands.php b/src/Commands/AbstractDrupalCommands.php index 4a996487..a62df16e 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; /** @@ -323,9 +324,9 @@ public function drushSetup(array $options = [ * * @command drupal:services-setup * - * @option root Drupal root. - * @option sites-subdir Drupal site subdirectory. - * @option force Drupal force generation of a new services.yml. + * @option root Drupal root. + * @option sites-subdir Drupal site subdirectory. + * @option force Drupal force generation of a new services.yml. * * @param array $options * @@ -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 From 07ddf79d9ba9a56558ca794a732677b11751a8f1 Mon Sep 17 00:00:00 2001 From: D Vargas Date: Wed, 4 Sep 2019 10:08:57 +0200 Subject: [PATCH 10/15] OPENEUROPA-1739: Add tests for force option. --- tests/Commands/DrupalCommandsTest.php | 31 +++++++++----- .../commands/drupal-services-setup.yml | 40 +++++++++++++++---- 2 files changed, 55 insertions(+), 16 deletions(-) diff --git a/tests/Commands/DrupalCommandsTest.php b/tests/Commands/DrupalCommandsTest.php index 863d3379..df271395 100644 --- a/tests/Commands/DrupalCommandsTest.php +++ b/tests/Commands/DrupalCommandsTest.php @@ -71,29 +71,42 @@ public function testPermissions(array $config, $command, $expected_error, $expec /** * Test the services file setup. * - * @param string $config + * @param array $configs * @param array $expected * * @dataProvider servicesSetupDataProvider */ - public function testServicesSetup($config, array $expected) + public function testServicesSetup(array $configs, array $expected) { + $config = $configs['runner']; $configFile = $this->getSandboxFilepath('runner.yml'); file_put_contents($configFile, $config); - $command = 'drupal:services-setup --root=' . $this->getSandboxRoot() . ' --working-dir=' . $this->getSandboxRoot(); + // Process information for destination file services.yml. + $sites_subdir = isset($config['drupal']['site']['sites_subdir']) ? $config['drupal']['site']['sites_subdir'] : 'default'; + $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'])) { + mkdir($services_destination_dir, 0777, true); + file_put_contents($services_destination_file, 'parameters: false'); + if ($configs['force']) { + $force = ' --force'; + } + } + + // Run the command. + $command = 'drupal:services-setup --root=' . $this->getSandboxRoot() . ' --working-dir=' . $this->getSandboxRoot() . $force; $input = new StringInput($command); $runner = new TaskRunner($input, new BufferedOutput(), $this->getClassLoader()); $exit_code = $runner->run(); - $this->assertEquals(0, $exit_code, 'Command run returned an error.'); - $sites_subdir = isset($config['drupal']['site']['sites_subdir']) ? $config['drupal']['site']['sites_subdir'] : 'default'; - $services_destination_dir = $this->getSandboxRoot() . '/sites/' . $sites_subdir; - $services_destination_file = $services_destination_dir . '/services.yml'; - + // Process given assertions. + $content = file_get_contents($services_destination_file); foreach ($expected as $row) { - $content = file_get_contents($services_destination_file); $this->assertContains($row['contains'], $content); } } diff --git a/tests/fixtures/commands/drupal-services-setup.yml b/tests/fixtures/commands/drupal-services-setup.yml index a342f70f..15ebba55 100644 --- a/tests/fixtures/commands/drupal-services-setup.yml +++ b/tests/fixtures/commands/drupal-services-setup.yml @@ -1,12 +1,38 @@ -- config: | - my_settings: - foo: bar - drupal: - service_parameters: - settings: - foo: ${my_settings.foo} +- config: + runner: | + my_settings: + foo: bar + drupal: + service_parameters: + settings: + foo: ${my_settings.foo} expected: - contains: | parameters: settings: foo: bar +- config: + force: true + runner: | + my_settings: + foo: bar + drupal: + service_parameters: + settings: + foo: ${my_settings.foo} + expected: + - contains: | + parameters: + settings: + foo: bar +- config: + force: false + runner: | + my_settings: + foo: bar + drupal: + service_parameters: + settings: + foo: ${my_settings.foo} + expected: + - contains: "parameters: false" From 9cea0e207faf861bca0cfae996d063640396052f Mon Sep 17 00:00:00 2001 From: D Vargas Date: Wed, 4 Sep 2019 11:36:38 +0200 Subject: [PATCH 11/15] OPENEUROPA-1739: Ensure compatibility with version 2 of simfony/yaml. --- src/Commands/AbstractDrupalCommands.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Commands/AbstractDrupalCommands.php b/src/Commands/AbstractDrupalCommands.php index a62df16e..e4e18d65 100644 --- a/src/Commands/AbstractDrupalCommands.php +++ b/src/Commands/AbstractDrupalCommands.php @@ -341,7 +341,14 @@ 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); + // Set flag to be compatible with symfony/yaml versions 2.x.x. (see https://github.com/symfony/yaml/blob/2.8/Dumper.php#L53) + if (property_exists(Yaml::class, 'DUMP_EXCEPTION_ON_INVALID_TYPE')) { + $flag = Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE; + } else { + $flag = true; + } + + $yaml = $dumper->dump($service_parameters, PHP_INT_MAX, 0, $flag); // Set the destination file. $services_destination_file = $options['root'] . '/sites/' . $options['sites-subdir'] . '/services.yml'; From beeb546d3f6071312bcd0d3ef2c6c417ff348e87 Mon Sep 17 00:00:00 2001 From: D Vargas Date: Wed, 4 Sep 2019 12:35:52 +0200 Subject: [PATCH 12/15] OPENEUROPA-1739: Ensure Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE exists by requiring simfony/yaml >3.1.0 --- composer.json | 6 +++++- src/Commands/AbstractDrupalCommands.php | 9 +-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index 11402243..757395f0 100644 --- a/composer.json +++ b/composer.json @@ -9,13 +9,17 @@ "require": { "consolidation/robo": "^1.4", "gitonomy/gitlib": "^1.0", + "nuvoleweb/robo-config": "^0.2.1", "jakeasmith/http_build_url": "^1.0.1", - "nuvoleweb/robo-config": "^0.2.1" + "symfony/yaml": ">3.1.0" }, "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 e4e18d65..a62df16e 100644 --- a/src/Commands/AbstractDrupalCommands.php +++ b/src/Commands/AbstractDrupalCommands.php @@ -341,14 +341,7 @@ public function servicesSetup(array $options = [ // Read given parameters. $service_parameters['parameters'] = $this->getConfig()->get('drupal.service_parameters'); $dumper = new Dumper(2); - // Set flag to be compatible with symfony/yaml versions 2.x.x. (see https://github.com/symfony/yaml/blob/2.8/Dumper.php#L53) - if (property_exists(Yaml::class, 'DUMP_EXCEPTION_ON_INVALID_TYPE')) { - $flag = Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE; - } else { - $flag = true; - } - - $yaml = $dumper->dump($service_parameters, PHP_INT_MAX, 0, $flag); + $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'; From 0d6d4dbaa0f1c67055360b8049a0100b44ccf82b Mon Sep 17 00:00:00 2001 From: D Vargas Date: Wed, 4 Sep 2019 17:04:27 +0200 Subject: [PATCH 13/15] OPENEUROPA-1739: Ensure services file is created without service_parameters in config. --- src/Commands/AbstractDrupalCommands.php | 2 +- tests/fixtures/commands/drupal-services-setup.yml | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Commands/AbstractDrupalCommands.php b/src/Commands/AbstractDrupalCommands.php index a62df16e..cbd590fe 100644 --- a/src/Commands/AbstractDrupalCommands.php +++ b/src/Commands/AbstractDrupalCommands.php @@ -339,7 +339,7 @@ public function servicesSetup(array $options = [ ]) { // Read given parameters. - $service_parameters['parameters'] = $this->getConfig()->get('drupal.service_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); diff --git a/tests/fixtures/commands/drupal-services-setup.yml b/tests/fixtures/commands/drupal-services-setup.yml index 15ebba55..3dd53ab0 100644 --- a/tests/fixtures/commands/drupal-services-setup.yml +++ b/tests/fixtures/commands/drupal-services-setup.yml @@ -36,3 +36,11 @@ foo: ${my_settings.foo} expected: - contains: "parameters: false" +- config: + runner: | + my_settings: + foo: bar + drupal: [] + expected: + - contains: | + parameters: { } \ No newline at end of file From fc5a85d18a438135f74e424f841c333851cd142d Mon Sep 17 00:00:00 2001 From: D Vargas Date: Mon, 9 Sep 2019 18:48:51 +0200 Subject: [PATCH 14/15] OPENEUROPA-1739: Fix code after review. --- composer.json | 5 +---- src/Commands/AbstractDrupalCommands.php | 19 +++++++++++++++---- tests/Commands/DrupalCommandsTest.php | 11 ++++------- .../commands/drupal-services-setup.yml | 3 ++- 4 files changed, 22 insertions(+), 16 deletions(-) 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 From a5a644093eb3bfa7dee3a2aa1673f485b477e824 Mon Sep 17 00:00:00 2001 From: D Vargas Date: Thu, 12 Dec 2019 12:38:32 +0100 Subject: [PATCH 15/15] OPENEUROPA-1739: OPENEUROPA-1739: Add cweagans/composer-patches dependency. --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index ded59312..cbcc1c4f 100644 --- a/composer.json +++ b/composer.json @@ -8,9 +8,10 @@ "prefer-stable": true, "require": { "consolidation/robo": "^1.4", + "cweagans/composer-patches": "^1.6", "gitonomy/gitlib": "^1.0", - "nuvoleweb/robo-config": "^0.2.1", "jakeasmith/http_build_url": "^1.0.1", + "nuvoleweb/robo-config": "^0.2.1", "symfony/yaml": "^3.4||4" }, "require-dev": {