33
33
use function is_int ;
34
34
use function is_object ;
35
35
use function is_string ;
36
+ use function is_writable ;
36
37
use function libxml_clear_errors ;
37
38
use function method_exists ;
38
39
use function ob_end_clean ;
@@ -1298,34 +1299,46 @@ private function runTest(): mixed
1298
1299
$ testArguments = array_merge ($ this ->data , array_values ($ this ->dependencyInput ));
1299
1300
1300
1301
$ capture = tmpfile ();
1301
- assert ($ capture !== false );
1302
1302
1303
1303
if (ini_get ('display_errors ' ) === '0 ' ) {
1304
1304
ShutdownHandler::setMessage ('Fatal error: Premature end of PHP process. Use display_errors=On to see the error message. ' );
1305
1305
}
1306
- $ errorLogPrevious = ini_set ('error_log ' , stream_get_meta_data ($ capture )['uri ' ]);
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
+ }
1307
1316
1308
1317
try {
1309
1318
/** @phpstan-ignore method.dynamicName */
1310
1319
$ testResult = $ this ->{$ this ->methodName }(...$ testArguments );
1311
1320
1312
- $ errorLogOutput = stream_get_contents ($ capture );
1321
+ if ($ capture !== false ) {
1322
+ $ errorLogOutput = stream_get_contents ($ capture );
1313
1323
1314
- if ($ this ->expectErrorLog ) {
1315
- $ this ->assertNotEmpty ($ errorLogOutput , 'Test did not call error_log(). ' );
1316
- } else {
1317
- if ($ errorLogOutput !== false ) {
1318
- // strip date from logged error, see https://github.com/php/php-src/blob/c696087e323263e941774ebbf902ac249774ec9f/main/main.c#L905
1319
- print preg_replace ('/\[.+\] / ' , '' , $ errorLogOutput );
1324
+ if ($ this ->expectErrorLog ) {
1325
+ $ this ->assertNotEmpty ($ errorLogOutput , 'Test did not call error_log(). ' );
1326
+ } else {
1327
+ if ($ errorLogOutput !== false ) {
1328
+ // strip date from logged error, see https://github.com/php/php-src/blob/c696087e323263e941774ebbf902ac249774ec9f/main/main.c#L905
1329
+ print preg_replace ('/\[.+\] / ' , '' , $ errorLogOutput );
1330
+ }
1320
1331
}
1321
1332
}
1322
1333
} catch (Throwable $ exception ) {
1323
- if (!$ this ->expectErrorLog ) {
1324
- $ errorLogOutput = stream_get_contents ($ capture );
1334
+ if ($ capture !== false ) {
1335
+ if (!$ this ->expectErrorLog ) {
1336
+ $ errorLogOutput = stream_get_contents ($ capture );
1325
1337
1326
- if ($ errorLogOutput !== false ) {
1327
- // strip date from logged error, see https://github.com/php/php-src/blob/c696087e323263e941774ebbf902ac249774ec9f/main/main.c#L905
1328
- print preg_replace ('/\[.+\] / ' , '' , $ errorLogOutput );
1338
+ if ($ errorLogOutput !== false ) {
1339
+ // strip date from logged error, see https://github.com/php/php-src/blob/c696087e323263e941774ebbf902ac249774ec9f/main/main.c#L905
1340
+ print preg_replace ('/\[.+\] / ' , '' , $ errorLogOutput );
1341
+ }
1329
1342
}
1330
1343
}
1331
1344
@@ -1337,10 +1350,13 @@ private function runTest(): mixed
1337
1350
1338
1351
return null ;
1339
1352
} finally {
1340
- ShutdownHandler::resetMessage ();
1341
- fclose ($ capture );
1353
+ if ($ capture !== false ) {
1354
+ ShutdownHandler::resetMessage ();
1355
+ fclose ($ capture );
1342
1356
1343
- ini_set ('error_log ' , $ errorLogPrevious );
1357
+ /** @phpstan-ignore variable.undefined (https://github.com/phpstan/phpstan/issues/12992) */
1358
+ ini_set ('error_log ' , $ errorLogPrevious );
1359
+ }
1344
1360
}
1345
1361
1346
1362
$ this ->expectedExceptionWasNotRaised ();
0 commit comments