12
12
13
13
final class ErrorHandlerTest extends TestCase
14
14
{
15
- private string $ backupErrorLog ;
16
- private string $ errorLog ;
17
15
private ErrorException $ exception ;
18
16
19
17
/** @var list<array{subject: string, body: string}> */
@@ -23,11 +21,6 @@ final class ErrorHandlerTest extends TestCase
23
21
24
22
protected function setUp (): void
25
23
{
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
-
31
24
$ this ->exception = new ErrorException (\uniqid ('normal_ ' ), \E_USER_NOTICE );
32
25
$ this ->errorHandler = new ErrorHandler (function (string $ subject , string $ body ): void {
33
26
$ this ->emailsSent [] = [
@@ -43,8 +36,6 @@ protected function setUp(): void
43
36
protected function tearDown (): void
44
37
{
45
38
\putenv ('COLUMNS ' );
46
- \ini_set ('error_log ' , $ this ->backupErrorLog );
47
- @\unlink ($ this ->errorLog );
48
39
if ($ this ->unregister ) {
49
40
\restore_exception_handler ();
50
41
\restore_error_handler ();
@@ -138,7 +129,8 @@ public function testHandleWebExceptionWithDisplay(): void
138
129
139
130
self ::assertStringContainsString ($ this ->exception ->getMessage (), $ output );
140
131
141
- $ errorLogContent = (string ) \file_get_contents ($ this ->errorLog );
132
+ self ::expectErrorLog ();
133
+ $ errorLogContent = (string ) \file_get_contents (\ini_get ('error_log ' ));
142
134
self ::assertStringContainsString ($ this ->exception ->getMessage (), $ errorLogContent );
143
135
}
144
136
@@ -154,7 +146,8 @@ public function testHandleWebExceptionWithoutDisplay(): void
154
146
155
147
self ::assertStringNotContainsString ($ this ->exception ->getMessage (), $ output );
156
148
157
- $ errorLogContent = (string ) \file_get_contents ($ this ->errorLog );
149
+ self ::expectErrorLog ();
150
+ $ errorLogContent = (string ) \file_get_contents (\ini_get ('error_log ' ));
158
151
self ::assertStringContainsString ($ this ->exception ->getMessage (), $ errorLogContent );
159
152
}
160
153
@@ -164,15 +157,16 @@ public function testLogErrorAndException(): void
164
157
165
158
$ this ->errorHandler ->logException ($ this ->exception );
166
159
167
- self ::assertSame (0 , \filesize ($ this -> errorLog ));
160
+ self ::assertSame (0 , \filesize (\ini_get ( ' error_log ' ) ));
168
161
169
162
$ this ->errorHandler ->setLogErrors (true );
170
163
171
164
$ exception = new ErrorException (\uniqid (), \E_USER_ERROR , \E_ERROR , __FILE__ , 1 , $ this ->exception );
172
165
173
166
$ this ->errorHandler ->logException ($ exception );
174
167
175
- $ errorLogContent = (string ) \file_get_contents ($ this ->errorLog );
168
+ self ::expectErrorLog ();
169
+ $ errorLogContent = (string ) \file_get_contents (\ini_get ('error_log ' ));
176
170
177
171
self ::assertStringContainsString ($ exception ->getMessage (), $ errorLogContent );
178
172
self ::assertStringContainsString ($ this ->exception ->getMessage (), $ errorLogContent );
@@ -236,7 +230,8 @@ public function testErroriNellInvioDellaMailVengonoComunqueLoggati(): void
236
230
237
231
$ errorHandler ->emailException ($ this ->exception );
238
232
239
- $ errorLogContent = (string ) \file_get_contents ($ this ->errorLog );
233
+ self ::expectErrorLog ();
234
+ $ errorLogContent = (string ) \file_get_contents (\ini_get ('error_log ' ));
240
235
self ::assertStringNotContainsString ($ this ->exception ->getMessage (), $ errorLogContent );
241
236
self ::assertStringContainsString ($ mailError , $ errorLogContent );
242
237
}
@@ -323,7 +318,7 @@ public function testCanSetCustomErrorLogCallback(): void
323
318
324
319
$ this ->errorHandler ->logException ($ this ->exception );
325
320
326
- self ::assertSame (0 , \filesize ($ this -> errorLog ));
321
+ self ::assertSame (0 , \filesize (\ini_get ( ' error_log ' ) ));
327
322
self ::assertStringContainsString ($ this ->exception ->getMessage (), \var_export ($ data , true ));
328
323
}
329
324
}
0 commit comments