Changeset 1398

Show
Ignore:
Timestamp:
03/04/08 18:46:18 (9 months ago)
Author:
mikey
Message:

added net::stubbles::lang::exceptions::stubChainedException::hasCause() and net::stubbles::lang::exceptions::stubChainedException::getFinalMessage()

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/lang/exceptions/stubChainedException.php

    r1209 r1398  
    3535 
    3636    /** 
     37     * checks whether a cause exists 
     38     * 
     39     * @return  bool 
     40     */ 
     41    public function hasCause() 
     42    { 
     43        return null !== $this->cause; 
     44    } 
     45 
     46    /** 
    3747     * returns the cause for this exception 
    3848     * 
     
    4252    { 
    4353        return $this->cause; 
     54    } 
     55 
     56    /** 
     57     * returns final message 
     58     * 
     59     * @return  string 
     60     */ 
     61    public function getFinalMessage() 
     62    { 
     63        if (null === $this->cause) { 
     64            return $this->getMessage(); 
     65        } 
     66         
     67        if (($this->cause instanceof stubChainedException) === false) { 
     68            return $this->cause->getMessage(); 
     69        } 
     70         
     71        return $this->cause->getFinalMessage(); 
    4472    } 
    4573 
  • trunk/src/test/php/net/stubbles/lang/exceptions/stubChainedExceptionTestCase.php

    r1236 r1398  
    5050        $this->stubChainedException1 = new stub1ChainedException('This is a chained exception.'); 
    5151        $this->stubChainedException2 = new stub2ChainedException('This is an exception.', $this->stubChainedException1); 
     52        $this->stubChainedException3 = new stub2ChainedException('foobar', new stub1ChainedException('This is a chained exception.', new Exception('baz'))); 
    5253    } 
    5354 
    5455    /** 
    55      * assure that class name mapping works as expected 
     56     * no cause means false, a cause true 
     57     * 
     58     * @test 
     59     */ 
     60    public function hasCause() 
     61    { 
     62        $this->assertFalse($this->stubChainedException1->hasCause()); 
     63        $this->assertTrue($this->stubChainedException2->hasCause()); 
     64        $this->assertTrue($this->stubChainedException3->hasCause()); 
     65    } 
     66 
     67    /** 
     68     * cause should be the same as set 
    5669     * 
    5770     * @test 
     
    6477 
    6578    /** 
    66      * assure that the equal() method works correct 
    67      * assure that class name mapping works as expected 
     79     * the final message should be found 
    6880     * 
    6981     * @test 
    7082     */ 
    71     public function toString() 
     83    public function getFinalMessage() 
     84    { 
     85        $this->assertEquals('This is a chained exception.', $this->stubChainedException1->getFinalMessage()); 
     86        $this->assertEquals('This is a chained exception.', $this->stubChainedException2->getFinalMessage()); 
     87        $this->assertEquals('baz', $this->stubChainedException3->getFinalMessage()); 
     88    } 
     89 
     90    /** 
     91     * string representation should contain some useful informations 
     92     * 
     93     * @test 
     94     */ 
     95    public function toStringResult() 
    7296    { 
    7397        $this->assertEquals("test::stub1ChainedException {\n    message(string): This is a chained exception.\n    file(string): " . __FILE__ . "\n    line(integer): 50\n    code(integer): 0\n}\n", (string) $this->stubChainedException1); 
    7498        $this->assertEquals("test::stub2ChainedException {\n    message(string): This is an exception.\n    file(string): " . __FILE__ . "\n    line(integer): 51\n    code(integer): 0\n} caused by test::stub1ChainedException {\n    message(string): This is a chained exception.\n    file(string): " . __FILE__ . "\n    line(integer): 50\n    code(integer): 0\n}\n", (string) $this->stubChainedException2); 
     99        $this->assertEquals("test::stub1ChainedException {\n    message(string): This is a chained exception.\n    file(string): " . __FILE__ . "\n    line(integer): 52\n    code(integer): 0\n} caused by Exception {\n    message(string): baz\n    file(string): " . __FILE__ . "\n    line(integer): 52\n    code(integer): 0\n}\n", (string) $this->stubChainedException3->getCause()); 
    75100    } 
    76101}