FunctionSetRejectionHandlerThatTriggersErrorHandlerThatThrowsShouldTerminateProgramForUnhandled.phpt 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. --TEST--
  2. The callback given to set_rejection_handler() may trigger a fatal error which in turn throws an exception which will terminate the program 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. set_error_handler(function (int $_, string $errstr): void {
  12. throw new \OverflowException('This function should never throw');
  13. });
  14. set_rejection_handler(function (Throwable $e): void {
  15. trigger_error($e->getMessage(), E_USER_ERROR);
  16. });
  17. reject(new RuntimeException('foo'));
  18. echo 'NEVER';
  19. ?>
  20. --EXPECTF--
  21. Fatal error: Uncaught OverflowException from unhandled promise rejection handler: This function should never throw in %s:%d
  22. Stack trace:
  23. #0 [internal function]: {closure}(%S)
  24. #1 %s(%d): trigger_error(%S)
  25. #2 %s/src/Internal/RejectedPromise.php(%d): {closure}(%S)
  26. #3 %s/src/functions.php(%d): React\Promise\Internal\RejectedPromise->__destruct()
  27. #4 %s(%d): React\Promise\reject(%S)
  28. #5 %A{main}