ErrorHandlerTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\App\Test\Unit;
  7. use \Magento\Framework\App\ErrorHandler;
  8. class ErrorHandlerTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /**
  11. * @var \Magento\Framework\App\ErrorHandler
  12. */
  13. protected $object;
  14. protected function setUp()
  15. {
  16. $this->object = new ErrorHandler();
  17. }
  18. /**
  19. * @param int $errorNo
  20. * @param string $errorStr
  21. * @param string $errorFile
  22. * @param bool $expectedResult
  23. * @dataProvider handlerProvider
  24. */
  25. public function testHandler($errorNo, $errorStr, $errorFile, $expectedResult)
  26. {
  27. $this->assertEquals($expectedResult, $this->object->handler($errorNo, $errorStr, $errorFile, 11));
  28. }
  29. /**
  30. * @return array
  31. */
  32. public function handlerProvider()
  33. {
  34. return [
  35. [0, 'DateTimeZone::__construct', 0, false],
  36. [0, 0, 0, false]
  37. ];
  38. }
  39. /**
  40. * Test handler() method with 'false' result
  41. *
  42. * @param int $errorNo
  43. * @param string $errorPhrase
  44. * @dataProvider handlerProviderException
  45. */
  46. public function testHandlerException($errorNo, $errorPhrase)
  47. {
  48. $errorStr = 'test_string';
  49. $errorFile = 'test_file';
  50. $errorLine = 'test_error_line';
  51. $expectedExceptionMessage = sprintf('%s: %s in %s on line %s', $errorPhrase, $errorStr, $errorFile, $errorLine);
  52. $this->expectException('Exception');
  53. $this->expectExceptionMessage($expectedExceptionMessage);
  54. $this->object->handler($errorNo, $errorStr, $errorFile, $errorLine);
  55. }
  56. /**
  57. * @return array
  58. */
  59. public function handlerProviderException()
  60. {
  61. return [
  62. [E_ERROR, 'Error'],
  63. [E_WARNING, 'Warning'],
  64. [E_PARSE, 'Parse Error'],
  65. [E_NOTICE, 'Notice'],
  66. [E_CORE_ERROR, 'Core Error'],
  67. [E_CORE_WARNING, 'Core Warning'],
  68. [E_COMPILE_ERROR, 'Compile Error'],
  69. [E_COMPILE_WARNING, 'Compile Warning'],
  70. [E_USER_ERROR, 'User Error'],
  71. [E_USER_WARNING, 'User Warning'],
  72. [E_USER_NOTICE, 'User Notice'],
  73. [E_STRICT, 'Strict Notice'],
  74. [E_RECOVERABLE_ERROR, 'Recoverable Error'],
  75. [E_DEPRECATED, 'Deprecated Functionality'],
  76. [E_USER_DEPRECATED, 'User Deprecated Functionality'],
  77. ['42', 'Unknown error (42)']
  78. ];
  79. }
  80. }