Changeset 1398
- Timestamp:
- 03/04/08 18:46:18 (9 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/lang/exceptions/stubChainedException.php
r1209 r1398 35 35 36 36 /** 37 * checks whether a cause exists 38 * 39 * @return bool 40 */ 41 public function hasCause() 42 { 43 return null !== $this->cause; 44 } 45 46 /** 37 47 * returns the cause for this exception 38 48 * … … 42 52 { 43 53 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(); 44 72 } 45 73 trunk/src/test/php/net/stubbles/lang/exceptions/stubChainedExceptionTestCase.php
r1236 r1398 50 50 $this->stubChainedException1 = new stub1ChainedException('This is a chained exception.'); 51 51 $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'))); 52 53 } 53 54 54 55 /** 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 56 69 * 57 70 * @test … … 64 77 65 78 /** 66 * assure that the equal() method works correct 67 * assure that class name mapping works as expected 79 * the final message should be found 68 80 * 69 81 * @test 70 82 */ 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() 72 96 { 73 97 $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); 74 98 $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()); 75 100 } 76 101 }
