error_handler.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Set custom error handler.
  8. */
  9. function setCustomErrorHandler()
  10. {
  11. set_error_handler(
  12. function ($errNo, $errStr, $errFile, $errLine) {
  13. if (error_reporting()) {
  14. $errorNames = [
  15. E_ERROR => 'Error',
  16. E_WARNING => 'Warning',
  17. E_PARSE => 'Parse',
  18. E_NOTICE => 'Notice',
  19. E_CORE_ERROR => 'Core Error',
  20. E_CORE_WARNING => 'Core Warning',
  21. E_COMPILE_ERROR => 'Compile Error',
  22. E_COMPILE_WARNING => 'Compile Warning',
  23. E_USER_ERROR => 'User Error',
  24. E_USER_WARNING => 'User Warning',
  25. E_USER_NOTICE => 'User Notice',
  26. E_STRICT => 'Strict',
  27. E_RECOVERABLE_ERROR => 'Recoverable Error',
  28. E_DEPRECATED => 'Deprecated',
  29. E_USER_DEPRECATED => 'User Deprecated',
  30. ];
  31. $errName = isset($errorNames[$errNo]) ? $errorNames[$errNo] : "";
  32. throw new \PHPUnit\Framework\Exception(
  33. sprintf("%s: %s in %s:%s.", $errName, $errStr, $errFile, $errLine),
  34. $errNo
  35. );
  36. }
  37. }
  38. );
  39. }