8000 [Debug] Undefined variables raise a warning in php 8. · symfony/symfony@1d20b51 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1d20b51

Browse files
committed
[Debug] Undefined variables raise a warning in php 8.
1 parent 52abcbe commit 1d20b51

File tree

1 file changed

+22
-6
lines changed
  • src/Symfony/Component/Debug/Tests
    • < 8000 div class="PRIVATE_TreeView-item-level-line prc-TreeView-TreeViewItemLevelLine-KPSSL">

1 file changed

+22
-6
lines changed

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

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,14 @@ public function testNotice()
101101
$this->fail('ErrorException expected');
102102
} catch (\ErrorException $exception) {
103103
// if an exception is thrown, the test passed
104-
$this->assertEquals(E_NOTICE, $exception->getSeverity());
104+
if (\PHP_VERSION_ID < 80000) {
105+
$this->assertEquals(E_NOTICE, $exception->getSeverity());
106+
$this->assertRegExp('/^Notice: Undefined variable: (foo|bar)/', $exception->getMessage());
107+
} else {
108+
$this->assertEquals(E_WARNING, $exception->getSeverity());
109+
$this->assertRegExp('/^Warning: Undefined variable \$(foo|bar)/', $exception->getMessage());
110+
}
105111
$this->assertEquals(__FILE__, $exception->getFile());
106-
$this->assertRegExp('/^Notice: Undefined variable: (foo|bar)/', $exception->getMessage());
107112

108113
$trace = $exception->getTrace();
109114

@@ -247,11 +252,17 @@ public function testHandleError()
247252

248253
$line = null;
249254
$logArgCheck = function ($level, $message, $context) use (&$line) {
250-
$this->assertEquals('Notice: Undefined variable: undefVar', $message);
251255
$this->assertArrayHasKey('exception', $context);
252256
$exception = $context['exception'];
257+
258+
if (\PHP_VERSION_ID < 80000) {
259+
$this->assertEquals('Notice: Undefined variable: undefVar', $message);
260+
$this->assertSame(E_NOTICE, $exception->getSeverity());
261+
} else {
262+
$this->assertEquals('Warning: Undefined variable $undefVar', $message);
263+
$this->assertSame(E_WARNING, $exception->getSeverity());
264+
}
253265
$this->assertInstanceOf(SilencedErrorContext::class, $exception);
254-
$this->assertSame(E_NOTICE, $exception->getSeverity());
255266
$this->assertSame(__FILE__, $exception->getFile());
256267
$this->assertSame($line, $exception->getLine());
257268
$this->assertNotEmpty($exception->getTrace());
@@ -265,8 +276,13 @@ public function testHandleError()
265276
;
266277

267278
$handler = ErrorHandler::register();
268-
$handler->setDefaultLogger($logger, E_NOTICE);
269-
$handler->screamAt(E_NOTICE);
279+
if (\PHP_VERSION_ID < 80000) {
280+
$handler->setDefaultLogger($logger, E_NOTICE);
281+
$handler->screamAt(E_NOTICE);
282+
} else {
283+
$handler->setDefaultLogger($logger, E_WARNING);
284+
$handler->screamAt(E_WARNING);
285+
}
270286
unset($undefVar);
271287
$line = __LINE__ + 1;
272288
@$undefVar++;

0 commit comments

Comments
 (0)
0