@@ -219,7 +219,12 @@ 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
+ /**
224
+ * @var false|resource
225
+ */
226
+ private mixed $ errorLogCapture = false ;
227
+ private false |string $ previousErrorLogTarget = false ;
223
228
224
229
/**
225
230
* @param non-empty-string $name
@@ -1299,35 +1304,15 @@ private function runTest(): mixed
1299
1304
{
1300
1305
$ testArguments = array_merge ($ this ->data , array_values ($ this ->dependencyInput ));
1301
1306
1302
- $ capture = $ this ->startErrorLogCapture ();
1307
+ $ this ->startErrorLogCapture ();
1303
1308
1304
1309
try {
1305
1310
/** @phpstan-ignore method.dynamicName */
1306
1311
$ testResult = $ this ->{$ this ->methodName }(...$ testArguments );
1307
1312
1308
- if ($ capture !== false ) {
1309
- $ errorLogOutput = stream_get_contents ($ capture );
1310
-
1311
- if ($ this ->expectErrorLog ) {
1312
- $ this ->assertNotEmpty ($ errorLogOutput , 'Test did not call error_log(). ' );
1313
- } else {
1314
- if ($ errorLogOutput !== false ) {
1315
- print $ this ->stripDateFromErrorLog ($ errorLogOutput );
1316
- }
1317
- }
1318
- } elseif ($ this ->expectErrorLog ) {
1319
- $ this ->markTestIncomplete ('Could not create writable error_log file. ' );
1320
- }
1313
+ $ this ->verifyErrorLogExpectation ();
1321
1314
} catch (Throwable $ exception ) {
1322
- if ($ capture !== false ) {
1323
- if (!$ this ->expectErrorLog ) {
1324
- $ errorLogOutput = stream_get_contents ($ capture );
1325
-
1326
- if ($ errorLogOutput !== false ) {
1327
- print $ this ->stripDateFromErrorLog ($ errorLogOutput );
1328
- }
1329
- }
1330
- }
1315
+ $ this ->handleErrorLogError ();
1331
1316
1332
1317
if (!$ this ->shouldExceptionExpectationsBeVerified ($ exception )) {
1333
1318
throw $ exception ;
@@ -1337,15 +1322,7 @@ private function runTest(): mixed
1337
1322
1338
1323
return null ;
1339
1324
} finally {
1340
- if ($ capture !== false ) {
1341
- ShutdownHandler::resetMessage ();
1342
-
1343
- fclose ($ capture );
1344
-
1345
- if ($ this ->previousErrorLogTarget !== false ) {
1346
- ini_set ('error_log ' , $ this ->previousErrorLogTarget );
1347
- }
1348
- }
1325
+ $ this ->stopErrorLogCapture ();
1349
1326
}
1350
1327
1351
1328
$ this ->expectedExceptionWasNotRaised ();
@@ -2336,28 +2313,72 @@ private function handleExceptionFromInvokedCountMockObjectRule(Throwable $t): vo
2336
2313
}
2337
2314
}
2338
2315
2339
- /**
2340
- * @return false|resource
2341
- */
2342
- private function startErrorLogCapture (): mixed
2316
+ private function startErrorLogCapture (): void
2343
2317
{
2344
2318
if (ini_get ('display_errors ' ) === '0 ' ) {
2345
2319
ShutdownHandler::setMessage ('Fatal error: Premature end of PHP process. Use display_errors=On to see the error message. ' );
2346
2320
}
2347
2321
2348
- $ capture = tmpfile ();
2322
+ $ errorLogCapture = tmpfile ();
2349
2323
2350
- if ($ capture !== false ) {
2351
- $ capturePath = stream_get_meta_data ($ capture )['uri ' ];
2324
+ if ($ errorLogCapture !== false ) {
2325
+ $ capturePath = stream_get_meta_data ($ errorLogCapture )['uri ' ];
2352
2326
2353
2327
if (@is_writable ($ capturePath )) {
2354
2328
$ this ->previousErrorLogTarget = ini_set ('error_log ' , $ capturePath );
2355
2329
} else {
2356
- $ capture = false ;
2330
+ $ errorLogCapture = false ;
2331
+ }
2332
+ }
2333
+
2334
+ $ this ->errorLogCapture = $ errorLogCapture ;
2335
+ }
2336
+
2337
+ private function verifyErrorLogExpectation (): void
2338
+ {
2339
+ if ($ this ->errorLogCapture !== false ) {
2340
+ $ errorLogOutput = stream_get_contents ($ this ->errorLogCapture );
2341
+
2342
+ if ($ this ->expectErrorLog ) {
2343
+ $ this ->assertNotEmpty ($ errorLogOutput , 'Test did not call error_log(). ' );
2344
+ } else {
2345
+ if ($ errorLogOutput !== false ) {
2346
+ print $ this ->stripDateFromErrorLog ($ errorLogOutput );
2347
+ }
2357
2348
}
2349
+ } elseif ($ this ->expectErrorLog ) {
2350
+ $ this ->markTestIncomplete ('Could not create writable error_log file. ' );
2358
2351
}
2352
+ }
2353
+
2354
+ private function handleErrorLogError (): void
2355
+ {
2356
+ if ($ this ->errorLogCapture !== false ) {
2357
+ if (!$ this ->expectErrorLog ) {
2358
+ $ errorLogOutput = stream_get_contents ($ this ->errorLogCapture );
2359
2359
2360
- return $ capture ;
2360
+ if ($ errorLogOutput !== false ) {
2361
+ print $ this ->stripDateFromErrorLog ($ errorLogOutput );
2362
+ }
2363
+ }
2364
+ }
2365
+ }
2366
+
2367
+ private function stopErrorLogCapture (): void
2368
+ {
2369
+ if ($ this ->errorLogCapture !== false ) {
2370
+ ShutdownHandler::resetMessage ();
2371
+
2372
+ fclose ($ this ->errorLogCapture );
2373
+
2374
+ $ this ->errorLogCapture = false ;
2375
+
2376
+ if ($ this ->previousErrorLogTarget !== false ) {
2377
+ ini_set ('error_log ' , $ this ->previousErrorLogTarget );
2378
+
2379
+ $ this ->previousErrorLogTarget = false ;
2380
+ }
2381
+ }
2361
2382
}
2362
2383
2363
2384
/**
0 commit comments