Browse files

v0.2.5; test: update of array values issue#12

  • Loading branch information...
1 parent 67b3399 commit 692c9fda3339ba4a214ed7ac63f2bde75f31c31c @pce pce committed Mar 30, 2016
Showing with 68 additions and 7 deletions.
  1. +2 −2 Config/Lite.php
  2. +17 −4 package.xml
  3. +49 −1 tests/Config_LiteTest.php
View
4 Config/Lite.php
@@ -380,7 +380,7 @@ public function getString($sec, $key, $default = null)
* if the option is not set, this is practical when dealing with
* editable files, to keep an application stable with default settings.
*
- * @param string $sec Section|null - null to get global option
+ * @param string $sec Section|null - null,$key to get global option
* @param string $key Key
* @param mixed $default return default value if is $key is not set
*
@@ -392,7 +392,7 @@ public function getString($sec, $key, $default = null)
*/
public function get($sec = null, $key = null, $default = null)
{
- // handle get without parameters, because we can
+ // handle get without parameters
if ((null === $sec) && (null === $key) && (null === $default)) {
return $this->sections;
}
View
21 package.xml
@@ -19,17 +19,17 @@ http://pear.php.net/dtd/package-2.0.xsd">
<email>pce@php.net</email>
<active>yes</active>
</lead>
- <date>2015-02-23</date>
+ <date>2016-03-30</date>
<version>
- <release>0.2.4</release>
- <api>0.2.4</api>
+ <release>0.2.5</release>
+ <api>0.2.5</api>
</version>
<stability>
<release>beta</release>
<api>beta</api>
</stability>
<license uri="http://www.gnu.org/copyleft/lesser.html">lgpl</license>
- <notes>* edit license of package to lgpl as declared in the sourcecode</notes>
+ <notes>* get without parameters returns all sections as documented</notes>
<contents>
<dir name="/">
<dir name="Config">
@@ -76,6 +76,19 @@ http://pear.php.net/dtd/package-2.0.xsd">
</dependencies>
<phprelease />
<changelog>
+ <release>
+ <version>
+ <release>0.2.5</release>
+ <api>0.2.5</api>
+ </version>
+ <stability>
+ <release>beta</release>
+ <api>beta</api>
+ </stability>
+ <date>2016-03-30</date>
+ <license uri="http://www.gnu.org/copyleft/lesser.html">lgpl</license>
+ <notes>* get without parameters returns all sections as documented</notes>
+ </release>
<release>
<version>
<release>0.2.4</release>
View
50 tests/Config_LiteTest.php
@@ -504,11 +504,59 @@ public function testGetAllSectionsWithGet()
array(
'users' => array('name' => 'John Doe', 'email' => 'john@doe.com'),
'servers' => array('dev' => '127.0.0.1', 'stage' => '140.10.10.1')
- ),
+ ),
$this->config->get());
}
+ public function testUpdateSectionByIndex()
+ {
+ $this->config->set('git', 'hidden', ['/home/git/repo1.git', '/home/git/repo2.git']);
+
+ $this->config->setFilename($this->filename);
+ $this->config->save();
+ $this->config->read();
+
+ $hidden = ($this->config->get('git', 'hidden'));
+ // update entry by index
+ $hidden[1] = "/home/git/repo2a.git";
+ // add entry
+ $hidden[] = "/home/git/repo3.git";
+ $this->config->setSection("git", ['hidden' => $hidden]);
+
+ $this->config->sync();
+
+ $this->assertEquals(
+ array(
+ 'hidden' => ['/home/git/repo1.git', '/home/git/repo2a.git', '/home/git/repo3.git']
+ ),
+ $this->config->get('git'));
+ }
+
+ public function testUpdateSection()
+ {
+ $this->config->set('git', 'repos', [
+ 'foo' => '/home/git/foo.git', 'bar' => '/home/git/bar.git', 'baz' => '/home/git/baz.git'
+ ]);
+
+ $this->config->setFilename($this->filename);
+ $this->config->save();
+ $this->config->read();
+
+ $repos = ($this->config->get('git', 'repos'));
+ $repos["foo"] = "/home/git/fizz.git";
+ $repos["bar"] = "/home/git/buzz.git";
+ unset($repos["baz"]);
+ $this->config->setSection("git", ['repos' => $repos]);
+
+ $this->config->sync();
+
+ $this->assertEquals(
+ array(
+ 'repos' => ['foo' => '/home/git/fizz.git', 'bar' => '/home/git/buzz.git']
+ ),
+ $this->config->get('git'));
+ }
}

0 comments on commit 692c9fd

Please sign in to comment.