Skip to content

Commit

Permalink
Issue #62: Allow users to define a custom Task Runner configuration a…
Browse files Browse the repository at this point in the history
…vailable in their home directory.
  • Loading branch information
drupol committed Feb 5, 2019
1 parent 2aa63e4 commit 0d36fdc
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/TaskRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
44 changes: 44 additions & 0 deletions tests/CommandsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
5 changes: 5 additions & 0 deletions tests/fixtures/userconfig.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
drupal:
root: "drupal"

wordpress:
root: "wordpress"
Empty file modified tests/sandbox/.gitkeep
100644 → 100755
Empty file.

0 comments on commit 0d36fdc

Please sign in to comment.