Skip to content

Commit 455e45b

Browse files
committed
ext/standard: Add trampoline tests for tick and shutdown functions
1 parent 63f6251 commit 455e45b

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
Use a trampoline as a shutdown function
3+
--FILE--
4+
<?php
5+
6+
class TrampolineTest {
7+
public function __call(string $name, array $arguments) {
8+
echo 'Trampoline for ', $name, PHP_EOL;
9+
var_dump($arguments);
10+
}
11+
}
12+
$o = new TrampolineTest();
13+
$callback = [$o, 'shutdownTrampoline'];
14+
15+
echo "Before registering\n";
16+
17+
register_shutdown_function($callback, "arg1", "arg2");
18+
19+
echo "After registering\n";
20+
?>
21+
--EXPECT--
22+
Before registering
23+
After registering
24+
Trampoline for shutdownTrampoline
25+
array(2) {
26+
[0]=>
27+
string(4) "arg1"
28+
[1]=>
29+
string(4) "arg2"
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
--TEST--
2+
Use a trampoline as a tick function
3+
--FILE--
4+
<?php
5+
declare(ticks=1);
6+
7+
class TrampolineTest {
8+
public function __call(string $name, array $arguments) {
9+
echo 'Trampoline for ', $name, PHP_EOL;
10+
var_dump($arguments);
11+
}
12+
}
13+
$o = new TrampolineTest();
14+
$callback = [$o, 'trampoline'];
15+
16+
register_tick_function($callback, "arg1", "arg2");
17+
18+
echo "Tick function should run\n";
19+
20+
unregister_tick_function($callback);
21+
22+
echo "Tick function should be removed and not run\n";
23+
$o->notTickTrampoline("not in tick");
24+
25+
?>
26+
--EXPECT--
27+
Trampoline for trampoline
28+
array(2) {
29+
[0]=>
30+
string(4) "arg1"
31+
[1]=>
32+
string(4) "arg2"
33+
}
34+
Tick function should run
35+
Trampoline for trampoline
36+
array(2) {
37+
[0]=>
38+
string(4) "arg1"
39+
[1]=>
40+
string(4) "arg2"
41+
}
42+
Tick function should be removed and not run
43+
Trampoline for notTickTrampoline
44+
array(1) {
45+
[0]=>
46+
string(11) "not in tick"
47+
}

0 commit comments

Comments
 (0)