[ErrorHandler] Apply php8 fixes from Debug component.
This commit is contained in:
parent
6d7c696742
commit
54f18698af
@ -91,9 +91,14 @@ class ErrorHandlerTest extends TestCase
|
||||
$this->fail('ErrorException expected');
|
||||
} catch (\ErrorException $exception) {
|
||||
// if an exception is thrown, the test passed
|
||||
$this->assertEquals(E_NOTICE, $exception->getSeverity());
|
||||
if (\PHP_VERSION_ID < 80000) {
|
||||
$this->assertEquals(E_NOTICE, $exception->getSeverity());
|
||||
$this->assertRegExp('/^Notice: Undefined variable: (foo|bar)/', $exception->getMessage());
|
||||
} else {
|
||||
$this->assertEquals(E_WARNING, $exception->getSeverity());
|
||||
$this->assertRegExp('/^Warning: Undefined variable \$(foo|bar)/', $exception->getMessage());
|
||||
}
|
||||
$this->assertEquals(__FILE__, $exception->getFile());
|
||||
$this->assertRegExp('/^Notice: Undefined variable: (foo|bar)/', $exception->getMessage());
|
||||
|
||||
$trace = $exception->getTrace();
|
||||
|
||||
@ -121,7 +126,7 @@ class ErrorHandlerTest extends TestCase
|
||||
public function testFailureCall()
|
||||
{
|
||||
$this->expectException(\ErrorException::class);
|
||||
$this->expectExceptionMessage('fopen(unknown.txt): failed to open stream: No such file or directory');
|
||||
$this->expectExceptionMessageMatches('/^fopen\(unknown\.txt\): [Ff]ailed to open stream: No such file or directory$/');
|
||||
|
||||
ErrorHandler::call('fopen', 'unknown.txt', 'r');
|
||||
}
|
||||
@ -149,9 +154,14 @@ class ErrorHandlerTest extends TestCase
|
||||
$this->fail('An \ErrorException should have been raised');
|
||||
} catch (\ErrorException $e) {
|
||||
$trace = $e->getTrace();
|
||||
$this->assertSame(E_NOTICE, $e->getSeverity());
|
||||
if (\PHP_VERSION_ID < 80000) {
|
||||
$this->assertEquals(E_NOTICE, $e->getSeverity());
|
||||
$this->assertSame('Undefined variable: foo', $e->getMessage());
|
||||
} else {
|
||||
$this->assertEquals(E_WARNING, $e->getSeverity());
|
||||
$this->assertSame('Undefined variable $foo', $e->getMessage());
|
||||
}
|
||||
$this->assertSame(__FILE__, $e->getFile());
|
||||
$this->assertSame('Undefined variable: foo', $e->getMessage());
|
||||
$this->assertSame(0, $e->getCode());
|
||||
$this->assertSame('Symfony\Component\ErrorHandler\{closure}', $trace[0]['function']);
|
||||
$this->assertSame(ErrorHandler::class, $trace[0]['class']);
|
||||
@ -288,11 +298,18 @@ class ErrorHandlerTest extends TestCase
|
||||
|
||||
$line = null;
|
||||
$logArgCheck = function ($level, $message, $context) use (&$line) {
|
||||
$this->assertEquals('Notice: Undefined variable: undefVar', $message);
|
||||
$this->assertArrayHasKey('exception', $context);
|
||||
$exception = $context['exception'];
|
||||
|
||||
if (\PHP_VERSION_ID < 80000) {
|
||||
$this->assertEquals('Notice: Undefined variable: undefVar', $message);
|
||||
$this->assertSame(E_NOTICE, $exception->getSeverity());
|
||||
} else {
|
||||
$this->assertEquals('Warning: Undefined variable $undefVar', $message);
|
||||
$this->assertSame(E_WARNING, $exception->getSeverity());
|
||||
}
|
||||
|
||||
$this->assertInstanceOf(SilencedErrorContext::class, $exception);
|
||||
$this->assertSame(E_NOTICE, $exception->getSeverity());
|
||||
$this->assertSame(__FILE__, $exception->getFile());
|
||||
$this->assertSame($line, $exception->getLine());
|
||||
$this->assertNotEmpty($exception->getTrace());
|
||||
@ -306,8 +323,13 @@ class ErrorHandlerTest extends TestCase
|
||||
;
|
||||
|
||||
$handler = ErrorHandler::register();
|
||||
$handler->setDefaultLogger($logger, E_NOTICE);
|
||||
$handler->screamAt(E_NOTICE);
|
||||
if (\PHP_VERSION_ID < 80000) {
|
||||
$handler->setDefaultLogger($logger, E_NOTICE);
|
||||
$handler->screamAt(E_NOTICE);
|
||||
} else {
|
||||
$handler->setDefaultLogger($logger, E_WARNING);
|
||||
$handler->screamAt(E_WARNING);
|
||||
}
|
||||
unset($undefVar);
|
||||
$line = __LINE__ + 1;
|
||||
@$undefVar++;
|
||||
|
@ -15,8 +15,8 @@ class ErrorHandlerThatUsesThePreviousOne
|
||||
return $handler;
|
||||
}
|
||||
|
||||
public function handleError($type, $message, $file, $line, $context)
|
||||
public function handleError()
|
||||
{
|
||||
return \call_user_func(self::$previous, $type, $message, $file, $line, $context);
|
||||
return \call_user_func_array(self::$previous, \func_get_args());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user