32
32
use function is_int ;
33
33
use function is_object ;
34
34
use function is_string ;
35
+ use function is_writable ;
35
36
use function libxml_clear_errors ;
36
37
use function method_exists ;
37
38
use function ob_end_clean ;
@@ -1252,27 +1253,40 @@ private function runTest(): mixed
1252
1253
{
1253
1254
$ testArguments = array_merge ($ this ->data , array_values ($ this ->dependencyInput ));
1254
1255
1255
- $ capture = tmpfile ();
1256
- $ errorLogPrevious = ini_set ('error_log ' , stream_get_meta_data ($ capture )['uri ' ]);
1256
+ $ capture = tmpfile ();
1257
+
1258
+ if ($ capture !== false ) {
1259
+ $ capturePath = stream_get_meta_data ($ capture )['uri ' ];
1260
+
1261
+ if (@is_writable ($ capturePath )) {
1262
+ $ errorLogPrevious = ini_set ('error_log ' , $ capturePath );
1263
+ } else {
1264
+ $ capture = false ;
1265
+ }
1266
+ }
1257
1267
1258
1268
try {
1259
1269
/** @phpstan-ignore method.dynamicName */
1260
1270
$ testResult = $ this ->{$ this ->methodName }(...$ testArguments );
1261
1271
1262
- $ errorLogOutput = stream_get_contents ($ capture );
1272
+ if ($ capture !== false ) {
1273
+ $ errorLogOutput = stream_get_contents ($ capture );
1263
1274
1264
- if ($ this ->expectErrorLog ) {
1265
- $ this ->assertNotEmpty ($ errorLogOutput , 'Test did not call error_log(). ' );
1266
- } else {
1267
- // strip date from logged error, see https://github.com/php/php-src/blob/c696087e323263e941774ebbf902ac249774ec9f/main/main.c#L905
1268
- print preg_replace ('/\[.+\] / ' , '' , $ errorLogOutput );
1275
+ if ($ this ->expectErrorLog ) {
1276
+ $ this ->assertNotEmpty ($ errorLogOutput , 'Test did not call error_log(). ' );
1277
+ } else {
1278
+ // strip date from logged error, see https://github.com/php/php-src/blob/c696087e323263e941774ebbf902ac249774ec9f/main/main.c#L905
1279
+ print preg_replace ('/\[.+\] / ' , '' , $ errorLogOutput );
1280
+ }
1269
1281
}
1270
1282
} catch (Throwable $ exception ) {
1271
- if (!$ this ->expectErrorLog ) {
1272
- $ errorLogOutput = stream_get_contents ($ capture );
1283
+ if ($ capture !== false ) {
1284
+ if (!$ this ->expectErrorLog ) {
1285
+ $ errorLogOutput = stream_get_contents ($ capture );
1273
1286
1274
- // strip date from logged error, see https://github.com/php/php-src/blob/c696087e323263e941774ebbf902ac249774ec9f/main/main.c#L905
1275
- print preg_replace ('/\[.+\] / ' , '' , $ errorLogOutput );
1287
+ // strip date from logged error, see https://github.com/php/php-src/blob/c696087e323263e941774ebbf902ac249774ec9f/main/main.c#L905
1288
+ print preg_replace ('/\[.+\] / ' , '' , $ errorLogOutput );
1289
+ }
1276
1290
}
1277
1291
1278
1292
if (!$ this ->shouldExceptionExpectationsBeVerified ($ exception )) {
@@ -1285,9 +1299,10 @@ private function runTest(): mixed
1285
1299
} finally {
1286
1300
if ($ capture !== false ) {
1287
1301
fclose ($ capture );
1288
- }
1289
1302
1290
- ini_set ('error_log ' , $ errorLogPrevious );
1303
+ /** @phpstan-ignore variable.undefined (https://github.com/phpstan/phpstan/issues/12992) */
1304
+ ini_set ('error_log ' , $ errorLogPrevious );
1305
+ }
1291
1306
}
1292
1307
1293
1308
$ this ->expectedExceptionWasNotRaised ();
0 commit comments