From b64c6731a86422784c33365c288c70f84cd13050 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Thu, 15 Dec 2022 14:43:16 +0100 Subject: [PATCH] Regression test Closes https://github.com/phpstan/phpstan/issues/4565 --- .../Analyser/NodeScopeResolverTest.php | 1 + tests/PHPStan/Analyser/data/bug-4565.php | 19 +++++++++++++++++++ .../PHPStan/Rules/Variables/UnsetRuleTest.php | 5 +++++ 3 files changed, 25 insertions(+) create mode 100644 tests/PHPStan/Analyser/data/bug-4565.php diff --git a/tests/PHPStan/Analyser/NodeScopeResolverTest.php b/tests/PHPStan/Analyser/NodeScopeResolverTest.php index 84a63fabf1..7cca5ea24f 100644 --- a/tests/PHPStan/Analyser/NodeScopeResolverTest.php +++ b/tests/PHPStan/Analyser/NodeScopeResolverTest.php @@ -1140,6 +1140,7 @@ public function dataFileAsserts(): iterable yield from $this->gatherAssertTypes(__DIR__ . '/data/discussion-8447.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-7805.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-82.php'); + yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-4565.php'); } /** diff --git a/tests/PHPStan/Analyser/data/bug-4565.php b/tests/PHPStan/Analyser/data/bug-4565.php new file mode 100644 index 0000000000..af941f8098 --- /dev/null +++ b/tests/PHPStan/Analyser/data/bug-4565.php @@ -0,0 +1,19 @@ + ''] + $variables['attributes']; + assertType('non-empty-array', $attributes); + if (!empty($variables['button'])) { + assertType('non-empty-array', $attributes); + $attributes['type'] = 'button'; + assertType("hasOffsetValue('type', 'button')&non-empty-array", $attributes); + unset($attributes['href']); + assertType("array&hasOffsetValue('type', 'button')", $attributes); + } + assertType('array', $attributes); + return $attributes; +} diff --git a/tests/PHPStan/Rules/Variables/UnsetRuleTest.php b/tests/PHPStan/Rules/Variables/UnsetRuleTest.php index d6a09f29fe..f6897a5b9c 100644 --- a/tests/PHPStan/Rules/Variables/UnsetRuleTest.php +++ b/tests/PHPStan/Rules/Variables/UnsetRuleTest.php @@ -86,4 +86,9 @@ public function testBug8113(): void $this->analyse([__DIR__ . '/data/bug-8113.php'], []); } + public function testBug4565(): void + { + $this->analyse([__DIR__ . '/../../Analyser/data/bug-4565.php'], []); + } + }