diff --git a/src/TaskRunner.php b/src/TaskRunner.php index bc3d334f..03e50438 100644 --- a/src/TaskRunner.php +++ b/src/TaskRunner.php @@ -144,6 +144,7 @@ private function createConfiguration() __DIR__.'/../config/runner.yml', 'runner.yml.dist', 'runner.yml', + getenv('TASKRUNNER_CONFIG') ?: getenv('HOME').'/.config/runner/runner.yml', ], $config); return $config; diff --git a/tests/CommandsTest.php b/tests/CommandsTest.php index 1a0a32c0..6b3cef37 100644 --- a/tests/CommandsTest.php +++ b/tests/CommandsTest.php @@ -336,6 +336,50 @@ public function testWorkingDirectoryToken() $this->assertContains('/tests/sandbox', $runner->getConfig()->get('working_dir')); } + /** + * Test the user config. + */ + public function testUserConfigFile() + { + $fixtureName = 'userconfig.yml'; + + $settings = [ + 'TASKRUNNER_CONFIG' => __DIR__ . '/fixtures/' . $fixtureName, + ]; + + // Convert the array into a proper string. + $envSettings = implode(' ', array_map( + function ($value, $key) { + return sprintf('%s=%s', $key, $value); + }, + $settings, + array_keys($settings) + )); + + // Create a runner. + $input = new StringInput('list --working-dir=' . $this->getSandboxRoot()); + $runner = new TaskRunner($input, new NullOutput(), $this->getClassLoader()); + $runner->run(); + + // Extract a value from the default configuration. + $drupalRoot = $runner->getConfig()->get('drupal.root'); + + // Add the environment setting. + putenv($envSettings); + + // Create a new runner. + $input = new StringInput('list --working-dir=' . $this->getSandboxRoot()); + $runner = new TaskRunner($input, new NullOutput(), $this->getClassLoader()); + $runner->run(); + + // Get the content of the fixture. + $content = $this->getFixtureContent($fixtureName); + + $this->assertEquals($content['wordpress'], $runner->getConfig()->get('wordpress')); + $this->assertEquals($content['drupal']['root'], $runner->getConfig()->get('drupal.root')); + $this->assertNotEquals($drupalRoot, $runner->getConfig()->get('drupal.root')); + } + /** * @return array */ diff --git a/tests/fixtures/userconfig.yml b/tests/fixtures/userconfig.yml new file mode 100644 index 00000000..c0e02103 --- /dev/null +++ b/tests/fixtures/userconfig.yml @@ -0,0 +1,5 @@ +drupal: + root: "drupal" + +wordpress: + root: "wordpress" diff --git a/tests/sandbox/.gitkeep b/tests/sandbox/.gitkeep old mode 100644 new mode 100755