8000 minor #36897 [Debug] Undefined variables raise a warning in php 8 (de… · symfony/symfony@b202696 · GitHub
[go: up one dir, main page]

Skip to content

Commit b202696

Browse files
committed
minor #36897 [Debug] Undefined variables raise a warning in php 8 (derrabus)
This PR was merged into the 3.4 branch. Discussion ---------- [Debug] Undefined variables raise a warning in php 8 | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | #36872 | License | MIT | Doc PR | N/A `ErrorHandlerTest` executes code with undefined variables to test how the error handler handles the triggered errors. In php 8.0, the severity and error message for this class of errors has been changed. I've adjusted the test accordingly. Commits ------- 1d20b51 [Debug] Undefined variables raise a warning in php 8.
2 parents 4a0d5f1 + 1d20b51 commit b202696

File tree

1 file changed

+22
-6
lines changed

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