Skip to content

Commit cb6666b

Browse files
committed
Improve tests
1 parent 78c5bac commit cb6666b

File tree

2 files changed

+125
-86
lines changed

2 files changed

+125
-86
lines changed

Zend/tests/get_error_handler.phpt

Lines changed: 62 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -8,61 +8,81 @@ class C {
88
static function handleStatic() {}
99
}
1010

11+
class Invokable {
12+
public function __invoke() {
13+
}
14+
}
15+
1116
function foo() {}
1217

13-
set_error_handler("foo");
14-
var_dump(get_error_handler());
18+
echo "No error handler\n";
19+
var_dump(get_error_handler() === null);
20+
21+
echo "\nFunction string\n";
22+
set_error_handler('foo');
23+
var_dump(get_error_handler() === 'foo');
1524

25+
echo "\nNULL\n";
1626
set_error_handler(null);
17-
var_dump(get_error_handler());
27+
var_dump(get_error_handler() === null);
1828

29+
echo "\nStatic method array\n";
1930
set_error_handler([C::class, 'handleStatic']);
20-
var_dump(get_error_handler());
31+
var_dump(get_error_handler() === [C::class, 'handleStatic']);
2132

33+
echo "\nStatic method string\n";
2234
set_error_handler('C::handleStatic');
23-
var_dump(get_error_handler());
35+
var_dump(get_error_handler() === 'C::handleStatic');
36+
37+
echo "\nInstance method array\n";
38+
set_error_handler([$c = new C(), 'handle']);
39+
var_dump(get_error_handler() === [$c, 'handle']);
40+
41+
echo "\nFirst class callable method\n";
42+
set_error_handler($f = (new C())->handle(...));
43+
var_dump(get_error_handler() === $f);
2444

25-
set_error_handler([new C(), 'handle']);
26-
var_dump(get_error_handler());
45+
echo "\nClosure\n";
46+
set_error_handler($f = function () {});
47+
var_dump(get_error_handler() === $f);
2748

28-
set_error_handler((new C())->handle(...));
29-
var_dump(get_error_handler());
49+
echo "\nInvokable\n";
50+
set_error_handler($object = new Invokable());
51+
var_dump(get_error_handler() === $object);
3052

31-
set_error_handler(function () {});
32-
var_dump(get_error_handler());
53+
echo "\nStable return value\n";
54+
var_dump(get_error_handler() === get_error_handler());
3355

3456
?>
3557
==DONE==
36-
--EXPECTF--
37-
string(3) "foo"
58+
--EXPECT--
59+
No error handler
60+
bool(true)
61+
62+
Function string
63+
bool(true)
64+
3865
NULL
39-
array(2) {
40-
[0]=>
41-
string(1) "C"
42-
[1]=>
43-
string(12) "handleStatic"
44-
}
45-
string(15) "C::handleStatic"
46-
array(2) {
47-
[0]=>
48-
object(C)#%d (0) {
49-
}
50-
[1]=>
51-
string(6) "handle"
52-
}
53-
object(Closure)#%d (2) {
54-
["function"]=>
55-
string(9) "C::handle"
56-
["this"]=>
57-
object(C)#%d (0) {
58-
}
59-
}
60-
object(Closure)#%d (3) {
61-
["name"]=>
62-
string(%d) "{closure:%s:%d}"
63-
["file"]=>
64-
string(%d) "%s"
65-
["line"]=>
66-
int(%d)
67-
}
66+
bool(true)
67+
68+
Static method array
69+
bool(true)
70+
71+
Static method string
72+
bool(true)
73+
74+
Instance method array
75+
bool(true)
76+
77+
First class callable method
78+
bool(true)
79+
80+
Closure
81+
bool(true)
82+
83+
Invokable
84+
bool(true)
85+
86+
Stable return value
87+
bool(true)
6888
==DONE==

Zend/tests/get_exception_handler.phpt

Lines changed: 63 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -8,61 +8,80 @@ class C {
88
static function handleStatic() {}
99
}
1010

11+
class Invokable {
12+
public function __invoke() {
13+
}
14+
}
15+
1116
function foo() {}
1217

13-
set_exception_handler("foo");
14-
var_dump(get_exception_handler());
18+
echo "No exception handler\n";
19+
var_dump(get_exception_handler() === null);
20+
21+
echo "\nFunction string\n";
22+
set_exception_handler('foo');
23+
var_dump(get_exception_handler() === 'foo');
1524

25+
echo "\nNULL\n";
1626
set_exception_handler(null);
17-
var_dump(get_exception_handler());
27+
var_dump(get_exception_handler() === null);
1828

29+
echo "\nStatic method array\n";
1930
set_exception_handler([C::class, 'handleStatic']);
20-
var_dump(get_exception_handler());
31+
var_dump(get_exception_handler() === [C::class, 'handleStatic']);
2132

33+
echo "\nStatic method string\n";
2234
set_exception_handler('C::handleStatic');
23-
var_dump(get_exception_handler());
35+
var_dump(get_exception_handler() === 'C::handleStatic');
2436

25-
set_exception_handler([new C(), 'handle']);
26-
var_dump(get_exception_handler());
37+
echo "\nInstance method array\n";
38+
set_exception_handler([$c = new C(), 'handle']);
39+
var_dump(get_exception_handler() === [$c, 'handle']);
2740

28-
set_exception_handler((new C())->handle(...));
29-
var_dump(get_exception_handler());
41+
echo "\nFirst class callable method\n";
42+
set_exception_handler($f = (new C())->handle(...));
43+
var_dump(get_exception_handler() === $f);
3044

31-
set_exception_handler(function () {});
32-
var_dump(get_exception_handler());
45+
echo "\nClosure\n";
46+
set_exception_handler($f = function () {});
47+
var_dump(get_exception_handler() === $f);
48+
49+
echo "\nInvokable\n";
50+
set_exception_handler($object = new Invokable());
51+
var_dump(get_exception_handler() === $object);
52+
53+
echo "\nStable return value\n";
54+
var_dump(get_exception_handler() === get_exception_handler());
55+
56+
?>==DONE==
57+
--EXPECT--
58+
No exception handler
59+
bool(true)
60+
61+
Function string
62+
bool(true)
3363

34-
?>
35-
==DONE==
36-
--EXPECTF--
37-
string(3) "foo"
3864
NULL
39-
array(2) {
40-
[0]=>
41-
string(1) "C"
42-
[1]=>
43-
string(12) "handleStatic"
44-
}
45-
string(15) "C::handleStatic"
46-
array(2) {
47-
[0]=>
48-
object(C)#%d (0) {
49-
}
50-
[1]=>
51-
string(6) "handle"
52-
}
53-
object(Closure)#%d (2) {
54-
["function"]=>
55-
string(9) "C::handle"
56-
["this"]=>
57-
object(C)#%d (0) {
58-
}
59-
}
60-
object(Closure)#%d (3) {
61-
["name"]=>
62-
string(%d) "{closure:%s:%d}"
63-
["file"]=>
64-
string(%d) "%s"
65-
["line"]=>
66-
int(%d)
67-
}
65+
bool(true)
66+
67+
Static method array
68+
bool(true)
69+
70+
Static method string
71+
bool(true)
72+
73+
Instance method array
74+
bool(true)
75+
76+
First class callable method
77+
bool(true)
78+
79+
Closure
80+
bool(true)
81+
82+
Invokable
83+
bool(true)
84+
85+
Stable return value
86+
bool(true)
6887
==DONE==

0 commit comments

Comments
 (0)