Translated using Weblate (Slovenian)
[phpmyadmin.git] / test / classes / ErrorHandlerTest.php
blob6ccef68668e0872ac41eb840bfb087a13683e26b
1 <?php
2 /**
3 * Tests for ErrorHandler
4 */
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;
14 use const E_WARNING;
16 class ErrorHandlerTest extends AbstractTestCase
18 /** @var ErrorHandler */
19 protected $object;
21 /**
22 * Sets up the fixture, for example, opens a network connection.
23 * This method is called before a test is executed.
25 * @access protected
27 protected function setUp(): void
29 parent::setUp();
30 parent::loadDefaultConfig();
31 $this->object = new ErrorHandler();
32 $_SESSION['errors'] = [];
33 $GLOBALS['server'] = 0;
34 $GLOBALS['cfg']['SendErrorReports'] = 'always';
37 /**
38 * Tears down the fixture, for example, closes a network connection.
39 * This method is called after a test is executed.
41 * @access protected
43 protected function tearDown(): void
45 parent::tearDown();
46 unset($this->object);
49 /**
50 * Data provider for testHandleError
52 * @return array data for testHandleError
54 public function providerForTestHandleError(): array
56 return [
58 E_RECOVERABLE_ERROR,
59 'Compile Error',
60 'error.txt',
61 12,
62 'Compile Error',
63 '',
66 E_USER_NOTICE,
67 'User notice',
68 'error.txt',
69 12,
70 'User notice',
71 'User notice',
76 /**
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
84 * enabled
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(
91 int $errno,
92 string $errstr,
93 string $errfile,
94 int $errline,
95 string $output_show,
96 string $output_hide
97 ): void {
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);
107 } else {
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
121 * enabled
122 * @param string $output_hide expected output if showing of errors is
123 * disabled
125 * @dataProvider providerForTestHandleError
127 public function testGetDispErrorsForDisplayTrue(
128 int $errno,
129 string $errstr,
130 string $errfile,
131 int $errline,
132 string $output_show,
133 string $output_hide
134 ): void {
135 $this->object->handleError($errno, $errstr, $errfile, $errline);
137 $this->assertIsString($output_hide);// Useless check
138 $this->assertStringContainsString(
139 $output_show,
140 $this->object->getDispErrors()
145 * Test for checkSavedErrors
147 public function testCheckSavedErrors(): void
149 $this->callFunction(
150 $this->object,
151 ErrorHandler::class,
152 'checkSavedErrors',
155 $this->assertArrayNotHasKey('errors', $_SESSION);
159 * Test for countErrors
161 * @group medium
163 public function testCountErrors(): void
165 $this->object->addError(
166 'Compile Error',
167 E_WARNING,
168 'error.txt',
171 $this->assertEquals(
173 $this->object->countErrors()
178 * Test for sliceErrors
180 * @group medium
182 public function testSliceErrors(): void
184 $this->object->addError(
185 'Compile Error',
186 E_WARNING,
187 'error.txt',
190 $this->assertEquals(
192 $this->object->countErrors()
194 $this->assertEquals(
196 $this->object->sliceErrors(1)
198 $this->assertEquals(
200 $this->object->countErrors()
202 $this->assertCount(
204 $this->object->sliceErrors(0)
206 $this->assertEquals(
208 $this->object->countErrors()
213 * Test for countUserErrors
215 public function testCountUserErrors(): void
217 $this->object->addError(
218 'Compile Error',
219 E_WARNING,
220 'error.txt',
223 $this->assertEquals(
225 $this->object->countUserErrors()
227 $this->object->addError(
228 'Compile Error',
229 E_USER_WARNING,
230 'error.txt',
233 $this->assertEquals(
235 $this->object->countUserErrors()
240 * Test for hasUserErrors
242 public function testHasUserErrors(): void
244 $this->assertFalse($this->object->hasUserErrors());
248 * Test for hasErrors
250 public function testHasErrors(): void
252 $this->assertFalse($this->object->hasErrors());
256 * Test for countDisplayErrors
258 public function testCountDisplayErrorsForDisplayTrue(): void
260 $this->assertEquals(
262 $this->object->countDisplayErrors()
267 * Test for countDisplayErrors
269 public function testCountDisplayErrorsForDisplayFalse(): void
271 $this->assertEquals(
273 $this->object->countDisplayErrors()
278 * Test for hasDisplayErrors
280 public function testHasDisplayErrors(): void
282 $this->assertFalse($this->object->hasDisplayErrors());