From e5347db75ec59c0327db51a892c8be5815973939 Mon Sep 17 00:00:00 2001 From: Greg Anderson Date: Mon, 26 Jun 2017 17:07:41 -0700 Subject: [PATCH] Add more tests to Config() class. --- src/Util/ApplyConfig.php | 25 +++++-------------------- tests/ConfigTest.php | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/Util/ApplyConfig.php b/src/Util/ApplyConfig.php index f44b104..d699298 100644 --- a/src/Util/ApplyConfig.php +++ b/src/Util/ApplyConfig.php @@ -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 { @@ -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 diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index 471cbf1..bdb5ac1 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -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();