Skip to content

Commit

Permalink
Add some tests for configuration groups.
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-1-anderson committed Jun 27, 2017
1 parent e5347db commit 98ec5a8
Showing 1 changed file with 91 additions and 0 deletions.
91 changes: 91 additions & 0 deletions tests/ConfigGroupTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php
namespace Consolidation\Config\Util;

use Consolidation\Config\Config;

class ConfigGroupTest extends \PHPUnit_Framework_TestCase
{
protected $config;

protected function setUp()
{
$data = [
// Define some configuration settings for the options for
// the commands my:foo and my:bar.
'command' => [
'my' => [
// commands.my.options.* apply to all my:* commands.
'options' => [
'path' => '/etc/common',
'priority' => 'normal',
],
'foo' => [
// commands.my.foo.options.* apply only to the my:foo command.
'options' => [
'name' => 'baz',
],
],
'bar' => [
// Similarly, commands.my.bar.options is for the my:bar command.
'options' => [
'priority' => 'high',
],
],
],
],
// Define some configuration settings for the configuration
// of some task \My\Tasks\Operations\Frobulate.
'task' => [
'Operations' => [
// task.Operations.settings apply to all tasks in
// any *.Tass.Operations namespace.
'settings' => [
'dir' => '/base/dir',
],
'Frobulate' => [
// task.Operations.Frobulate.settings applies only
// the Frobulate task.
'settings' => [
'object' => 'fire truck',
],
],
],
],
];

$this->config = new Config($data);
}

public function testDotNotation()
{
// Test the test
$this->assertEquals('baz', $this->config->get('command.my.foo.options.name'));
}

public function testFallback()
{
$fooFallback = new ConfigFallback($this->config, 'my.foo', 'command.', '.options.');
$barFallback = new ConfigFallback($this->config, 'my.bar', 'command.', '.options.');

$this->assertEquals(null, $barFallback->get('name'));
$this->assertEquals('baz', $fooFallback->get('name'));
$this->assertEquals('high', $barFallback->get('priority'));

$this->assertEquals('normal', $fooFallback->get('priority'));
$this->assertEquals('/etc/common', $barFallback->get('path'));
$this->assertEquals('/etc/common', $fooFallback->get('path'));
}

public function testMerge()
{
$frobulateMerge = new ConfigMerge($this->config, 'Operations.Frobulate', 'task.');

$settings = $frobulateMerge->get('settings');
$this->assertEquals('fire truck', $settings['object']);
$this->assertEquals('/base/dir', $settings['dir']);
$keys = array_keys($settings);
sort($keys);
$this->assertEquals('dir,object', implode(',', $keys));
}
}

0 comments on commit 98ec5a8

Please sign in to comment.