2 declare(strict_types = 1);
18 use PHPUnit\Framework\MockObject\MockObject;
23 use TYPO3\TestingFramework\Core\AccessibleObjectInterface;
24 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
38 'initCommands' =>
'SET NAMES \'UTF8\';',
55 'The first error triggers database connection to be initialized and should be caught.',
59 'The second error should be caught by ErrorHandler as well.',
62 $this->assertTrue(
true);
85 static::assertNotSame(0, error_reporting());
88 $logManagerMock = $this->createMock(LogManager::class);
89 $logManagerMock->expects($this->never())->method(
'getLogger')->with(
'TYPO3.CMS.deprecations');
90 GeneralUtility::setSingletonInstance(LogManager::class, $logManagerMock);
93 $logger = $this->getMockBuilder(Logger::class)
94 ->disableOriginalConstructor()
99 $logger->expects($this->never())->method(
'log');
103 E_ALL & ~(E_STRICT | E_NOTICE | E_COMPILE_WARNING | E_COMPILE_ERROR | E_CORE_WARNING | E_CORE_ERROR | E_PARSE | E_ERROR)
105 $coreErrorHandler->setLogger($logger);
107 $customErrorHandler =
new class {
108 protected $existingHandler;
110 public function setExistingHandler($existingHandler)
112 $this->existingHandler = $existingHandler;
123 public function handleError($code, $message, $file =
'', $line = 0, $context = [])
126 if ($this->existingHandler !==
null) {
127 return call_user_func($this->existingHandler, $code, $message, $file, $line, $context);
134 $existingHandler = set_error_handler([$customErrorHandler,
'handleError'], E_ALL);
135 $customErrorHandler->setExistingHandler($existingHandler);
137 static::assertTrue($customErrorHandler->handleError(E_NOTICE,
'Notice error message', __FILE__, __LINE__));