Explorar el Código

Avoid writing to log files during unit tests (#9373)

* Avoid writing to log files during unit tests

* Translate PHPDoc of `record()`

* Move environment variable into `phpunit.xml` and use tabs for indents
Inverle hace 20 horas
padre
commit
1f055da218
Se han modificado 3 ficheros con 19 adiciones y 16 borrados
  1. 7 7
      lib/Minz/Log.php
  2. 11 8
      phpunit.xml
  3. 1 1
      tests/lib/Minz/LogTest.php

+ 7 - 7
lib/Minz/Log.php

@@ -24,14 +24,14 @@ class Minz_Log {
 	];
 
 	/**
-	 * Enregistre un message dans un fichier de log spécifique
-	 * Message non loggué si
+	 * Records a message in a specific log file
+	 * The message is not logged if
 	 * 	- environment = SILENT
-	 * 	- level est moins sévère que le seuil déterminé par `log_level`,
-	 * 	  ou par défaut par `environment` (PRODUCTION ne garde que warning et error)
-	 * @param string $information message d'erreur / information à enregistrer
-	 * @param int $level niveau d'erreur https://www.php.net/function.syslog
-	 * @param string $file_name fichier de log
+	 * 	- level is less severe than the threshold determined by `log_level`,
+	 * 	  or, by default, by `environment` (PRODUCTION keeps only warnings and errors)
+	 * @param string $information error message / information to record
+	 * @param int $level error level https://www.php.net/function.syslog
+	 * @param string $file_name log file
 	 * @throws Minz_PermissionDeniedException
 	 */
 	public static function record(string $information, int $level, ?string $file_name = null): void {

+ 11 - 8
phpunit.xml

@@ -1,12 +1,15 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <phpunit
-    bootstrap="./tests/bootstrap.php"
-    displayDetailsOnAllIssues="true"
-    failOnAllIssues="true"
+	bootstrap="./tests/bootstrap.php"
+	displayDetailsOnAllIssues="true"
+	failOnAllIssues="true"
 >
-    <testsuites>
-        <testsuite name="default">
-            <directory>./tests</directory>
-        </testsuite>
-    </testsuites>
+	<php>
+		<env name="FRESHRSS_ENV" value="silent" force="true"/> <!-- To avoid writing into log files -->
+	</php>
+	<testsuites>
+		<testsuite name="default">
+			<directory>./tests</directory>
+		</testsuite>
+	</testsuites>
 </phpunit>

+ 1 - 1
tests/lib/Minz/LogTest.php

@@ -13,7 +13,7 @@ class LogTest extends TestCase {
 
 	#[\Override]
 	protected function tearDown(): void {
-		putenv('FRESHRSS_ENV');
+		putenv('FRESHRSS_ENV=silent');
 		@unlink($this->logFile);
 	}