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
|
--TEST--
ReflectionFiber basic tests
--FILE--
<?php
$callable = function (): void {
$reflection = new ReflectionFiber(Fiber::getCurrent());
echo "\nWithin Fiber:\n";
var_dump($reflection->getExecutingFile());
var_dump($reflection->getExecutingLine());
var_dump($reflection->getTrace());
Fiber::suspend();
};
$fiber = new Fiber($callable);
$reflection = new ReflectionFiber($fiber);
echo "Before Start:\n";
var_dump($fiber === $reflection->getFiber());
var_dump($callable === $reflection->getCallable());
$fiber->start();
echo "\nAfter Start:\n";
var_dump($reflection->getExecutingFile());
var_dump($reflection->getExecutingLine());
var_dump($callable === $reflection->getCallable());
var_dump($reflection->getTrace());
$fiber->resume();
echo "\nAfter Resume:\n";
$reflection->getTrace();
?>
--EXPECTF--
Before Start:
bool(true)
bool(true)
Within Fiber:
string(%d) "%sReflectionFiber_basic.php"
int(7)
array(2) {
[0]=>
array(7) {
["file"]=>
string(%d) "%sReflectionFiber_basic.php"
["line"]=>
int(8)
["function"]=>
string(8) "getTrace"
["class"]=>
string(15) "ReflectionFiber"
["object"]=>
object(ReflectionFiber)#4 (0) {
}
["type"]=>
string(2) "->"
["args"]=>
array(0) {
}
}
[1]=>
array(2) {
["function"]=>
string(%d) "{closure:%s:%d}"
["args"]=>
array(0) {
}
}
}
After Start:
string(%d) "%sReflectionFiber_basic.php"
int(9)
bool(true)
array(2) {
[0]=>
array(6) {
["file"]=>
string(%d) "%sReflectionFiber_basic.php"
["line"]=>
int(9)
["function"]=>
string(7) "suspend"
["class"]=>
string(5) "Fiber"
["type"]=>
string(2) "::"
["args"]=>
array(0) {
}
}
[1]=>
array(2) {
["function"]=>
string(%d) "{closure:%s:%d}"
["args"]=>
array(0) {
}
}
}
After Resume:
Fatal error: Uncaught Error: Cannot fetch information from a fiber that has not been started or is terminated in %sReflectionFiber_basic.php:%d
Stack trace:
#0 %sReflectionFiber_basic.php(%d): ReflectionFiber->getTrace()
#1 {main}
thrown in %sReflectionFiber_basic.php on line %d
|