Skip to content

Commit

Permalink
OPENEUROPA-1739: Improve dumped YAML format and tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ademarco committed Sep 3, 2019
1 parent dca43f0 commit 1939266
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 38 deletions.
4 changes: 3 additions & 1 deletion src/Commands/AbstractDrupalCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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';
Expand Down
6 changes: 3 additions & 3 deletions tests/Commands/DrupalCommandsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
42 changes: 8 additions & 34 deletions tests/fixtures/commands/drupal-services-setup.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1939266

Please sign in to comment.