1212
1313final class ErrorHandlerTest extends TestCase
1414{
15- private string $ backupErrorLog ;
16- private string $ errorLog ;
1715 private ErrorException $ exception ;
1816
1917 /** @var list<array{subject: string, body: string}> */
@@ -23,11 +21,6 @@ final class ErrorHandlerTest extends TestCase
2321
2422 protected function setUp (): void
2523 {
26- $ this ->backupErrorLog = (string ) \ini_get ('error_log ' );
27- $ this ->errorLog = __DIR__ . \DIRECTORY_SEPARATOR . 'error_log_test ' ;
28- \touch ($ this ->errorLog );
29- \ini_set ('error_log ' , $ this ->errorLog );
30-
3124 $ this ->exception = new ErrorException (\uniqid ('normal_ ' ), \E_USER_NOTICE );
3225 $ this ->errorHandler = new ErrorHandler (function (string $ subject , string $ body ): void {
3326 $ this ->emailsSent [] = [
@@ -43,8 +36,6 @@ protected function setUp(): void
4336 protected function tearDown (): void
4437 {
4538 \putenv ('COLUMNS ' );
46- \ini_set ('error_log ' , $ this ->backupErrorLog );
47- @\unlink ($ this ->errorLog );
4839 if ($ this ->unregister ) {
4940 \restore_exception_handler ();
5041 \restore_error_handler ();
@@ -138,7 +129,8 @@ public function testHandleWebExceptionWithDisplay(): void
138129
139130 self ::assertStringContainsString ($ this ->exception ->getMessage (), $ output );
140131
141- $ errorLogContent = (string ) \file_get_contents ($ this ->errorLog );
132+ self ::expectErrorLog ();
133+ $ errorLogContent = (string ) \file_get_contents (\ini_get ('error_log ' ));
142134 self ::assertStringContainsString ($ this ->exception ->getMessage (), $ errorLogContent );
143135 }
144136
@@ -154,7 +146,8 @@ public function testHandleWebExceptionWithoutDisplay(): void
154146
155147 self ::assertStringNotContainsString ($ this ->exception ->getMessage (), $ output );
156148
157- $ errorLogContent = (string ) \file_get_contents ($ this ->errorLog );
149+ self ::expectErrorLog ();
150+ $ errorLogContent = (string ) \file_get_contents (\ini_get ('error_log ' ));
158151 self ::assertStringContainsString ($ this ->exception ->getMessage (), $ errorLogContent );
159152 }
160153
@@ -164,15 +157,16 @@ public function testLogErrorAndException(): void
164157
165158 $ this ->errorHandler ->logException ($ this ->exception );
166159
167- self ::assertSame (0 , \filesize ($ this -> errorLog ));
160+ self ::assertSame (0 , \filesize (\ini_get ( ' error_log ' ) ));
168161
169162 $ this ->errorHandler ->setLogErrors (true );
170163
171164 $ exception = new ErrorException (\uniqid (), \E_USER_ERROR , \E_ERROR , __FILE__ , 1 , $ this ->exception );
172165
173166 $ this ->errorHandler ->logException ($ exception );
174167
175- $ errorLogContent = (string ) \file_get_contents ($ this ->errorLog );
168+ self ::expectErrorLog ();
169+ $ errorLogContent = (string ) \file_get_contents (\ini_get ('error_log ' ));
176170
177171 self ::assertStringContainsString ($ exception ->getMessage (), $ errorLogContent );
178172 self ::assertStringContainsString ($ this ->exception ->getMessage (), $ errorLogContent );
@@ -236,7 +230,8 @@ public function testErroriNellInvioDellaMailVengonoComunqueLoggati(): void
236230
237231 $ errorHandler ->emailException ($ this ->exception );
238232
239- $ errorLogContent = (string ) \file_get_contents ($ this ->errorLog );
233+ self ::expectErrorLog ();
234+ $ errorLogContent = (string ) \file_get_contents (\ini_get ('error_log ' ));
240235 self ::assertStringNotContainsString ($ this ->exception ->getMessage (), $ errorLogContent );
241236 self ::assertStringContainsString ($ mailError , $ errorLogContent );
242237 }
@@ -323,7 +318,7 @@ public function testCanSetCustomErrorLogCallback(): void
323318
324319 $ this ->errorHandler ->logException ($ this ->exception );
325320
326- self ::assertSame (0 , \filesize ($ this -> errorLog ));
321+ self ::assertSame (0 , \filesize (\ini_get ( ' error_log ' ) ));
327322 self ::assertStringContainsString ($ this ->exception ->getMessage (), \var_export ($ data , true ));
328323 }
329324}
0 commit comments