ReflectionFiber_basic.phpt 2.1 KB

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