From 3720095a0aea57ac2d1ab87fcd09e6622f91622e Mon Sep 17 00:00:00 2001 From: Antonio De Marco Date: Mon, 25 Jun 2018 11:40:48 +0200 Subject: [PATCH] OPENEUROPA-696: Make sure the Task Runner provides current working directory as a replaceable token. --- config/runner.yml | 4 ++++ src/TaskRunner.php | 8 ++++++-- tests/CommandsTest.php | 20 ++++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/config/runner.yml b/config/runner.yml index 6cae0551..e3622d13 100644 --- a/config/runner.yml +++ b/config/runner.yml @@ -5,8 +5,12 @@ # ----------------------------------------------------------------------------- # Global Task Runner settings # ----------------------------------------------------------------------------- +# +# The "runner.working_dir" will contain the full path to current working directory. +# @see OpenEuropa\TaskRunner\TaskRunner::createConfiguration() runner: bin_dir: "./vendor/bin" +# working_dir: ~ # ----------------------------------------------------------------------------- # Drupal-related settings. diff --git a/src/TaskRunner.php b/src/TaskRunner.php index 106c0fee..8f981a74 100644 --- a/src/TaskRunner.php +++ b/src/TaskRunner.php @@ -158,11 +158,15 @@ private function getCommandDiscovery() */ private function createConfiguration() { - return Robo::createConfiguration([ + $config = new Config(); + $config->set('runner.working_dir', realpath($this->workingDir)); + Robo::loadConfiguration([ __DIR__.'/../config/runner.yml', 'runner.yml.dist', 'runner.yml', - ]); + ], $config); + + return $config; } /** diff --git a/tests/CommandsTest.php b/tests/CommandsTest.php index f6a8463a..37de11c6 100644 --- a/tests/CommandsTest.php +++ b/tests/CommandsTest.php @@ -7,6 +7,7 @@ use OpenEuropa\TaskRunner\Tests\AbstractTest; use Symfony\Component\Console\Input\StringInput; use Symfony\Component\Console\Output\BufferedOutput; +use Symfony\Component\Console\Output\NullOutput; use Symfony\Component\Yaml\Yaml; /** @@ -158,6 +159,25 @@ public function testSettingsSetup(array $config, array $expected) } } + /** + * Test current working directory as a replaceable token. + */ + public function testWorkingDirectoryToken() + { + $configFile = $this->getSandboxFilepath('runner.yml'); + $config = [ + 'working_dir' => '${runner.working_dir}', + ]; + file_put_contents($configFile, Yaml::dump($config)); + + $input = new StringInput("list --working-dir=".$this->getSandboxRoot()); + $runner = new TaskRunner($input, new NullOutput()); + $runner->run(); + + $this->assertContains('/tests/sandbox', $runner->getConfig()->get('runner.working_dir')); + $this->assertContains('/tests/sandbox', $runner->getConfig()->get('working_dir')); + } + /** * @return array */