1--TEST--
2ReflectionFiber basic tests
3--FILE--
4<?php
5
6$callable = function (): void {
7    $reflection = new ReflectionFiber(Fiber::getCurrent());
8    echo "\nWithin Fiber:\n";
9    var_dump($reflection->getExecutingFile());
10    var_dump($reflection->getExecutingLine());
11    var_dump($reflection->getTrace());
12    Fiber::suspend();
13};
14
15$fiber = new Fiber($callable);
16
17$reflection = new ReflectionFiber($fiber);
18
19echo "Before Start:\n";
20var_dump($fiber === $reflection->getFiber());
21var_dump($callable === $reflection->getCallable());
22
23$fiber->start();
24
25echo "\nAfter Start:\n";
26var_dump($reflection->getExecutingFile());
27var_dump($reflection->getExecutingLine());
28var_dump($callable === $reflection->getCallable());
29var_dump($reflection->getTrace());
30
31$fiber->resume();
32
33echo "\nAfter Resume:\n";
34$reflection->getTrace();
35
36?>
37--EXPECTF--
38Before Start:
39bool(true)
40bool(true)
41
42Within Fiber:
43string(%d) "%sReflectionFiber_basic.php"
44int(7)
45array(2) {
46  [0]=>
47  array(7) {
48    ["file"]=>
49    string(%d) "%sReflectionFiber_basic.php"
50    ["line"]=>
51    int(8)
52    ["function"]=>
53    string(8) "getTrace"
54    ["class"]=>
55    string(15) "ReflectionFiber"
56    ["object"]=>
57    object(ReflectionFiber)#4 (0) {
58    }
59    ["type"]=>
60    string(2) "->"
61    ["args"]=>
62    array(0) {
63    }
64  }
65  [1]=>
66  array(2) {
67    ["function"]=>
68    string(%d) "{closure:%s:%d}"
69    ["args"]=>
70    array(0) {
71    }
72  }
73}
74
75After Start:
76string(%d) "%sReflectionFiber_basic.php"
77int(9)
78bool(true)
79array(2) {
80  [0]=>
81  array(6) {
82    ["file"]=>
83    string(%d) "%sReflectionFiber_basic.php"
84    ["line"]=>
85    int(9)
86    ["function"]=>
87    string(7) "suspend"
88    ["class"]=>
89    string(5) "Fiber"
90    ["type"]=>
91    string(2) "::"
92    ["args"]=>
93    array(0) {
94    }
95  }
96  [1]=>
97  array(2) {
98    ["function"]=>
99    string(%d) "{closure:%s:%d}"
100    ["args"]=>
101    array(0) {
102    }
103  }
104}
105
106After Resume:
107
108Fatal error: Uncaught Error: Cannot fetch information from a fiber that has not been started or is terminated in %sReflectionFiber_basic.php:%d
109Stack trace:
110#0 %sReflectionFiber_basic.php(%d): ReflectionFiber->getTrace()
111#1 {main}
112  thrown in %sReflectionFiber_basic.php on line %d
113