bce3a526d80557eeb25610f5ec63706a51629e82
[m6w6/ext-http] / phpunit / ObjectTest.php
1 <?php
2
3 class eh extends http\Object {
4 }
5
6 class ObjectTest extends PHPUnit_Framework_TestCase {
7 function testDefaultErrorHandling() {
8 $this->assertEquals(http\Object::EH_NORMAL, http\Object::getDefaultErrorHandling());
9 http\Object::setDefaultErrorHandling(http\Object::EH_SUPPRESS);
10 $this->assertEquals(http\Object::EH_SUPPRESS, http\Object::getDefaultErrorHandling());
11 }
12
13 function testErrorHandling() {
14 $eh = new eh;
15 $this->assertEquals(eh::EH_NORMAL, $eh->getErrorHandling());
16 $eh->setErrorHandling(eh::EH_SUPPRESS);
17 $this->assertEquals(eh::EH_SUPPRESS, $eh->getErrorHandling());
18 }
19
20 function testSuppress() {
21 http\Object::setDefaultErrorHandling(http\Object::EH_SUPPRESS);
22 (new eh)->triggerError(E_USER_WARNING, http\Exception::E_UNKNOWN, "suppress");
23 }
24
25 function testException() {
26 http\Object::setDefaultErrorHandling(http\Object::EH_THROW);
27 $this->setExpectedException("http\\Exception");
28 (new eh)->triggerError(E_USER_WARNING, http\Exception::E_UNKNOWN, "exception");
29 }
30
31 function testNormalError() {
32 http\Object::setDefaultErrorHandling(http\Object::EH_NORMAL);
33 $this->setExpectedException("PHPUnit_Framework_Error_Warning");
34 (new eh)->triggerError(E_USER_WARNING, http\Exception::E_UNKNOWN, "warning");
35 }
36
37 function testSuppress2() {
38 $eh = new eh;
39 $eh->setErrorHandling(http\Object::EH_SUPPRESS);
40 $eh->triggerError(E_USER_WARNING, http\Exception::E_UNKNOWN, "suppress");
41 }
42
43 function testException2() {
44 $eh = new eh;
45 $eh->setErrorHandling(http\Object::EH_THROW);
46 $this->setExpectedException("http\\Exception");
47 $eh->triggerError(E_USER_WARNING, http\Exception::E_UNKNOWN, "exception");
48 }
49
50 function testNormalError2() {
51 $eh = new eh;
52 $eh->setErrorHandling(http\Object::EH_NORMAL);
53 $this->setExpectedException("PHPUnit_Framework_Error_Warning");
54 $eh->triggerError(E_USER_WARNING, http\Exception::E_UNKNOWN, "warning");
55 }
56
57 function testUnknownDefaultErrorHandling() {
58 $this->setExpectedException("PHPUnit_Framework_Error_Warning");
59 http\Object::setDefaultErrorHandling(12345);
60 }
61
62 function testUnknownErrorHandling() {
63 $eh = new eh;
64 $this->setExpectedException("PHPUnit_Framework_Error_Warning");
65 $eh->setErrorHandling(12345);
66 }
67 }
68