Skip to content

Commit

Permalink
Add more tests to Config() class.
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-1-anderson committed Jun 27, 2017
1 parent 594cacf commit e5347db
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
25 changes: 5 additions & 20 deletions src/Util/ApplyConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,12 @@
namespace Consolidation\Config\Util;

/**
* Fetch a configuration value from a configuration group. If the
* desired configuration value is not found in the most specific
* group named, keep stepping up to the next parent group until a
* value is located.
* Given an object that contains configuration methods, inject any
* configuration found in the configuration file.
*
* Given the following constructor inputs:
* - $prefix = "command."
* - $group = "foo.bar.baz"
* - $postfix = ".options."
* Then the `get` method will then consider, in order:
* - command.foo.bar.baz.options
* - command.foo.bar.options
* - command.foo.options
* If any of these contain an option for "$key", then return its value.
* The proper use for this method is to call setter methods of the
* provided object. Using configuration to call methods that do work
* is an abuse of this mechanism.
*/
class ApplyConfig
{
Expand All @@ -31,13 +23,6 @@ public function __construct($config, $group, $prefix = '', $postfix = '.')
}

/**
* Given an object that contains configuration methods, inject any
* configuration found in the configuration file.
*
* The proper use for this method is to call setter methods of the
* provided object. Using configuration to call methods that do work
* is an abuse of this mechanism.
*
* TODO: We could use reflection to test to see if the return type
* of the provided object is a reference to the object itself. All
* setter methods should do this. This test is insufficient to guarentee
Expand Down
20 changes: 20 additions & 0 deletions tests/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,26 @@

class ConfigTest extends \PHPUnit_Framework_TestCase
{
public function testDefault()
{
$data = [
'a' => 'foo',
'b' => 'bar',
'c' => 'boz',
];

$config = new Config($data);

$config->setDefault('c', 'other');
$config->setDefault('d', 'other');

$this->assertEquals('foo', $config->get('a'));
$this->assertEquals('boz', $config->get('c'));
$this->assertEquals('other', $config->get('d'));
$this->assertEquals('other', $config->getDefault('c'));
$this->assertEquals('', $config->get('e'));
}

public function testConfigurationWithCrossFileReferences()
{
$config = new Config();
Expand Down

0 comments on commit e5347db

Please sign in to comment.