3 * Tests for ErrorHandler
6 declare(strict_types
=1);
8 namespace PhpMyAdmin\Tests
;
10 use PhpMyAdmin\ErrorHandler
;
11 use const E_RECOVERABLE_ERROR
;
12 use const E_USER_NOTICE
;
13 use const E_USER_WARNING
;
16 class ErrorHandlerTest
extends AbstractTestCase
18 /** @var ErrorHandler */
22 * Sets up the fixture, for example, opens a network connection.
23 * This method is called before a test is executed.
27 protected function setUp(): void
30 parent
::loadDefaultConfig();
31 $this->object = new ErrorHandler();
32 $_SESSION['errors'] = [];
33 $GLOBALS['server'] = 0;
34 $GLOBALS['cfg']['SendErrorReports'] = 'always';
38 * Tears down the fixture, for example, closes a network connection.
39 * This method is called after a test is executed.
43 protected function tearDown(): void
50 * Data provider for testHandleError
52 * @return array data for testHandleError
54 public function providerForTestHandleError(): array
77 * Test for getDispErrors when PHP errors are not shown
79 * @param int $errno error number
80 * @param string $errstr error string
81 * @param string $errfile error file
82 * @param int $errline error line
83 * @param string $output_show expected output if showing of errors is
85 * @param string $output_hide expected output if showing of errors is
86 * disabled and 'sendErrorReports' is set to 'never'
88 * @dataProvider providerForTestHandleError
90 public function testGetDispErrorsForDisplayFalse(
98 // TODO: Add other test cases for all combination of 'sendErrorReports'
99 $GLOBALS['cfg']['SendErrorReports'] = 'never';
101 $this->object->handleError($errno, $errstr, $errfile, $errline);
103 $output = $this->object->getDispErrors();
105 if ($output_hide === '') {
106 $this->assertEquals('', $output);
108 $this->assertNotEmpty($output_show);// Useless check
109 $this->assertStringContainsString($output_hide, $output);
114 * Test for getDispErrors when PHP errors are shown
116 * @param int $errno error number
117 * @param string $errstr error string
118 * @param string $errfile error file
119 * @param int $errline error line
120 * @param string $output_show expected output if showing of errors is
122 * @param string $output_hide expected output if showing of errors is
125 * @dataProvider providerForTestHandleError
127 public function testGetDispErrorsForDisplayTrue(
135 $this->object->handleError($errno, $errstr, $errfile, $errline);
137 $this->assertIsString($output_hide);// Useless check
138 $this->assertStringContainsString(
140 $this->object->getDispErrors()
145 * Test for checkSavedErrors
147 public function testCheckSavedErrors(): void
155 $this->assertArrayNotHasKey('errors', $_SESSION);
159 * Test for countErrors
163 public function testCountErrors(): void
165 $this->object->addError(
173 $this->object->countErrors()
178 * Test for sliceErrors
182 public function testSliceErrors(): void
184 $this->object->addError(
192 $this->object->countErrors()
196 $this->object->sliceErrors(1)
200 $this->object->countErrors()
204 $this->object->sliceErrors(0)
208 $this->object->countErrors()
213 * Test for countUserErrors
215 public function testCountUserErrors(): void
217 $this->object->addError(
225 $this->object->countUserErrors()
227 $this->object->addError(
235 $this->object->countUserErrors()
240 * Test for hasUserErrors
242 public function testHasUserErrors(): void
244 $this->assertFalse($this->object->hasUserErrors());
250 public function testHasErrors(): void
252 $this->assertFalse($this->object->hasErrors());
256 * Test for countDisplayErrors
258 public function testCountDisplayErrorsForDisplayTrue(): void
262 $this->object->countDisplayErrors()
267 * Test for countDisplayErrors
269 public function testCountDisplayErrorsForDisplayFalse(): void
273 $this->object->countDisplayErrors()
278 * Test for hasDisplayErrors
280 public function testHasDisplayErrors(): void
282 $this->assertFalse($this->object->hasDisplayErrors());