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 Jul 3, 2018
1 parent fcfadab commit 5548a0c
Show file tree
Hide file tree
Showing 3 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 @@ -164,6 +164,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 @@ -178,6 +178,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());
$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());
$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"

0 comments on commit 5548a0c

Please sign in to comment.