Permalink
Browse files

fix #18673

  • Loading branch information...
1 parent f2c3adc commit 48e4552691f9561e6c2b9fdd37f1fad48745c5d4 pce committed Jul 18, 2011
Showing with 12 additions and 2 deletions.
  1. +4 −2 Config/Lite.php
  2. +8 −0 tests/Config_LiteTest.php
View
@@ -336,7 +336,9 @@ public function getString($sec, $key, $default = null)
*/
public function get($sec = null, $key = null, $default = null)
{
- if ((null !== $sec) && array_key_exists($key, $this->sections[$sec])) {
+ if ((null !== $sec) && array_key_exists($sec, $this->sections)
+ && isset($this->sections[$sec][$key])
+ ) {
return $this->sections[$sec][$key];
}
// global value
@@ -348,7 +350,7 @@ public function get($sec = null, $key = null, $default = null)
return $this->sections[$sec];
}
// all sections
- if ((null === $sec) && array_key_exists($sec, $this->sections)) {
+ if (null === $sec && array_key_exists($sec, $this->sections)) {
return $this->sections;
}
if (null !== $default) {
@@ -99,6 +99,14 @@ public function testGet()
$this->assertEquals(3, $counter);
}
+ public function testGetDefaultByNonExistingSection()
+ {
+ $this->config->read(dirname(__FILE__).'/test.cfg');
+ // fallback to default given value 3
+ $counter = $this->config->get('foo', 'nonexisting_counter_option', 3);
+ $this->assertEquals(3, $counter);
+ }
+
public function testGetGlobalOption()
{
$this->config->read(dirname(__FILE__).'/test.cfg');

0 comments on commit 48e4552

Please sign in to comment.