FunctionSetRejectionHandlerShouldInvokeLastHandlerForUnhandled.phpt 887 B

12345678910111213141516171819202122232425262728293031323334353637
  1. --TEST--
  2. The callback given to the last set_rejection_handler() should be invoked for 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. $ret = set_rejection_handler($first = function (Throwable $e): void {
  12. echo 'THIS WILL NEVER BE CALLED' . PHP_EOL;
  13. });
  14. // previous should be null
  15. var_dump($ret === null);
  16. $ret = set_rejection_handler(function (Throwable $e): void {
  17. echo 'Unhandled ' . get_class($e) . ': ' . $e->getMessage() . PHP_EOL;
  18. });
  19. // previous rejection handler should be first rejection handler callback
  20. var_dump($ret === $first);
  21. reject(new RuntimeException('foo'));
  22. echo 'done' . PHP_EOL;
  23. ?>
  24. --EXPECT--
  25. bool(true)
  26. bool(true)
  27. Unhandled RuntimeException: foo
  28. done