0
|
1 <?php
|
|
2 $localFile = __DIR__ . '/../../PEAR/Exception.php';
|
|
3 if (file_exists($localFile)) {
|
|
4 require_once $localFile;
|
|
5 } else {
|
|
6 require_once 'PEAR/Exception.php';
|
|
7 }
|
|
8
|
|
9 class PEAR_ExceptionTest extends PHPUnit_Framework_TestCase
|
|
10 {
|
|
11 /**
|
|
12 * @expectedException PEAR_Exception
|
|
13 * @expectedExceptionMessage foo
|
|
14 */
|
|
15 public function testThrow()
|
|
16 {
|
|
17 throw new PEAR_Exception('foo');
|
|
18 }
|
|
19
|
|
20 public function testGetCauseNone()
|
|
21 {
|
|
22 $e = new PEAR_Exception('foo bar');
|
|
23 $this->assertNull($e->getCause());
|
|
24 }
|
|
25
|
|
26 public function testGetCauseException()
|
|
27 {
|
|
28 $cause = new Exception('foo bar');
|
|
29 $e = new PEAR_Exception('I caught an exception', $cause);
|
|
30 $this->assertNotNull($e->getCause());
|
|
31 $this->assertInstanceOf('Exception', $e->getCause());
|
|
32 $this->assertEquals($cause, $e->getCause());
|
|
33 }
|
|
34
|
|
35 public function testGetCauseMessage()
|
|
36 {
|
|
37 $cause = new Exception('foo bar');
|
|
38 $e = new PEAR_Exception('I caught an exception', $cause);
|
|
39
|
|
40 $e->getCauseMessage($causes);
|
|
41 $this->assertEquals('I caught an exception', $causes[0]['message']);
|
|
42 $this->assertEquals('foo bar', $causes[1]['message']);
|
|
43 }
|
|
44
|
|
45 public function testGetTraceSafe()
|
|
46 {
|
|
47 $e = new PEAR_Exception('oops');
|
|
48 $this->assertInternalType('array', $e->getTraceSafe());
|
|
49 }
|
|
50
|
|
51 public function testGetErrorClass()
|
|
52 {
|
|
53 $e = new PEAR_Exception('oops');
|
|
54 $this->assertEquals('PEAR_ExceptionTest', $e->getErrorClass());
|
|
55 }
|
|
56
|
|
57 public function testGetErrorMethod()
|
|
58 {
|
|
59 $e = new PEAR_Exception('oops');
|
|
60 $this->assertEquals('testGetErrorMethod', $e->getErrorMethod());
|
|
61 }
|
|
62
|
|
63 public function test__toString()
|
|
64 {
|
|
65 $e = new PEAR_Exception('oops');
|
|
66 $this->assertInternalType('string', (string) $e);
|
|
67 $this->assertContains('oops', (string) $e);
|
|
68 }
|
|
69
|
|
70 public function testToHtml()
|
|
71 {
|
|
72 $e = new PEAR_Exception('oops');
|
|
73 $html = $e->toHtml();
|
|
74 $this->assertInternalType('string', $html);
|
|
75 $this->assertContains('oops', $html);
|
|
76 }
|
|
77 }
|
|
78 ?>
|