diff --git a/tests/PHPStan/Analyser/NodeScopeResolverTest.php b/tests/PHPStan/Analyser/NodeScopeResolverTest.php index 0701921eaf..85d802ca25 100644 --- a/tests/PHPStan/Analyser/NodeScopeResolverTest.php +++ b/tests/PHPStan/Analyser/NodeScopeResolverTest.php @@ -961,6 +961,7 @@ public function dataFileAsserts(): iterable yield from $this->gatherAssertTypes(__DIR__ . '/../Rules/Arrays/data/bug-6364.php'); yield from $this->gatherAssertTypes(__DIR__ . '/../Rules/Arrays/data/bug-5758.php'); yield from $this->gatherAssertTypes(__DIR__ . '/../Rules/Functions/data/bug-3931.php'); + yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-5223.php'); } /** diff --git a/tests/PHPStan/Analyser/data/bug-5223.php b/tests/PHPStan/Analyser/data/bug-5223.php new file mode 100644 index 0000000000..0e19768606 --- /dev/null +++ b/tests/PHPStan/Analyser/data/bug-5223.php @@ -0,0 +1,56 @@ +, tagNames: array}", $filters); + + unset($filters['page']); + assertType("array{categoryKeys: array, tagNames: array}", $filters); + + unset($filters['limit']); + assertType("array{categoryKeys: array, tagNames: array}", $filters); + + assertType('*ERROR*', $filters['something']); + var_dump($filters['something']); + + $this->test($filters); + } + + /** + * @param array{ + * categoryKeys: string[], + * tagNames: string[], + * } $filters + */ + public function withoutUnset(array $filters): void + { + assertType("array{categoryKeys: array, tagNames: array}", $filters); + assertType('*ERROR*', $filters['something']); + var_dump($filters['something']); + + $this->test($filters); + } + + /** + * @param array{ + * categoryKeys: string[], + * tagNames: string[], + * } $filters + */ + private function test(array $filters): void + { + } +} diff --git a/tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php b/tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php index 33139d1a7f..abba64d252 100644 --- a/tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php +++ b/tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php @@ -453,4 +453,26 @@ public function testBug5758(): void $this->analyse([__DIR__ . '/data/bug-5758.php'], []); } + public function testBug5223(): void + { + $this->analyse([__DIR__ . '/../../Analyser/data/bug-5223.php'], [ + [ + 'Offset \'something\' does not exist on array{categoryKeys: array, tagNames: array}.', + 26, + ], + [ + 'Offset \'something\' does not exist on array{categoryKeys: array, tagNames: array}.', + 27, + ], + [ + 'Offset \'something\' does not exist on array{categoryKeys: array, tagNames: array}.', + 41, + ], + [ + 'Offset \'something\' does not exist on array{categoryKeys: array, tagNames: array}.', + 42, + ], + ]); + } + } diff --git a/tests/PHPStan/Rules/Variables/UnsetRuleTest.php b/tests/PHPStan/Rules/Variables/UnsetRuleTest.php index 370fe14ea6..ef7bb22993 100644 --- a/tests/PHPStan/Rules/Variables/UnsetRuleTest.php +++ b/tests/PHPStan/Rules/Variables/UnsetRuleTest.php @@ -57,4 +57,18 @@ public function testBug4289(): void $this->analyse([__DIR__ . '/data/bug-4289.php'], []); } + public function testBug5223(): void + { + $this->analyse([__DIR__ . '/../../Analyser/data/bug-5223.php'], [ + [ + 'Cannot unset offset \'page\' on array{categoryKeys: array, tagNames: array}.', + 20, + ], + [ + 'Cannot unset offset \'limit\' on array{categoryKeys: array, tagNames: array}.', + 23, + ], + ]); + } + }