1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
<?php
require_once(dirname(__FILE__) . '/../errors.php');
class TestOfErrorQueue extends UnitTestCase {
function setUp() {
$queue = &SimpleErrorQueue::instance();
$queue->clear();
}
function tearDown() {
$queue = &SimpleErrorQueue::instance();
$queue->clear();
}
function testSingleton() {
$this->assertReference(
SimpleErrorQueue::instance(),
SimpleErrorQueue::instance());
$this->assertIsA(SimpleErrorQueue::instance(), 'SimpleErrorQueue');
}
function testEmpty() {
$queue = &SimpleErrorQueue::instance();
$this->assertTrue($queue->isEmpty());
$this->assertFalse($queue->extract());
}
function testOrder() {
$queue = &SimpleErrorQueue::instance();
$queue->add(1024, 'Ouch', 'here.php', 100, array());
$this->assertFalse($queue->isEmpty());
$queue->add(512, 'Yuk', 'there.php', 101, array());
$this->assertEqual(
$queue->extract(),
array(1024, 'Ouch', 'here.php', 100, array()));
$this->assertEqual(
$queue->extract(),
array(512, 'Yuk', 'there.php', 101, array()));
$this->assertFalse($queue->extract());
}
}
class TestOfErrorTrap extends UnitTestCase {
var $_old;
function setUp() {
$this->_old = error_reporting(E_ALL);
set_error_handler('simpleTestErrorHandler');
}
function tearDown() {
restore_error_handler();
error_reporting($this->_old);
}
function testTrappedErrorPlacedInQueue() {
$queue = &SimpleErrorQueue::instance();
$this->assertFalse($queue->extract());
trigger_error('Ouch!');
list($severity, $message, $file, $line, $globals) = $queue->extract();
$this->assertEqual($message, 'Ouch!');
$this->assertEqual($file, __FILE__);
$this->assertFalse($queue->extract());
}
}
class TestOfErrors extends UnitTestCase {
var $_old;
function setUp() {
$this->_old = error_reporting(E_ALL);
}
function tearDown() {
error_reporting($this->_old);
}
function testDefaultWhenAllReported() {
error_reporting(E_ALL);
trigger_error('Ouch!');
$this->assertError('Ouch!');
}
function testNoticeWhenReported() {
error_reporting(E_ALL);
trigger_error('Ouch!', E_USER_NOTICE);
$this->assertError('Ouch!');
}
function testWarningWhenReported() {
error_reporting(E_ALL);
trigger_error('Ouch!', E_USER_WARNING);
$this->assertError('Ouch!');
}
function testErrorWhenReported() {
error_reporting(E_ALL);
trigger_error('Ouch!', E_USER_ERROR);
$this->assertError('Ouch!');
}
function testNoNoticeWhenNotReported() {
error_reporting(0);
trigger_error('Ouch!', E_USER_NOTICE);
$this->assertNoErrors();
}
function testNoWarningWhenNotReported() {
error_reporting(0);
trigger_error('Ouch!', E_USER_WARNING);
$this->assertNoErrors();
}
function testNoErrorWhenNotReported() {
error_reporting(0);
trigger_error('Ouch!', E_USER_ERROR);
$this->assertNoErrors();
}
function testNoticeSuppressedWhenReported() {
error_reporting(E_ALL);
@trigger_error('Ouch!', E_USER_NOTICE);
$this->assertNoErrors();
}
function testWarningSuppressedWhenReported() {
error_reporting(E_ALL);
@trigger_error('Ouch!', E_USER_WARNING);
$this->assertNoErrors();
}
function testErrorSuppressedWhenReported() {
error_reporting(E_ALL);
@trigger_error('Ouch!', E_USER_ERROR);
$this->assertNoErrors();
}
}
?>
|