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/
|
||||
main.uml
|
||||
composer.lock
|
||||
.phpunit.result.cache
|
||||
|
@ -27,14 +27,15 @@ class ConfigBuilder implements ConfigurationInterface {
|
||||
->arrayNode('logger')
|
||||
->canBeEnabled()
|
||||
->children()
|
||||
->scalarNode('file')
|
||||
->end()
|
||||
->scalarNode('file')->end()
|
||||
->scalarNode('level')
|
||||
->defaultValue('ERROR')
|
||||
->validate()
|
||||
->IfNotInArray(['DEBUG', 'INFO', 'NOTICE', 'WARNING', 'ERROR', 'CRITICAL', 'ALERT', 'EMERGENCY'])
|
||||
->thenInvalid('Invalid log level %s')
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end();
|
||||
|
||||
foreach ($this->configs as $config) {
|
||||
|
@ -2,13 +2,13 @@
|
||||
|
||||
namespace Aerex\BaikalStorage\Configs;
|
||||
|
||||
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
||||
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
|
||||
|
||||
class TaskwarriorConfig {
|
||||
public function get() {
|
||||
$treeBuilder = new TreeBuilder();
|
||||
$node = $treeBuilder->root('taskwarrior');
|
||||
$node->children()
|
||||
$node = new ArrayNodeDefinition('taskwarrior');
|
||||
$node->canBeEnabled()
|
||||
->children()
|
||||
->scalarNode('taskdata')
|
||||
->defaultValue('~/.task')
|
||||
->end()
|
||||
|
@ -3,6 +3,7 @@ namespace Aerex\BaikalStorage;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Aerex\BaikalStorage\Configs\ConfigBuilder;
|
||||
use Aerex\BaikalStorage\Configs\TaskwarriorConfig;
|
||||
|
||||
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