Changeset 1494

Show
Ignore:
Timestamp:
04/04/08 17:36:32 (6 months ago)
Author:
mikey
Message:

added possibility to return a default value other than null

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/peer/stubHeaderList.php

    r1486 r1494  
    177177     * returns value of header with given key 
    178178     * 
    179      * @param   string  $key  name of header 
     179     * @param   string  $key      name of header 
     180     * @param   mixed   $default  optional  value to return if given header not set 
    180181     * @return  string 
    181182     */ 
    182     public function get($key
     183    public function get($key, $default = null
    183184    { 
    184185        if ($this->containsKey($key) == true) { 
     
    186187        } 
    187188         
    188         return null
     189        return $default
    189190    } 
    190191 
  • trunk/src/test/php/net/stubbles/peer/stubHeaderListTestCase.php

    r1486 r1494  
    131131 
    132132    /** 
     133     * assert default values are returned if no header with given name is set 
     134     * 
     135     * @test 
     136     */ 
     137    public function get() 
     138    { 
     139        $this->assertNull($this->headerList->get('foo')); 
     140        $this->assertEquals('bar', $this->headerList->get('foo', 'bar')); 
     141        $this->headerList->put('foo', 'bar'); 
     142        $this->assertEquals('bar', $this->headerList->get('foo')); 
     143        $this->assertEquals('bar', $this->headerList->get('foo', 'bar')); 
     144    } 
     145 
     146    /** 
    133147     * assure that the headerlist clears correctly 
    134148     *