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 */