From 3aa1c2be6733e7582a2b61680726db6ccfeaa42e Mon Sep 17 00:00:00 2001 From: Antonio De Marco Date: Sun, 24 Dec 2017 12:19:52 +0100 Subject: [PATCH] Issue #2: Fix parser and test. --- .gitignore | 2 +- src/Commands/SetupCommands.php | 4 +- .../ReplaceConfigTokens.php | 2 +- tests/CommandsTest.php | 38 ++++++++++++++++-- tests/fixtures/setup.yml | 39 +++++++++++++++++++ .../fixtures/{commands.yml => simulation.yml} | 0 .../tasks/replace-config-tokens/extract.yml | 7 ++++ 7 files changed, 84 insertions(+), 8 deletions(-) create mode 100644 tests/fixtures/setup.yml rename tests/fixtures/{commands.yml => simulation.yml} (100%) diff --git a/.gitignore b/.gitignore index 0eecb1d0..65d6aeca 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,4 @@ phpunit.xml composer.lock behat.yml RoboFile.php -/tests/sandbox/*.yml \ No newline at end of file +/tests/sandbox/* \ No newline at end of file diff --git a/src/Commands/SetupCommands.php b/src/Commands/SetupCommands.php index 25e23109..3b59e96a 100644 --- a/src/Commands/SetupCommands.php +++ b/src/Commands/SetupCommands.php @@ -43,7 +43,7 @@ public function setupBehat(array $options = [ 'destination' => InputOption::VALUE_REQUIRED, ]) { - return $this->taskReplaceConfigTokens($options['source'], $options['destination']); + return $this->setupReplace($options); } /** @@ -75,7 +75,7 @@ public function setupPhpunit(array $options = [ 'destination' => InputOption::VALUE_REQUIRED, ]) { - return $this->taskReplaceConfigTokens($options['source'], $options['destination']); + return $this->setupReplace($options); } diff --git a/src/Tasks/ReplaceConfigTokens/ReplaceConfigTokens.php b/src/Tasks/ReplaceConfigTokens/ReplaceConfigTokens.php index 422fbb13..2b0c9d80 100644 --- a/src/Tasks/ReplaceConfigTokens/ReplaceConfigTokens.php +++ b/src/Tasks/ReplaceConfigTokens/ReplaceConfigTokens.php @@ -17,7 +17,7 @@ class ReplaceConfigTokens extends BaseTask implements BuilderAwareInterface { use BuilderAwareTrait; - const TOKEN_REGEX = '/\$\{((\w+\.?)+)\}/'; + const TOKEN_REGEX = '/\$\{(([A-Za-z_\-]+\.?)+)\}/'; /** * Source file. diff --git a/tests/CommandsTest.php b/tests/CommandsTest.php index 4ad29967..0b31ab58 100644 --- a/tests/CommandsTest.php +++ b/tests/CommandsTest.php @@ -22,9 +22,9 @@ class CommandsTest extends AbstractTest * @param array $config * @param array $expected * - * @dataProvider commandsDataProvider + * @dataProvider simulationDataProvider */ - public function testSiteInstall($command, array $config, array $expected) + public function testSimulation($command, array $config, array $expected) { $configFile = $this->getSandboxPath('runner.test.yml'); file_put_contents($configFile, Yaml::dump($config)); @@ -39,11 +39,41 @@ public function testSiteInstall($command, array $config, array $expected) } } + /** + * @param string $command + * @param string $content + * @param string $expected + * + * @dataProvider setupDataProvider + */ + public function testSetupCommands($command, $content, $expected) + { + $source = $this->getSandboxPath('source.yml'); + $destination = $this->getSandboxPath('destination.yml'); + file_put_contents($source, $content); + + $input = new StringInput("{$command} --source={$source} --destination={$destination}"); + $output = new BufferedOutput(); + $runner = new TaskRunner([], $input, $output); + $runner->run(); + + $actual = file_get_contents($destination); + $this->assertEquals($expected, $actual); + } + + /** + * @return array + */ + public function simulationDataProvider() + { + return $this->getFixtureContent('simulation.yml'); + } + /** * @return array */ - public function commandsDataProvider() + public function setupDataProvider() { - return $this->getFixtureContent('commands.yml'); + return $this->getFixtureContent('setup.yml'); } } diff --git a/tests/fixtures/setup.yml b/tests/fixtures/setup.yml new file mode 100644 index 00000000..0609d946 --- /dev/null +++ b/tests/fixtures/setup.yml @@ -0,0 +1,39 @@ +- command: setup:replace + content: > + test1: ${drupal.root} + test2: ${drupal.core} + expected: > + test1: build + test2: 8 + +- command: setup:behat + content: > + default: + extensions: + Behat\MinkExtension: + base_url: ${drupal.base-url} + formatters: + progress: ~ + expected: > + default: + extensions: + Behat\MinkExtension: + base_url: http://127.0.0.1:8888 + formatters: + progress: ~ + +- command: setup:phpunit + content: > + + + + + + + expected: > + + + + + + diff --git a/tests/fixtures/commands.yml b/tests/fixtures/simulation.yml similarity index 100% rename from tests/fixtures/commands.yml rename to tests/fixtures/simulation.yml diff --git a/tests/fixtures/tasks/replace-config-tokens/extract.yml b/tests/fixtures/tasks/replace-config-tokens/extract.yml index 6f425035..7d52ee70 100644 --- a/tests/fixtures/tasks/replace-config-tokens/extract.yml +++ b/tests/fixtures/tasks/replace-config-tokens/extract.yml @@ -15,3 +15,10 @@ expected: '${token.four}': 'token.four' +- + text: > + + + + expected: + '${drupal.base-url}': 'drupal.base-url'