Ejemplo n.º 1
0
 public function merge($options)
 {
     if (!$options instanceof \Rapid\Config) {
         $options = new \Rapid\Config($options);
     }
     $this->options = array_merge($this->options, $options->options());
 }
Ejemplo n.º 2
0
 public function testMerge()
 {
     $options1 = array();
     for ($i = 0; $i < 5; $i++) {
         $options1['key_' . $i] = 'value_' . $i;
     }
     $options2 = array();
     for ($i = 5; $i < 10; $i++) {
         $options2['key_' . $i] = 'value_' . $i;
     }
     $test1Config = new \Rapid\Config($options1);
     for ($i = 0; $i < 10; $i++) {
         if ($i < 5) {
             $this->assertArrayHasKey('key_' . $i, $test1Config->options());
         } else {
             $this->assertArrayNotHasKey('key_' . $i, $test1Config->options());
         }
     }
     $test1Config->merge($options2);
     for ($i = 0; $i < 10; $i++) {
         $key = 'key_' . $i;
         $this->assertArrayHasKey($key, $test1Config->options());
         $this->assertEquals('value_' . $i, $test1Config->get($key));
     }
     $test2Config = new \Rapid\Config($options1);
     for ($i = 0; $i < 10; $i++) {
         if ($i < 5) {
             $this->assertArrayHasKey('key_' . $i, $test2Config->options());
         } else {
             $this->assertArrayNotHasKey('key_' . $i, $test2Config->options());
         }
     }
     $test2Config->merge(new \Rapid\Config($options2));
     for ($i = 0; $i < 10; $i++) {
         $key = 'key_' . $i;
         $this->assertArrayHasKey($key, $test2Config->options());
         $this->assertEquals('value_' . $i, $test2Config->get($key));
     }
 }