FunctionSetRejectionHandlerThatUsesNestedSetRejectionHandlerShouldInvokeInnerHandlerForUnhandled.phpt 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. --TEST--
  2. The callback given to set_rejection_handler() should be invoked for outer unhandled rejection and may set new rejection handler for inner unhandled rejection
  3. --INI--
  4. # suppress legacy PHPUnit 7 warning for Xdebug 3
  5. xdebug.default_enable=
  6. --FILE--
  7. <?php
  8. use function React\Promise\reject;
  9. use function React\Promise\set_rejection_handler;
  10. require __DIR__ . '/../vendor/autoload.php';
  11. set_rejection_handler(function (Throwable $e): void {
  12. $ret = set_rejection_handler(function (Throwable $e): void {
  13. echo 'Unhandled inner ' . get_class($e) . ': ' . $e->getMessage() . PHP_EOL;
  14. });
  15. // previous rejection handler should be unset while handling a rejection
  16. var_dump($ret === null);
  17. reject(new \UnexpectedValueException('bar'));
  18. echo 'Unhandled outer ' . get_class($e) . ': ' . $e->getMessage() . PHP_EOL;
  19. });
  20. reject(new RuntimeException('foo'));
  21. echo 'done' . PHP_EOL;
  22. ?>
  23. --EXPECT--
  24. bool(true)
  25. Unhandled inner UnexpectedValueException: bar
  26. Unhandled outer RuntimeException: foo
  27. done