Skip to content

Commit 0a50c14

Browse files
committed
Add test for Fiber::getCoroutine() method
1 parent f1736c2 commit 0a50c14

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
--TEST--
2+
Fiber::getCoroutine() method
3+
--FILE--
4+
<?php
5+
6+
use function Async\spawn;
7+
use function Async\await;
8+
9+
// Test with coroutine
10+
$c = spawn(function() {
11+
$f = new Fiber(function() {
12+
Fiber::suspend();
13+
});
14+
15+
$f->start();
16+
17+
$coro = $f->getCoroutine();
18+
echo "Has coroutine: " . ($coro !== null ? "yes" : "no") . "\n";
19+
echo "Coroutine ID: " . $coro->getId() . "\n";
20+
echo "Is started: " . ($coro->isStarted() ? "yes" : "no") . "\n";
21+
echo "Is suspended: " . ($coro->isSuspended() ? "yes" : "no") . "\n";
22+
23+
$f->resume();
24+
});
25+
26+
await($c);
27+
28+
// Test without coroutine (regular fiber)
29+
$f = new Fiber(function() {
30+
Fiber::suspend();
31+
});
32+
33+
$f->start();
34+
35+
$coro = $f->getCoroutine();
36+
echo "Regular fiber coroutine: " . ($coro === null ? "null" : "not-null") . "\n";
37+
38+
$f->resume();
39+
40+
echo "OK\n";
41+
?>
42+
--EXPECT--
43+
Has coroutine: yes
44+
Coroutine ID: 2
45+
Is started: yes
46+
Is suspended: yes
47+
Regular fiber coroutine: null
48+
OK

0 commit comments

Comments
 (0)