Skip to content

Commit a7532a2

Browse files
authored
Avoid crash by triggering side-effect via count on PHPUnit\Framework\Test
1 parent a52eda5 commit a7532a2

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"phpstan/phpstan": "1.11.4",
2727
"phpstan/phpstan-phpunit": "1.4.0",
2828
"phpstan/phpstan-strict-rules": "1.6.0",
29-
"phpunit/phpunit": "^9.5 || 10.5.20",
29+
"phpunit/phpunit": "^9.5 || ^10.5.21",
3030
"psr/http-message": "^1 || ^2",
3131
"react/http": "^1.6",
3232
"react/promise": "^2.0 || ^3.0",

src/Error/FormattedError.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use GraphQL\Language\SourceLocation;
88
use GraphQL\Type\Definition\Type;
99
use GraphQL\Utils\Utils;
10+
use PHPUnit\Framework\Test;
1011

1112
/**
1213
* This class is used for [default error formatting](error-handling.md).
@@ -299,7 +300,12 @@ public static function printVar($var): string
299300
}
300301

301302
if (\is_object($var)) {
302-
return 'instance of ' . \get_class($var) . ($var instanceof \Countable ? '(' . \count($var) . ')' : '');
303+
// Calling `count` on instances of `PHPUnit\Framework\Test` triggers an unintended side effect - see https://github.com/sebastianbergmann/phpunit/issues/5866#issuecomment-2172429263
304+
$count = ! $var instanceof Test && $var instanceof \Countable
305+
? '(' . \count($var) . ')'
306+
: '';
307+
308+
return 'instance of ' . \get_class($var) . $count;
303309
}
304310

305311
if (\is_array($var)) {

0 commit comments

Comments
 (0)