From 28694e86d567c959aa4894db11bc715f9959fcba Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Thu, 4 Dec 2025 16:26:40 +0100 Subject: [PATCH 1/8] More precise return type for gatherAssertTypes --- src/Testing/TypeInferenceTestCase.php | 7 ++++++- tests/PHPStan/Analyser/LooseConstComparisonPhp7Test.php | 3 --- tests/PHPStan/Analyser/LooseConstComparisonPhp8Test.php | 3 --- tests/PHPStan/Analyser/SubstrPhp7Test.php | 4 ---- tests/PHPStan/Analyser/SubstrPhp8Test.php | 3 --- 5 files changed, 6 insertions(+), 14 deletions(-) diff --git a/src/Testing/TypeInferenceTestCase.php b/src/Testing/TypeInferenceTestCase.php index f3c998d5dc..a9f4a354ef 100644 --- a/src/Testing/TypeInferenceTestCase.php +++ b/src/Testing/TypeInferenceTestCase.php @@ -220,8 +220,13 @@ public function assertFileAsserts( } /** + * @return array + * * @api - * @return array */ public static function gatherAssertTypes(string $file): array { diff --git a/tests/PHPStan/Analyser/LooseConstComparisonPhp7Test.php b/tests/PHPStan/Analyser/LooseConstComparisonPhp7Test.php index 3b4f48d07a..3139b7a5b9 100644 --- a/tests/PHPStan/Analyser/LooseConstComparisonPhp7Test.php +++ b/tests/PHPStan/Analyser/LooseConstComparisonPhp7Test.php @@ -8,9 +8,6 @@ class LooseConstComparisonPhp7Test extends TypeInferenceTestCase { - /** - * @return iterable> - */ public static function dataFileAsserts(): iterable { // compares constants according to the php-version phpstan configuration, diff --git a/tests/PHPStan/Analyser/LooseConstComparisonPhp8Test.php b/tests/PHPStan/Analyser/LooseConstComparisonPhp8Test.php index fae702cec2..35ade6c0cd 100644 --- a/tests/PHPStan/Analyser/LooseConstComparisonPhp8Test.php +++ b/tests/PHPStan/Analyser/LooseConstComparisonPhp8Test.php @@ -8,9 +8,6 @@ class LooseConstComparisonPhp8Test extends TypeInferenceTestCase { - /** - * @return iterable> - */ public static function dataFileAsserts(): iterable { // compares constants according to the php-version phpstan configuration, diff --git a/tests/PHPStan/Analyser/SubstrPhp7Test.php b/tests/PHPStan/Analyser/SubstrPhp7Test.php index 561b33500c..f18ed6dad9 100644 --- a/tests/PHPStan/Analyser/SubstrPhp7Test.php +++ b/tests/PHPStan/Analyser/SubstrPhp7Test.php @@ -7,10 +7,6 @@ class SubstrPhp7Test extends TypeInferenceTestCase { - - /** - * @return iterable> - */ public static function dataFileAsserts(): iterable { yield from self::gatherAssertTypes(__DIR__ . '/data/bug-13129-php7.php'); diff --git a/tests/PHPStan/Analyser/SubstrPhp8Test.php b/tests/PHPStan/Analyser/SubstrPhp8Test.php index 934a7ac78c..a5da5b57c8 100644 --- a/tests/PHPStan/Analyser/SubstrPhp8Test.php +++ b/tests/PHPStan/Analyser/SubstrPhp8Test.php @@ -8,9 +8,6 @@ class SubstrPhp8Test extends TypeInferenceTestCase { - /** - * @return iterable> - */ public static function dataFileAsserts(): iterable { yield from self::gatherAssertTypes(__DIR__ . '/data/bug-13129-php8.php'); From b67108e912dd36fd9b6180996b801dd30a76592a Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Thu, 4 Dec 2025 16:28:56 +0100 Subject: [PATCH 2/8] cs --- tests/PHPStan/Analyser/SubstrPhp7Test.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/PHPStan/Analyser/SubstrPhp7Test.php b/tests/PHPStan/Analyser/SubstrPhp7Test.php index f18ed6dad9..deb4f19717 100644 --- a/tests/PHPStan/Analyser/SubstrPhp7Test.php +++ b/tests/PHPStan/Analyser/SubstrPhp7Test.php @@ -7,6 +7,7 @@ class SubstrPhp7Test extends TypeInferenceTestCase { + public static function dataFileAsserts(): iterable { yield from self::gatherAssertTypes(__DIR__ . '/data/bug-13129-php7.php'); From a447737714f75a99fc88790e8f8272dcf2f14092 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Thu, 4 Dec 2025 16:33:50 +0100 Subject: [PATCH 3/8] fix --- tests/PHPStan/Analyser/NodeScopeResolverTest.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/PHPStan/Analyser/NodeScopeResolverTest.php b/tests/PHPStan/Analyser/NodeScopeResolverTest.php index c8beac7f17..14cf5d2851 100644 --- a/tests/PHPStan/Analyser/NodeScopeResolverTest.php +++ b/tests/PHPStan/Analyser/NodeScopeResolverTest.php @@ -270,17 +270,21 @@ public function testFile(string $file): void $failures = []; foreach ($asserts as $args) { - $assertType = array_shift($args); - $file = array_shift($args); - if ($assertType === 'type') { + if ($args[0] === 'type') { + $assertType = array_shift($args); + $file = array_shift($args); + $expected = $args[0]; $actual = $args[1]; if ($expected !== $actual) { $failures[] = sprintf("Line %d:\nExpected: %s\nActual: %s\n", $args[2], $expected, $actual); } - } elseif ($assertType === 'variableCertainty') { + } elseif ($args[0] === 'variableCertainty') { + $assertType = array_shift($args); + $file = array_shift($args); + $expectedCertainty = $args[0]; $actualCertainty = $args[1]; $variableName = $args[2]; From eb6f8d67075cbc02f9edb61022fff03d2924f279 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Thu, 4 Dec 2025 16:42:54 +0100 Subject: [PATCH 4/8] fix --- .../Analyser/NodeScopeResolverTest.php | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/tests/PHPStan/Analyser/NodeScopeResolverTest.php b/tests/PHPStan/Analyser/NodeScopeResolverTest.php index 14cf5d2851..1f3f1bf450 100644 --- a/tests/PHPStan/Analyser/NodeScopeResolverTest.php +++ b/tests/PHPStan/Analyser/NodeScopeResolverTest.php @@ -12,6 +12,7 @@ use function define; use function dirname; use function implode; +use function PHPStan\dumpType; use function sprintf; use function str_starts_with; use function strlen; @@ -270,27 +271,24 @@ public function testFile(string $file): void $failures = []; foreach ($asserts as $args) { - if ($args[0] === 'type') { - $assertType = array_shift($args); - $file = array_shift($args); + $file = $args[1]; - $expected = $args[0]; - $actual = $args[1]; + $expected = $args[2]; + $actual = $args[3]; if ($expected !== $actual) { - $failures[] = sprintf("Line %d:\nExpected: %s\nActual: %s\n", $args[2], $expected, $actual); + $failures[] = sprintf("Line %d:\nExpected: %s\nActual: %s\n", $args[4], $expected, $actual); } } elseif ($args[0] === 'variableCertainty') { - $assertType = array_shift($args); - $file = array_shift($args); + $file = $args[1]; - $expectedCertainty = $args[0]; - $actualCertainty = $args[1]; - $variableName = $args[2]; + $expectedCertainty = $args[2]; + $actualCertainty = $args[3]; + $variableName = $args[4]; if ($expectedCertainty->equals($actualCertainty) !== true) { - $failures[] = sprintf("Certainty of %s on line %d:\nExpected: %s\nActual: %s\n", $variableName, $args[3], $expectedCertainty->describe(), $actualCertainty->describe()); + $failures[] = sprintf("Certainty of %s on line %d:\nExpected: %s\nActual: %s\n", $variableName, $args[5], $expectedCertainty->describe(), $actualCertainty->describe()); } } } From 833ed4e28962ab9b475c939fd4ee90d36cb4367c Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Thu, 4 Dec 2025 16:44:17 +0100 Subject: [PATCH 5/8] fix --- src/Testing/TypeInferenceTestCase.php | 4 ++-- tests/PHPStan/Analyser/NodeScopeResolverTest.php | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Testing/TypeInferenceTestCase.php b/src/Testing/TypeInferenceTestCase.php index a9f4a354ef..14858bcbcd 100644 --- a/src/Testing/TypeInferenceTestCase.php +++ b/src/Testing/TypeInferenceTestCase.php @@ -395,7 +395,7 @@ public static function gatherAssertTypes(string $file): array } if (count($delayedErrors) === 0) { - return $asserts; + return $asserts; // @phpstan-ignore return.type } foreach ($asserts as $i => $assert) { @@ -403,7 +403,7 @@ public static function gatherAssertTypes(string $file): array $asserts[$i] = $assert; } - return $asserts; + return $asserts; // @phpstan-ignore return.type } /** diff --git a/tests/PHPStan/Analyser/NodeScopeResolverTest.php b/tests/PHPStan/Analyser/NodeScopeResolverTest.php index 1f3f1bf450..c08efc1a78 100644 --- a/tests/PHPStan/Analyser/NodeScopeResolverTest.php +++ b/tests/PHPStan/Analyser/NodeScopeResolverTest.php @@ -8,11 +8,9 @@ use PHPUnit\Framework\Attributes\DataProvider; use stdClass; use function array_merge; -use function array_shift; use function define; use function dirname; use function implode; -use function PHPStan\dumpType; use function sprintf; use function str_starts_with; use function strlen; From 5064ea444973bbd69cd27c57e6c754405ed52347 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Thu, 4 Dec 2025 18:23:10 +0100 Subject: [PATCH 6/8] Update TypeInferenceTestCase.php --- src/Testing/TypeInferenceTestCase.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Testing/TypeInferenceTestCase.php b/src/Testing/TypeInferenceTestCase.php index 14858bcbcd..d8b541abbc 100644 --- a/src/Testing/TypeInferenceTestCase.php +++ b/src/Testing/TypeInferenceTestCase.php @@ -221,9 +221,9 @@ public function assertFileAsserts( /** * @return array * * @api @@ -395,7 +395,7 @@ public static function gatherAssertTypes(string $file): array } if (count($delayedErrors) === 0) { - return $asserts; // @phpstan-ignore return.type + return $asserts; } foreach ($asserts as $i => $assert) { @@ -403,7 +403,7 @@ public static function gatherAssertTypes(string $file): array $asserts[$i] = $assert; } - return $asserts; // @phpstan-ignore return.type + return $asserts; } /** From d667fc1950b835fcd196ea15c0a2b86ef11caab0 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Thu, 4 Dec 2025 18:30:59 +0100 Subject: [PATCH 7/8] Update TypeInferenceTestCase.php --- src/Testing/TypeInferenceTestCase.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Testing/TypeInferenceTestCase.php b/src/Testing/TypeInferenceTestCase.php index d8b541abbc..ecc5b08e0a 100644 --- a/src/Testing/TypeInferenceTestCase.php +++ b/src/Testing/TypeInferenceTestCase.php @@ -44,6 +44,7 @@ use function in_array; use function is_dir; use function is_string; +use function PHPStan\dumpType; use function preg_match; use function sprintf; use function str_starts_with; @@ -221,9 +222,9 @@ public function assertFileAsserts( /** * @return array}| + * array{0: 'superType', 1: string, 2: string, 3: string, 4: bool, 5: int, 6?: non-empty-list}| + * array{0: 'variableCertainty', 1: string, 2: TrinaryLogic, 3: TrinaryLogic, 4: string, 5: int, 6?: non-empty-list} * )> * * @api From 912cd5a0d081b6333a067f981e5effac87cc89b8 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Thu, 4 Dec 2025 18:31:15 +0100 Subject: [PATCH 8/8] Update TypeInferenceTestCase.php --- src/Testing/TypeInferenceTestCase.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Testing/TypeInferenceTestCase.php b/src/Testing/TypeInferenceTestCase.php index ecc5b08e0a..be3471b02d 100644 --- a/src/Testing/TypeInferenceTestCase.php +++ b/src/Testing/TypeInferenceTestCase.php @@ -44,7 +44,6 @@ use function in_array; use function is_dir; use function is_string; -use function PHPStan\dumpType; use function preg_match; use function sprintf; use function str_starts_with;