File tree Expand file tree Collapse file tree 2 files changed +64
-1
lines changed
Expand file tree Collapse file tree 2 files changed +64
-1
lines changed Original file line number Diff line number Diff line change 11--TEST--
2- Coroutine: getTrace() - returns empty array (TODO implementation)
2+ Coroutine: getTrace() - returns empty array for non-suspended coroutine
33--FILE--
44<?php
55
66use function Async \spawn ;
7+ use function Async \await ;
78
89$ coroutine = spawn (function () {
910 return "test " ;
1011});
1112
13+ // Wait for coroutine to complete
14+ await ($ coroutine );
15+
16+ // After completion, trace should be empty
1217$ trace = $ coroutine ->getTrace ();
1318
1419var_dump (is_array ($ trace ));
1520var_dump (count ($ trace ));
1621
22+ // Test with options parameter
23+ $ trace2 = $ coroutine ->getTrace (DEBUG_BACKTRACE_IGNORE_ARGS );
24+ var_dump (is_array ($ trace2 ));
25+ var_dump (count ($ trace2 ));
26+
27+ // Test with limit parameter
28+ $ trace3 = $ coroutine ->getTrace (DEBUG_BACKTRACE_PROVIDE_OBJECT , 5 );
29+ var_dump (is_array ($ trace3 ));
30+ var_dump (count ($ trace3 ));
31+
1732?>
1833--EXPECT--
1934bool(true)
35+ int(0)
36+ bool(true)
37+ int(0)
38+ bool(true)
2039int(0)
Original file line number Diff line number Diff line change 1+ --TEST--
2+ Coroutine: getTrace() - returns backtrace for suspended coroutine
3+ --FILE--
4+ <?php
5+
6+ use function Async \spawn ;
7+ use function Async \await ;
8+
9+ $ coroutine = spawn (function () {
10+ // This function will suspend
11+ Async \sleep (0.1 );
12+ return "test " ;
13+ });
14+
15+ // Get trace while coroutine is suspended
16+ $ trace = $ coroutine ->getTrace ();
17+
18+ var_dump (is_array ($ trace ));
19+ echo "Trace has entries: " . (count ($ trace ) > 0 ? "yes " : "no " ) . "\n" ;
20+
21+ // Test with DEBUG_BACKTRACE_IGNORE_ARGS
22+ $ traceNoArgs = $ coroutine ->getTrace (DEBUG_BACKTRACE_IGNORE_ARGS );
23+ var_dump (is_array ($ traceNoArgs ));
24+
25+ // Test with limit
26+ $ traceLimited = $ coroutine ->getTrace (DEBUG_BACKTRACE_PROVIDE_OBJECT , 2 );
27+ var_dump (is_array ($ traceLimited ));
28+
29+ // Wait for coroutine to complete
30+ await ($ coroutine );
31+
32+ // After completion, trace should be empty
33+ $ traceAfter = $ coroutine ->getTrace ();
34+ var_dump (is_array ($ traceAfter ));
35+ var_dump (count ($ traceAfter ) === 0 );
36+
37+ ?>
38+ --EXPECTF--
39+ bool(true)
40+ Trace has entries: %s
41+ bool(true)
42+ bool(true)
43+ bool(true)
44+ bool(true)
You can’t perform that action at this time.
0 commit comments