8000 minor #36909 [ErrorHandler] Apply php8 fixes from Debug component (de… · symfony/symfony@f32c2c1 · GitHub
[go: up one dir, main page]

Skip to content

Commit f32c2c1

Browse files
minor #36909 [ErrorHandler] Apply php8 fixes from Debug component (derrabus)
This PR was merged into the 4.4 branch. Discussion ---------- [ErrorHandler] Apply php8 fixes from Debug component | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | #36872 | License | MIT | Doc PR | N/A The changes of #36898 and #36897 ported to the ErrorHandler component. Commits ------- 54f1869 [ErrorHandler] Apply php8 fixes from Debug component.
2 parents 5d7b7e9 + 54f1869 commit f32c2c1

File tree

2 files changed

+33
-11
lines changed

2 files changed

+33
-11
lines changed

src/Symfony/Component/ErrorHandler/Tests/ErrorHandlerTest.php

Lines changed: 31 additions & 9 deletions
< 10000 td data-grid-cell-id="diff-258da769eed42a2dbcac11c190514216c438fd9f108c9472f0b7be884cd4936c-96-101-2" data-line-anchor="diff-258da769eed42a2dbcac11c190514216c438fd9f108c9472f0b7be884cd4936cL96" data-selected="false" role="gridcell" style="background-color:var(--diffBlob-deletionLine-bgColor, var(--diffBlob-deletion-bgColor-line));padding-right:24px" tabindex="-1" valign="top" class="focusable-grid-cell diff-text-cell left-side-diff-cell border-right left-side">-
$this->assertRegExp('/^Notice: Undefined variable: (foo|bar)/', $exception->getMessage());
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,14 @@ public function testNotice()
9191
$this->fail('ErrorException expected');
9292
} catch (\ErrorException $exception) {
9393
// if an exception is thrown, the test passed
94-
$this->assertEquals(E_NOTICE, $exception->getSeverity());
94+
if (\PHP_VERSION_ID < 80000) {
95+
$this->assertEquals(E_NOTICE, $exception->getSeverity());
96+
$this->assertRegExp('/^Notice: Undefined variable: (foo|bar)/', $exception->getMessage());
97+
} else {
98+
$this->assertEquals(E_WARNING, $exception->getSeverity());
99+
$this->assertRegExp('/^Warning: Undefined variable \$(foo|bar)/', $exception->getMessage());
100+
}
95101
$this->assertEquals(__FILE__, $exception->getFile());
96
97102

98103
$trace = $exception->getTrace();
99104

@@ -121,7 +126,7 @@ public static function triggerNotice($that)
121126
public function testFailureCall()
122127
{
123128
$this->expectException(\ErrorException::class);
124-
$this->expectExceptionMessage('fopen(unknown.txt): failed to open stream: No such file or directory');
129+
$this->expectExceptionMessageMatches('/^fopen\(unknown\.txt\): [Ff]ailed to open stream: No such file or directory$/');
125130

126131
ErrorHandler::call('fopen', 'unknown.txt', 'r');
127132
}
@@ -149,9 +154,14 @@ public function testCallErrorExceptionInfo()
149154
$this->fail('An \ErrorException should have been raised');
150155
} catch (\ErrorException $e) {
151156
$trace = $e->getTrace();
152-
$this->assertSame(E_NOTICE, $e->getSeverity());
157+
if (\PHP_VERSION_ID < 80000) {
158+
$this->assertEquals(E_NOTICE, $e->getSeverity());
159+
$this->assertSame('Undefined variable: foo', $e->getMessage());
160+
} else {
161+
$this->assertEquals(E_WARNING, $e->getSeverity());
162+
$this->assertSame('Undefined variable $foo', $e->getMessage());
163+
}
153164
$this->assertSame(__FILE__, $e->getFile());
154-
$this->assertSame('Undefined variable: foo', $e->getMessage());
155165
$this->assertSame(0, $e->getCode());
156166
$this->assertSame('Symfony\Component\ErrorHandler\{closure}', $trace[0]['function']);
157167
$this->assertSame(ErrorHandler::class, $trace[0]['class']);
@@ -288,11 +298,18 @@ public function testHandleError()
288298

289299
$line = null;
290300
$logArgCheck = function ($level, $message, $context) use (&$line) {
291-
$this->assertEquals('Notice: Undefined variable: undefVar', $message);
292301
$this->assertArrayHasKey('exception', $context);
293302
$exception = $context['exception'];
303+
304+
if (\PHP_VERSION_ID < 80000) {
305+
$this->assertEquals('Notice: Undefined variable: undefVar', $message);
306+
$this->assertSame(E_NOTICE, $exception->getSeverity());
307+
} else {
308+
$this->assertEquals('Warning: Undefined variable $undefVar', $message);
309+
$this->assertSame(E_WARNING, $exception->getSeverity());
310+
}
311+
294312
$this->assertInstanceOf(SilencedErrorContext::class, $exception);
295-
$this->assertSame(E_NOTICE, $exception->getSeverity());
296313
$this->assertSame(__FILE__, $exception->getFile());
297314
$this->assertSame($line, $exception->getLine());
298315
$this->assertNotEmpty($exception->getTrace());
@@ -306,8 +323,13 @@ public function testHandleError()
306323
;
307324

308325
$handler = ErrorHandler::register();
309-
$handler->setDefaultLogger($logger, E_NOTICE);
310-
$handler->screamAt(E_NOTICE);
326+
if (\PHP_VERSION_ID < 80000) {
327+
$handler->setDefaultLogger($logger, E_NOTICE);
328+
$handler->screamAt(E_NOTICE);
329+
} else {
330+
$handler->setDefaultLogger($logger, E_WARNING);
331+
$handler->screamAt(E_WARNING);
332+
}
311333
unset($undefVar);
312334
$line = __LINE__ + 1;
313335
@$undefVar++;

src/Symfony/Component/ErrorHandler/Tests/Fixtures/ErrorHandlerThatUsesThePreviousOne.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ public static function register()
1515
return $handler;
1616
}
1717

18-
public function handleError($type, $message, $file, $line, $context)
18+
public function handleError()
1919
{
20-
return \call_user_func(self::$previous, $type, $message, $file, $line, $context);
20+
return \call_user_func_array(self::$previous, \func_get_args());
2121
}
2222
}

0 commit comments

Comments
 (0)
0