Changeset 525

Show
Ignore:
Timestamp:
04/14/07 20:47:38 (1 year ago)
Author:
mikey
Message:

added remove(), removeConfig(), getKeys(), getConfigKeys()

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/util/stubRegistry.php

    r358 r525  
    6060 
    6161    /** 
     62     * removes a value from the registry 
     63     * 
     64     * @param  string  $key  key where the value is stored under 
     65     */ 
     66    public function remove($key) 
     67    { 
     68        if (isset(self::$registry[$key]) == true) { 
     69            unset(self::$registry[$key]); 
     70        } 
     71    } 
     72 
     73    /** 
     74     * removes a value from the config 
     75     * 
     76     * @param  string  $key  key where the value is stored under 
     77     */ 
     78    public function removeConfig($key) 
     79    { 
     80        if (isset(self::$config[$key]) == true) { 
     81            unset(self::$config[$key]); 
     82        } 
     83    } 
     84 
     85    /** 
    6286     * check if a value exists under the given key 
    6387     * 
     
    116140        return $default; 
    117141    } 
     142 
     143    /** 
     144     * returns all registry values 
     145     * 
     146     * @return  array<string,mixed> 
     147     */ 
     148    public static function getKeys() 
     149    { 
     150        return array_keys(self::$registry); 
     151    } 
     152 
     153    /** 
     154     * returns all configuration values 
     155     * 
     156     * @return  array<string,mixed> 
     157     */ 
     158    public static function getConfigKeys() 
     159    { 
     160        return array_keys(self::$config); 
     161    } 
    118162} 
    119163?> 
  • trunk/src/test/php/net/stubbles/ipo/request/filters/stubFloatFilterTestCase.php

    r360 r525  
    4747        $this->mockStubValidatorMax             = new MockStubValidator(); 
    4848        $this->mockStubRequestValueErrorFactory->setReturnValue('create', new stubRequestValueError('foo', array('en_EN' => 'Something wrent wrong.'))); 
     49    } 
     50 
     51    /** 
     52     * clean up test environment 
     53     */ 
     54    public function tearDown() 
     55    { 
     56        stubRegistry::removeConfig('net.stubbles.number.decimals'); 
    4957    } 
    5058 
     
    134142        $floatFilter->execute(11); 
    135143    } 
     144 
    136145    /** 
    137146     * assure that the correct value depending on $decimal_places is returned 
  • trunk/src/test/php/net/stubbles/util/stubRegistryTestCase.php

    r358 r525  
    2424        $this->assertEqual(stubRegistry::get('test', 'foo'), 'foo'); 
    2525        $this->assertFalse(stubRegistry::has('test')); 
     26        $this->assertEqual(stubRegistry::getKeys(), array()); 
    2627        stubRegistry::set('test', 'test'); 
    2728        $this->assertTrue(stubRegistry::has('test')); 
     
    3233        $regTest = stubRegistry::get('test'); 
    3334        $this->assertReference($regTest, $test); 
     35        $this->assertEqual(stubRegistry::getKeys(), array('test')); 
     36        stubRegistry::remove('test'); 
     37        $this->assertNull(stubRegistry::get('test')); 
     38        $this->assertFalse(stubRegistry::has('test')); 
     39        $this->assertEqual(stubRegistry::getKeys(), array()); 
    3440    } 
    3541 
     
    4248        $this->assertEqual(stubRegistry::getConfig('test', 'foo'), 'foo'); 
    4349        $this->assertFalse(stubRegistry::hasConfig('test')); 
     50        $this->assertEqual(stubRegistry::getConfigKeys(), array()); 
    4451        stubRegistry::setConfig('test', 'test'); 
    4552        $this->assertTrue(stubRegistry::hasConfig('test')); 
     
    5057        $regTest = stubRegistry::getConfig('test'); 
    5158        $this->assertReference($regTest, $test); 
     59        $this->assertEqual(stubRegistry::getConfigKeys(), array('test')); 
     60        stubRegistry::removeConfig('test'); 
     61        $this->assertNull(stubRegistry::getConfig('test')); 
     62        $this->assertFalse(stubRegistry::hasConfig('test')); 
     63        $this->assertEqual(stubRegistry::getConfigKeys(), array()); 
    5264    } 
    5365}