Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ErrorHandlerTest.php
Go to the documentation of this file.
1 <?php
8 
9 use \Magento\Framework\App\ErrorHandler;
10 
11 class ErrorHandlerTest extends \PHPUnit\Framework\TestCase
12 {
16  protected $object;
17 
18  protected function setUp()
19  {
20  $this->object = new ErrorHandler();
21  }
22 
30  public function testHandler($errorNo, $errorStr, $errorFile, $expectedResult)
31  {
32  $this->assertEquals($expectedResult, $this->object->handler($errorNo, $errorStr, $errorFile, 11));
33  }
34 
38  public function handlerProvider()
39  {
40  return [
41  [0, 'DateTimeZone::__construct', 0, false],
42  [0, 0, 0, false]
43  ];
44  }
45 
53  public function testHandlerException($errorNo, $errorPhrase)
54  {
55  $errorStr = 'test_string';
56  $errorFile = 'test_file';
57  $errorLine = 'test_error_line';
58 
59  $exceptedExceptionMessage = sprintf('%s: %s in %s on line %s', $errorPhrase, $errorStr, $errorFile, $errorLine);
60  $this->expectException('Exception');
61  $this->expectExceptionMessage($exceptedExceptionMessage);
62 
63  $this->object->handler($errorNo, $errorStr, $errorFile, $errorLine);
64  }
65 
69  public function handlerProviderException()
70  {
71  return [
72  [E_ERROR, 'Error'],
73  [E_WARNING, 'Warning'],
74  [E_PARSE, 'Parse Error'],
75  [E_NOTICE, 'Notice'],
76  [E_CORE_ERROR, 'Core Error'],
77  [E_CORE_WARNING, 'Core Warning'],
78  [E_COMPILE_ERROR, 'Compile Error'],
79  [E_COMPILE_WARNING, 'Compile Warning'],
80  [E_USER_ERROR, 'User Error'],
81  [E_USER_WARNING, 'User Warning'],
82  [E_USER_NOTICE, 'User Notice'],
83  [E_STRICT, 'Strict Notice'],
84  [E_RECOVERABLE_ERROR, 'Recoverable Error'],
85  [E_DEPRECATED, 'Deprecated Functionality'],
86  [E_USER_DEPRECATED, 'User Deprecated Functionality'],
87  ['42', 'Unknown error (42)']
88  ];
89  }
90 }
testHandler($errorNo, $errorStr, $errorFile, $expectedResult)