2 namespace Consolidation\Config\Util;
4 use Consolidation\Config\Config;
6 class ConfigGroupTest extends \PHPUnit_Framework_TestCase
10 protected function setUp()
13 // Define some configuration settings for the options for
14 // the commands my:foo and my:bar.
17 // commands.my.options.* apply to all my:* commands.
19 'path' => '/etc/common',
20 'priority' => 'normal',
23 // commands.my.foo.options.* apply only to the my:foo command.
29 // Similarly, commands.my.bar.options is for the my:bar command.
36 // Define some configuration settings for the configuration
37 // of some task \My\Tasks\Operations\Frobulate.
40 // task.Operations.settings apply to all tasks in
41 // any *.Tass.Operations namespace.
46 // task.Operations.Frobulate.settings applies only
47 // the Frobulate task.
49 'object' => 'fire truck',
56 $this->config = new Config($data);
59 public function testDotNotation()
62 $this->assertEquals('baz', $this->config->get('command.my.foo.options.name'));
65 public function testFallback()
67 $fooFallback = new ConfigFallback($this->config, 'my.foo', 'command.', '.options.');
68 $barFallback = new ConfigFallback($this->config, 'my.bar', 'command.', '.options.');
70 $this->assertEquals(null, $barFallback->get('name'));
71 $this->assertEquals('baz', $fooFallback->get('name'));
72 $this->assertEquals('high', $barFallback->get('priority'));
74 $this->assertEquals('normal', $fooFallback->get('priority'));
75 $this->assertEquals('/etc/common', $barFallback->get('path'));
76 $this->assertEquals('/etc/common', $fooFallback->get('path'));
79 public function testMerge()
81 $frobulateMerge = new ConfigMerge($this->config, 'Operations.Frobulate', 'task.');
83 $settings = $frobulateMerge->get('settings');
84 $this->assertEquals('fire truck', $settings['object']);
85 $this->assertEquals('/base/dir', $settings['dir']);
86 $keys = array_keys($settings);
88 $this->assertEquals('dir,object', implode(',', $keys));