From 2f3dffebe51010e117f349023761141f67fdc37f Mon Sep 17 00:00:00 2001 From: Antonio De Marco Date: Wed, 20 Dec 2017 15:12:20 +0100 Subject: [PATCH 1/5] Issue #2: Initial work on phpunit and behat porting. --- grumphp.yml.dist | 1 + phpunit.xml.dist | 2 +- src/Commands/DrupalCommands.php | 5 +++ .../ReplaceConfigTokens.php | 43 ++++++++++++++++++ src/Tasks/ReplaceConfigTokens/loadTasks.php | 20 +++++++++ tests/AbstractTaskTest.php | 7 +-- tests/AbstractTest.php | 43 ++++++++++++++++++ tests/CommandsTest.php | 3 +- tests/Tasks/ReplaceConfigTokensTaskTest.php | 45 +++++++++++++++++++ .../tasks/replace-config-tokens/extract.yml | 17 +++++++ 10 files changed, 181 insertions(+), 5 deletions(-) create mode 100644 src/Tasks/ReplaceConfigTokens/ReplaceConfigTokens.php create mode 100644 src/Tasks/ReplaceConfigTokens/loadTasks.php create mode 100644 tests/AbstractTest.php create mode 100644 tests/Tasks/ReplaceConfigTokensTaskTest.php create mode 100644 tests/fixtures/tasks/replace-config-tokens/extract.yml diff --git a/grumphp.yml.dist b/grumphp.yml.dist index 81c1e59b..89ff24ce 100644 --- a/grumphp.yml.dist +++ b/grumphp.yml.dist @@ -3,5 +3,6 @@ imports: parameters: tasks.phpcs.ignore_patterns: - vendor/ + - loadTasks.php tasks.phpmd.exclude: - vendor/ diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 534178b5..5e58c0b8 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -6,7 +6,7 @@ convertErrorsToExceptions = "true" convertNoticesToExceptions = "true" convertWarningsToExceptions = "true" - processIsolation = "true" + processIsolation = "false" stopOnFailure = "false" syntaxCheck = "false" bootstrap = "vendor/autoload.php"> diff --git a/src/Commands/DrupalCommands.php b/src/Commands/DrupalCommands.php index a17477f2..c03f00b1 100644 --- a/src/Commands/DrupalCommands.php +++ b/src/Commands/DrupalCommands.php @@ -12,6 +12,11 @@ class DrupalCommands extends BaseCommands { /** + * Install target site. + * + * This command will install the target site using configuration values + * provided in runner.yml.dist (overridable by runner.yml). + * * @command drupal:site-install * * @option root Drupal root. diff --git a/src/Tasks/ReplaceConfigTokens/ReplaceConfigTokens.php b/src/Tasks/ReplaceConfigTokens/ReplaceConfigTokens.php new file mode 100644 index 00000000..f2a2c753 --- /dev/null +++ b/src/Tasks/ReplaceConfigTokens/ReplaceConfigTokens.php @@ -0,0 +1,43 @@ +task(ReplaceConfigTokens::class); + } +} diff --git a/tests/AbstractTaskTest.php b/tests/AbstractTaskTest.php index 04b76cca..f6fa46ee 100644 --- a/tests/AbstractTaskTest.php +++ b/tests/AbstractTaskTest.php @@ -2,6 +2,7 @@ namespace EC\OpenEuropa\TaskRunner\Tests; +use EC\OpenEuropa\TaskRunner\TaskRunner; use League\Container\ContainerAwareInterface; use League\Container\ContainerAwareTrait; use PHPUnit\Framework\TestCase; @@ -15,7 +16,7 @@ * * @package EC\OpenEuropa\TaskRunner\Tests */ -abstract class AbstractTaskTest extends TestCase implements ContainerAwareInterface +abstract class AbstractTaskTest extends AbstractTest implements ContainerAwareInterface { use TaskAccessor; use ContainerAwareTrait; @@ -25,8 +26,8 @@ abstract class AbstractTaskTest extends TestCase implements ContainerAwareInterf */ public function setup() { - $container = Robo::createDefaultContainer(null, new NullOutput()); - $this->setContainer($container); + $runner = new TaskRunner([], null, new NullOutput()); + $this->setContainer($runner->getContainer()); } /** diff --git a/tests/AbstractTest.php b/tests/AbstractTest.php new file mode 100644 index 00000000..f339189a --- /dev/null +++ b/tests/AbstractTest.php @@ -0,0 +1,43 @@ +getMethod($methodName); + $method->setAccessible(true); + + return $method->invokeArgs($object, $parameters); + } + + /** + * @param $filepath + * + * @return mixed + */ + protected function getFixtureContent($filepath) + { + return Yaml::parse(file_get_contents(__DIR__."/fixtures/{$filepath}")); + } +} diff --git a/tests/CommandsTest.php b/tests/CommandsTest.php index 63ff6b09..2bd86143 100644 --- a/tests/CommandsTest.php +++ b/tests/CommandsTest.php @@ -3,6 +3,7 @@ namespace EC\OpenEuropa\TaskRunner\Tests\Commands; use EC\OpenEuropa\TaskRunner\TaskRunner; +use EC\OpenEuropa\TaskRunner\Tests\AbstractTest; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Input\StringInput; use Symfony\Component\Console\Output\BufferedOutput; @@ -14,7 +15,7 @@ * * @package EC\OpenEuropa\TaskRunner\Tests\Commands */ -class CommandsTest extends TestCase +class CommandsTest extends AbstractTest { /** * @param string $command diff --git a/tests/Tasks/ReplaceConfigTokensTaskTest.php b/tests/Tasks/ReplaceConfigTokensTaskTest.php new file mode 100644 index 00000000..5da40271 --- /dev/null +++ b/tests/Tasks/ReplaceConfigTokensTaskTest.php @@ -0,0 +1,45 @@ +taskReplaceConfigTokens()->run(); + } + + /** + * @param string $text + * @param array $expected + * + * @dataProvider extractTokensDataProvider + */ + public function testExtractTokens($text, array $expected) + { + $task = new ReplaceConfigTokens(); + $actual = $this->invokeMethod($task, 'extractTokens', [$text]); + $this->assertEquals($expected, $actual); + } + + /** + * @return array + */ + public function extractTokensDataProvider() + { + return $this->getFixtureContent('tasks/replace-config-tokens/extract.yml'); + } +} diff --git a/tests/fixtures/tasks/replace-config-tokens/extract.yml b/tests/fixtures/tasks/replace-config-tokens/extract.yml new file mode 100644 index 00000000..6f425035 --- /dev/null +++ b/tests/fixtures/tasks/replace-config-tokens/extract.yml @@ -0,0 +1,17 @@ +- text: "test ${token.one.two}${token.three}" + expected: + '${token.one.two}': 'token.one.two' + '${token.three}': 'token.three' + +- text: "empty" + expected: [] + +- text: 'test ${token.one.${token.three}two},${token.four}' + expected: + '${token.three}': 'token.three' + '${token.four}': 'token.four' + +- text: '${toke!2#n.two},${token.four}' + expected: + '${token.four}': 'token.four' + From 2aed2476c1962ffb98148b340a0571676602ed47 Mon Sep 17 00:00:00 2001 From: Antonio De Marco Date: Wed, 20 Dec 2017 15:13:16 +0100 Subject: [PATCH 2/5] Issue #2: Restore process isolation. --- phpunit.xml.dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 5e58c0b8..534178b5 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -6,7 +6,7 @@ convertErrorsToExceptions = "true" convertNoticesToExceptions = "true" convertWarningsToExceptions = "true" - processIsolation = "false" + processIsolation = "true" stopOnFailure = "false" syntaxCheck = "false" bootstrap = "vendor/autoload.php"> From ad2568b5b5c9caf6578f39fc40c807e9bc17702d Mon Sep 17 00:00:00 2001 From: Antonio De Marco Date: Wed, 20 Dec 2017 18:21:31 +0100 Subject: [PATCH 3/5] Issue #2: Add replace task tests. --- .../ReplaceConfigTokens.php | 53 ++++++++++++++++++- src/Tasks/ReplaceConfigTokens/loadTasks.php | 8 +-- tests/AbstractTaskTest.php | 9 +++- tests/AbstractTest.php | 10 ++++ tests/CommandsTest.php | 2 +- tests/Tasks/ReplaceConfigTokensTaskTest.php | 26 +++++++-- .../tasks/replace-config-tokens/task.yml | 22 ++++++++ 7 files changed, 120 insertions(+), 10 deletions(-) create mode 100644 tests/fixtures/tasks/replace-config-tokens/task.yml diff --git a/src/Tasks/ReplaceConfigTokens/ReplaceConfigTokens.php b/src/Tasks/ReplaceConfigTokens/ReplaceConfigTokens.php index f2a2c753..422fbb13 100644 --- a/src/Tasks/ReplaceConfigTokens/ReplaceConfigTokens.php +++ b/src/Tasks/ReplaceConfigTokens/ReplaceConfigTokens.php @@ -4,8 +4,9 @@ use Robo\Common\BuilderAwareTrait; use Robo\Contract\BuilderAwareInterface; -use Robo\Result; use Robo\Task\BaseTask; +use Robo\Task\File\Replace; +use Robo\Task\Filesystem\FilesystemStack; /** * Class ReplaceConfigTokens @@ -18,12 +19,60 @@ class ReplaceConfigTokens extends BaseTask implements BuilderAwareInterface const TOKEN_REGEX = '/\$\{((\w+\.?)+)\}/'; + /** + * Source file. + * + * @var string + */ + protected $source; + + /** + * Destination file. + * + * @var string + */ + protected $destination; + + /** + * @var \Robo\Task\Filesystem\FilesystemStack + */ + protected $filesystem; + + /** + * @var \Robo\Task\File\Replace + */ + protected $replace; + + /** + * ReplaceConfigTokens constructor. + * + * @param string $source + * @param string $destination + */ + public function __construct($source, $destination) + { + $this->source = $source; + $this->destination = $destination; + $this->filesystem = new FilesystemStack(); + $this->replace = new Replace($destination); + } + /** * @return \Robo\Result */ public function run() { - return Result::success($this); + $content = file_get_contents($this->source); + $config = $this->getConfig(); + + $tokens = array_map(function ($key) use ($config) { + return $config->get($key); + }, $this->extractTokens($content)); + + return $this->collectionBuilder()->addTaskList([ + $this->filesystem->copy($this->source, $this->destination, true), + $this->replace->from(array_keys($tokens))->to(array_values($tokens)), + ])->run(); } /** diff --git a/src/Tasks/ReplaceConfigTokens/loadTasks.php b/src/Tasks/ReplaceConfigTokens/loadTasks.php index d493976b..e72660be 100644 --- a/src/Tasks/ReplaceConfigTokens/loadTasks.php +++ b/src/Tasks/ReplaceConfigTokens/loadTasks.php @@ -9,12 +9,14 @@ */ trait loadTasks { - /** + * @param $source + * @param $destination + * * @return \EC\OpenEuropa\TaskRunner\Tasks\ReplaceConfigTokens\ReplaceConfigTokens */ - public function taskReplaceConfigTokens() + public function taskReplaceConfigTokens($source, $destination) { - return $this->task(ReplaceConfigTokens::class); + return $this->task(ReplaceConfigTokens::class, $source, $destination); } } diff --git a/tests/AbstractTaskTest.php b/tests/AbstractTaskTest.php index f6fa46ee..f00199ae 100644 --- a/tests/AbstractTaskTest.php +++ b/tests/AbstractTaskTest.php @@ -6,6 +6,7 @@ use League\Container\ContainerAwareInterface; use League\Container\ContainerAwareTrait; use PHPUnit\Framework\TestCase; +use Symfony\Component\Console\Output\BufferedOutput; use Symfony\Component\Console\Output\NullOutput; use Robo\TaskAccessor; use Robo\Robo; @@ -21,12 +22,18 @@ abstract class AbstractTaskTest extends AbstractTest implements ContainerAwareIn use TaskAccessor; use ContainerAwareTrait; + /** + * @var \Symfony\Component\Console\Output\BufferedOutput + */ + protected $output; + /** * Setup hook. */ public function setup() { - $runner = new TaskRunner([], null, new NullOutput()); + $this->output = new BufferedOutput(); + $runner = new TaskRunner([], null, $this->output); $this->setContainer($runner->getContainer()); } diff --git a/tests/AbstractTest.php b/tests/AbstractTest.php index f339189a..c4071816 100644 --- a/tests/AbstractTest.php +++ b/tests/AbstractTest.php @@ -40,4 +40,14 @@ protected function getFixtureContent($filepath) { return Yaml::parse(file_get_contents(__DIR__."/fixtures/{$filepath}")); } + + /** + * @param $name + * + * @return string + */ + protected function getSandboxPath($name) + { + return __DIR__."/sandbox/{$name}"; + } } diff --git a/tests/CommandsTest.php b/tests/CommandsTest.php index 2bd86143..7b6d31bb 100644 --- a/tests/CommandsTest.php +++ b/tests/CommandsTest.php @@ -26,7 +26,7 @@ class CommandsTest extends AbstractTest */ public function testSiteInstall($command, array $config, array $expected) { - $configFile = __DIR__.'/sandbox/runner.test.yml'; + $configFile = $this->getSandboxPath('runner.test.yml'); file_put_contents($configFile, Yaml::dump($config)); $input = new StringInput("{$command} --simulate"); $output = new BufferedOutput(); diff --git a/tests/Tasks/ReplaceConfigTokensTaskTest.php b/tests/Tasks/ReplaceConfigTokensTaskTest.php index 5da40271..28216717 100644 --- a/tests/Tasks/ReplaceConfigTokensTaskTest.php +++ b/tests/Tasks/ReplaceConfigTokensTaskTest.php @@ -4,6 +4,8 @@ use EC\OpenEuropa\TaskRunner\Tasks\ReplaceConfigTokens\ReplaceConfigTokens; use EC\OpenEuropa\TaskRunner\Tests\AbstractTaskTest; +use Robo\Task\Simulator; +use Symfony\Component\Yaml\Yaml; /** * Class ReplaceConfigTokensTaskTest. @@ -16,10 +18,20 @@ class ReplaceConfigTokensTaskTest extends AbstractTaskTest /** * Test task. + * + * @param array $data + * @param array $expected + * + * @dataProvider testTaskDataProvider */ - public function testTask() + public function testTask(array $data, array $expected) { - $result = $this->taskReplaceConfigTokens()->run(); + $source = $this->getSandboxPath('source.yml'); + $destination = $this->getSandboxPath('destination.yml'); + file_put_contents($source, Yaml::dump($data)); + $this->taskReplaceConfigTokens($source, $destination)->run(); + $destinationData = Yaml::parse(file_get_contents($destination)); + $this->assertEquals($expected, $destinationData); } /** @@ -30,7 +42,7 @@ public function testTask() */ public function testExtractTokens($text, array $expected) { - $task = new ReplaceConfigTokens(); + $task = new ReplaceConfigTokens(null, null); $actual = $this->invokeMethod($task, 'extractTokens', [$text]); $this->assertEquals($expected, $actual); } @@ -42,4 +54,12 @@ public function extractTokensDataProvider() { return $this->getFixtureContent('tasks/replace-config-tokens/extract.yml'); } + + /** + * @return array + */ + public function testTaskDataProvider() + { + return $this->getFixtureContent('tasks/replace-config-tokens/task.yml'); + } } diff --git a/tests/fixtures/tasks/replace-config-tokens/task.yml b/tests/fixtures/tasks/replace-config-tokens/task.yml new file mode 100644 index 00000000..785009fe --- /dev/null +++ b/tests/fixtures/tasks/replace-config-tokens/task.yml @@ -0,0 +1,22 @@ +- source: + one: ${drupal.root} + two: + three: ${drupal.core} + expected: + one: "build" + two: + three: "8" + +- source: + missing: ${this.does.not.exists} + not-valid: "drupal.core" + ok: ${drupal.core} + expected: + missing: "" + not-valid: "drupal.core" + ok: "8" + +- source: + concat: "${drupal.core}/${drupal.root}" + expected: + concat: "8/build" From 626a7559bd4739a3d4b0cfe8566b24f9280fd556 Mon Sep 17 00:00:00 2001 From: Antonio De Marco Date: Sat, 23 Dec 2017 14:55:05 +0100 Subject: [PATCH 4/5] Issue #2: Initial setup commands. --- .gitignore | 2 +- config/commands/drupal.yml | 6 - config/commands/setup.yml | 10 ++ src/Commands/SetupCommands.php | 113 ++++++++++++++++++ src/TaskRunner.php | 1 + tests/AbstractTaskTest.php | 3 - tests/AbstractTest.php | 2 +- tests/CommandsTest.php | 9 +- .../{commands/drupal.yml => commands.yml} | 0 9 files changed, 127 insertions(+), 19 deletions(-) create mode 100644 config/commands/setup.yml create mode 100644 src/Commands/SetupCommands.php rename tests/fixtures/{commands/drupal.yml => commands.yml} (100%) diff --git a/.gitignore b/.gitignore index 65d6aeca..0eecb1d0 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,4 @@ phpunit.xml composer.lock behat.yml RoboFile.php -/tests/sandbox/* \ No newline at end of file +/tests/sandbox/*.yml \ No newline at end of file diff --git a/config/commands/drupal.yml b/config/commands/drupal.yml index b5534b8e..51351f61 100644 --- a/config/commands/drupal.yml +++ b/config/commands/drupal.yml @@ -1,14 +1,8 @@ command: - - # Drupal-related command options. drupal: - - # Global options, this will be forwarded to all commands in 'drupal:' namespace. options: root: ${drupal.root} base-url: ${drupal.base-url} - - # Install Drupal site. site-install: options: site-name: ${drupal.site.name} diff --git a/config/commands/setup.yml b/config/commands/setup.yml new file mode 100644 index 00000000..d7cc67b4 --- /dev/null +++ b/config/commands/setup.yml @@ -0,0 +1,10 @@ +command: + setup: + behat: + options: + source: "behat.yml.dist" + destination: "behat.yml" + phpunit: + options: + source: "phpunit.xml.dist" + destination: "phpunit.xml" diff --git a/src/Commands/SetupCommands.php b/src/Commands/SetupCommands.php new file mode 100644 index 00000000..25e23109 --- /dev/null +++ b/src/Commands/SetupCommands.php @@ -0,0 +1,113 @@ + drupal: + * > root: build + * + * Then its token format would be: ${drupal.root} + * + * @command setup:behat + * + * @option source Source configuration file. + * @option destination Destination configuration file. + * + * @aliases setup:b,sb + * + * @param array $options + * + * @return \Robo\Contract\TaskInterface + */ + public function setupBehat(array $options = [ + 'source' => InputOption::VALUE_REQUIRED, + 'destination' => InputOption::VALUE_REQUIRED, + ]) + { + return $this->taskReplaceConfigTokens($options['source'], $options['destination']); + } + + /** + * Setup PHPUnit. + * + * This command will copy phpunit.xml.dist in phpunit.xml and replace + * configuration tokens with values provided in runner.yml.dist/runner.yml. + * + * For example, given the following configuration: + * + * > drupal: + * > root: build + * + * Then its token format would be: ${drupal.root} + * + * @command setup:phpunit + * + * @option source Source configuration file. + * @option destination Destination configuration file. + * + * @aliases setup:p,sp + * + * @param array $options + * + * @return \Robo\Contract\TaskInterface + */ + public function setupPhpunit(array $options = [ + 'source' => InputOption::VALUE_REQUIRED, + 'destination' => InputOption::VALUE_REQUIRED, + ]) + { + return $this->taskReplaceConfigTokens($options['source'], $options['destination']); + } + + + /** + * Replace configuration tokens in a text file. + * + * This command will copy source file in destination file and replace + * configuration tokens with values provided in runner.yml.dist/runner.yml. + * + * For example, given the following configuration: + * + * > drupal: + * > root: build + * + * Then its token format would be: ${drupal.root} + * + * @command setup:replace + * + * @option source Source configuration file. + * @option destination Destination configuration file. + * + * @aliases setup:p,sp + * + * @param array $options + * + * @return \Robo\Contract\TaskInterface + */ + public function setupReplace(array $options = [ + 'source' => InputOption::VALUE_REQUIRED, + 'destination' => InputOption::VALUE_REQUIRED, + ]) + { + return $this->taskReplaceConfigTokens($options['source'], $options['destination']); + } +} diff --git a/src/TaskRunner.php b/src/TaskRunner.php index cea1f3a8..091f35d3 100644 --- a/src/TaskRunner.php +++ b/src/TaskRunner.php @@ -123,6 +123,7 @@ private function createConfiguration(array $configPaths) $configPaths = array_merge([ __DIR__.'/../config/runner.yml', __DIR__.'/../config/commands/drupal.yml', + __DIR__.'/../config/commands/setup.yml', ], $configPaths); return Robo::createConfiguration($configPaths); diff --git a/tests/AbstractTaskTest.php b/tests/AbstractTaskTest.php index f00199ae..8fff493c 100644 --- a/tests/AbstractTaskTest.php +++ b/tests/AbstractTaskTest.php @@ -5,11 +5,8 @@ use EC\OpenEuropa\TaskRunner\TaskRunner; use League\Container\ContainerAwareInterface; use League\Container\ContainerAwareTrait; -use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Output\BufferedOutput; -use Symfony\Component\Console\Output\NullOutput; use Robo\TaskAccessor; -use Robo\Robo; use Robo\Collection\CollectionBuilder; /** diff --git a/tests/AbstractTest.php b/tests/AbstractTest.php index c4071816..72ae8085 100644 --- a/tests/AbstractTest.php +++ b/tests/AbstractTest.php @@ -10,7 +10,7 @@ * * @package EC\OpenEuropa\TaskRunner\Tests */ -class AbstractTest extends TestCase +abstract class AbstractTest extends TestCase { /** diff --git a/tests/CommandsTest.php b/tests/CommandsTest.php index 7b6d31bb..4ad29967 100644 --- a/tests/CommandsTest.php +++ b/tests/CommandsTest.php @@ -44,13 +44,6 @@ public function testSiteInstall($command, array $config, array $expected) */ public function commandsDataProvider() { - $data = []; - $finder = new Finder(); - $finder->files()->name('*.yml')->in(__DIR__.'/fixtures/commands'); - foreach ($finder as $file) { - $data = array_merge($data, Yaml::parse($file->getContents())); - } - - return $data; + return $this->getFixtureContent('commands.yml'); } } diff --git a/tests/fixtures/commands/drupal.yml b/tests/fixtures/commands.yml similarity index 100% rename from tests/fixtures/commands/drupal.yml rename to tests/fixtures/commands.yml From 3aa1c2be6733e7582a2b61680726db6ccfeaa42e Mon Sep 17 00:00:00 2001 From: Antonio De Marco Date: Sun, 24 Dec 2017 12:19:52 +0100 Subject: [PATCH 5/5] 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'