fix: Used ArrayNodeDefinition to append taskwarrior config to main
config
This commit is contained in:
parent
346e5c239b
commit
2f87752f6e
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
vendor/
|
vendor/
|
||||||
main.uml
|
main.uml
|
||||||
composer.lock
|
composer.lock
|
||||||
|
.phpunit.result.cache
|
||||||
|
@ -27,15 +27,16 @@ class ConfigBuilder implements ConfigurationInterface {
|
|||||||
->arrayNode('logger')
|
->arrayNode('logger')
|
||||||
->canBeEnabled()
|
->canBeEnabled()
|
||||||
->children()
|
->children()
|
||||||
->scalarNode('file')
|
->scalarNode('file')->end()
|
||||||
->end()
|
|
||||||
->scalarNode('level')
|
->scalarNode('level')
|
||||||
->defaultValue('ERROR')
|
->defaultValue('ERROR')
|
||||||
->validate()
|
->validate()
|
||||||
->IfNotInArray(['DEBUG', 'INFO', 'NOTICE', 'WARNING', 'ERROR', 'CRITICAL', 'ALERT', 'EMERGENCY'])
|
->IfNotInArray(['DEBUG', 'INFO', 'NOTICE', 'WARNING', 'ERROR', 'CRITICAL', 'ALERT', 'EMERGENCY'])
|
||||||
->thenInvalid('Invalid log level %s')
|
->thenInvalid('Invalid log level %s')
|
||||||
->end()
|
->end()
|
||||||
->end();
|
->end()
|
||||||
|
->end()
|
||||||
|
->end();
|
||||||
|
|
||||||
foreach ($this->configs as $config) {
|
foreach ($this->configs as $config) {
|
||||||
$ref = $ref->append($config->get());
|
$ref = $ref->append($config->get());
|
||||||
|
@ -2,24 +2,24 @@
|
|||||||
|
|
||||||
namespace Aerex\BaikalStorage\Configs;
|
namespace Aerex\BaikalStorage\Configs;
|
||||||
|
|
||||||
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
|
||||||
|
|
||||||
class TaskwarriorConfig {
|
class TaskwarriorConfig {
|
||||||
public function get() {
|
public function get() {
|
||||||
$treeBuilder = new TreeBuilder();
|
$node = new ArrayNodeDefinition('taskwarrior');
|
||||||
$node = $treeBuilder->root('taskwarrior');
|
$node->canBeEnabled()
|
||||||
$node->children()
|
->children()
|
||||||
->scalarNode('taskdata')
|
->scalarNode('taskdata')
|
||||||
->defaultValue('~/.task')
|
->defaultValue('~/.task')
|
||||||
->end()
|
->end()
|
||||||
->scalarNode('taskrc')
|
->scalarNode('taskrc')
|
||||||
->defaultValue('~/.taskrc')
|
->defaultValue('~/.taskrc')
|
||||||
->end()
|
->end()
|
||||||
->scalarNode('project_tag_suffix')
|
->scalarNode('project_tag_suffix')
|
||||||
->defaultValue('project_')
|
->defaultValue('project_')
|
||||||
->end()
|
->end()
|
||||||
->end();
|
->end();
|
||||||
|
|
||||||
return $node;
|
return $node;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ namespace Aerex\BaikalStorage;
|
|||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Aerex\BaikalStorage\Configs\ConfigBuilder;
|
use Aerex\BaikalStorage\Configs\ConfigBuilder;
|
||||||
|
use Aerex\BaikalStorage\Configs\TaskwarriorConfig;
|
||||||
|
|
||||||
class ConfigTest extends TestCase {
|
class ConfigTest extends TestCase {
|
||||||
|
|
||||||
@ -26,6 +27,24 @@ class ConfigTest extends TestCase {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testTaskwarriorConfig() {
|
||||||
|
$configs = new ConfigBuilder(__DIR__ . '/Fixtures/TaskwarriorConfig.yaml');
|
||||||
|
$configs->add(new TaskwarriorConfig());
|
||||||
|
$contents = $configs->loadYaml();
|
||||||
|
$this->assertEquals(sizeof($contents), 2);
|
||||||
|
$this->assertArrayHasKey('logger', $contents, 'config missing logger property');
|
||||||
|
$this->assertArrayHasKey('file', $contents['logger'], 'config missing logger.file property');
|
||||||
|
$this->assertArrayHasKey('level', $contents['logger'], 'config missing logger.level property');
|
||||||
|
$this->assertArrayHasKey('enabled', $contents['logger'], 'config missing logger.enabled property');
|
||||||
|
$this->assertArrayHasKey('taskwarrior', $contents, 'config missing taskwarrior property');
|
||||||
|
$this->assertArrayHasKey('taskrc', $contents['taskwarrior'], 'config missing taskwarrior.taskrc property');
|
||||||
|
$this->assertEquals($contents['taskwarrior']['taskrc'], '/home/aerex/.taskrc');
|
||||||
|
$this->assertArrayHasKey('taskdata', $contents['taskwarrior'], 'config missing taskwarrior.taskdata property');
|
||||||
|
$this->assertEquals($contents['taskwarrior']['taskdata'], '/home/aerex/.task');
|
||||||
|
$this->assertArrayHasKey('project_tag_suffix', $contents['taskwarrior'], 'config missing taskwarrior.taskdata property');
|
||||||
|
$this->assertEquals($contents['taskwarrior']['project_tag_suffix'], 'project_');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user