From c81b602657e52f4f9e25c3342bca4954fafc2037 Mon Sep 17 00:00:00 2001 From: Clemens Schwaighofer Date: Thu, 9 Oct 2025 15:05:00 +0900 Subject: [PATCH] phpunit: redirect error_log message to temp file so they are not printed to console This is for any logging part that logs to emergency where emergency logging is set to log to the error_log too --- .../Logging/CoreLibsLoggingErrorMessagesTest.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/4dev/tests/Logging/CoreLibsLoggingErrorMessagesTest.php b/4dev/tests/Logging/CoreLibsLoggingErrorMessagesTest.php index 5e9c3ac6..ba343533 100644 --- a/4dev/tests/Logging/CoreLibsLoggingErrorMessagesTest.php +++ b/4dev/tests/Logging/CoreLibsLoggingErrorMessagesTest.php @@ -105,11 +105,15 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase 'log_folder' => self::LOG_FOLDER, 'log_level' => Level::Error, ]); + $errorLogTmpfile = tmpfile(); + $errorLogLocationBackup = ini_set('error_log', stream_get_meta_data($errorLogTmpfile)['uri']); $em = new \CoreLibs\Logging\ErrorMessage($log); $em->setMessage( $level, $str ); + // for exceptions if log level is set to catch them + $error_log_content = stream_get_contents($errorLogTmpfile); $this->assertEquals( [ 'level' => $expected, @@ -377,6 +381,8 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase ?bool $log_warning, string $expected ): void { + $errorLogTmpfile = tmpfile(); + $errorLogLocationBackup = ini_set('error_log', stream_get_meta_data($errorLogTmpfile)['uri']); $log = new \CoreLibs\Logging\Logging([ 'log_file_id' => 'testErrorMessagesLogError', 'log_folder' => self::LOG_FOLDER, @@ -392,6 +398,9 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase log_error: $log_error, log_warning: $log_warning ); + ini_set('error_log', $errorLogLocationBackup); + // for exceptions if log level is set to catch them + $error_log_content = stream_get_contents($errorLogTmpfile); $file_content = ''; if (is_file($log->getLogFolder() . $log->getLogFile())) { $file_content = file_get_contents( @@ -447,6 +456,8 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase 'log_level' => Level::Debug, 'log_per_run' => true ]); + $errorLogTmpfile = tmpfile(); + $errorLogLocationBackup = ini_set('error_log', stream_get_meta_data($errorLogTmpfile)['uri']); $em = new \CoreLibs\Logging\ErrorMessage($log); $em->setErrorMsg( $id, @@ -456,6 +467,9 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase log_error: $log_error, log_warning: $log_warning ); + ini_set('error_log', $errorLogLocationBackup); + // for exceptions if log level is set to catch them + $error_log_content = stream_get_contents($errorLogTmpfile); $file_content = ''; if (is_file($log->getLogFolder() . $log->getLogFile())) { $file_content = file_get_contents(