10000 Merge branch '5.1' · symfony/error-handler@8419104 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8419104

Browse files
Merge branch '5.1'
* 5.1: (33 commits) [Cache] $lifetime cannot be null [Serializer] minor cleanup fix merge Run PHP 8 as 7.4.99 Remove calls to deprecated ReflectionParameter::getClass(). [VarDumper] fix PHP 8 support Removed "services" prototype node from "custom_authenticator" Add php 8 to travis. [Cache] Accessing undefined constants raises an Error in php8 [Cache] allow DBAL v3 Skip Doctrine DBAL on php 8 until we have a compatible version. [DomCrawler] Catch expected ValueError. Made method signatures compatible with their corresponding traits. [ErrorHandler] Apply php8 fixes from Debug component. [DomCrawler] Catch expected ValueError. [Validator] Catch expected ValueError. [VarDumper] ReflectionFunction::isDisabled() is deprecated. [BrowserKit] Raw body with custom Content-Type header Revert symfony/symfony#34986 Make ExpressionLanguageSyntax validator usable with annotation ...
2 parents 7bdb671 + 6c1ee65 commit 8419104

File tree

2 files changed

+33
-11
lines changed

2 files changed

+33
-11
lines changed

Tests/ErrorHandlerTest.php

Lines changed: 31 additions & 9 deletions
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-
$this->assertRegExp('/^Notice: Undefined variable: (foo|bar)/', $exception->getMessage());
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++;

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