@@ -219,6 +219,7 @@ abstract class TestCase extends Assert implements Reorderable, SelfDescribing, T
219
219
* @var list<non-empty-string>
220
220
*/
221
221
private array $ expectedUserDeprecationMessageRegularExpression = [];
222
+ private false |string $ previousErrorLogTarget = false ;
222
223
223
224
/**
224
225
* @param non-empty-string $name
@@ -1298,21 +1299,7 @@ private function runTest(): mixed
1298
1299
{
1299
1300
$ testArguments = array_merge ($ this ->data , array_values ($ this ->dependencyInput ));
1300
1301
1301
- $ capture = tmpfile ();
1302
-
1303
- if (ini_get ('display_errors ' ) === '0 ' ) {
1304
- ShutdownHandler::setMessage ('Fatal error: Premature end of PHP process. Use display_errors=On to see the error message. ' );
1305
- }
1306
-
1307
- if ($ capture !== false ) {
1308
- $ capturePath = stream_get_meta_data ($ capture )['uri ' ];
1309
-
1310
- if (@is_writable ($ capturePath )) {
1311
- $ errorLogPrevious = ini_set ('error_log ' , $ capturePath );
1312
- } else {
1313
- $ capture = false ;
1314
- }
1315
- }
1302
+ $ capture = $ this ->startErrorLogCapture ();
1316
1303
1317
1304
try {
1318
1305
/** @phpstan-ignore method.dynamicName */
@@ -1352,10 +1339,12 @@ private function runTest(): mixed
1352
1339
} finally {
1353
1340
if ($ capture !== false ) {
1354
1341
ShutdownHandler::resetMessage ();
1342
+
1355
1343
fclose ($ capture );
1356
1344
1357
- /** @phpstan-ignore variable.undefined (https://github.com/phpstan/phpstan/issues/12992) */
1358
- ini_set ('error_log ' , $ errorLogPrevious );
1345
+ if ($ this ->previousErrorLogTarget !== false ) {
1346
+ ini_set ('error_log ' , $ this ->previousErrorLogTarget );
1347
+ }
1359
1348
}
1360
1349
}
1361
1350
@@ -2347,6 +2336,30 @@ private function handleExceptionFromInvokedCountMockObjectRule(Throwable $t): vo
2347
2336
}
2348
2337
}
2349
2338
2339
+ /**
2340
+ * @return false|resource
2341
+ */
2342
+ private function startErrorLogCapture (): mixed
2343
+ {
2344
+ if (ini_get ('display_errors ' ) === '0 ' ) {
2345
+ ShutdownHandler::setMessage ('Fatal error: Premature end of PHP process. Use display_errors=On to see the error message. ' );
2346
+ }
2347
+
2348
+ $ capture = tmpfile ();
2349
+
2350
+ if ($ capture !== false ) {
2351
+ $ capturePath = stream_get_meta_data ($ capture )['uri ' ];
2352
+
2353
+ if (@is_writable ($ capturePath )) {
2354
+ $ this ->previousErrorLogTarget = ini_set ('error_log ' , $ capturePath );
2355
+ } else {
2356
+ $ capture = false ;
2357
+ }
2358
+ }
2359
+
2360
+ return $ capture ;
2361
+ }
2362
+
2350
2363
/**
2351
2364
* Creates a test stub for the specified interface or class.
2352
2365
*
0 commit comments