diff --git a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php index a5fedd94c7..413d8f160d 100644 --- a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php +++ b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php @@ -1338,6 +1338,7 @@ public function testBug9994(): void $this->assertSame('Parameter #2 $callback of function array_filter expects (callable(1|2|3|null): bool)|null, false given.', $errors[1]->getMessage()); } + #[RequiresPhp('>= 8.1')] public function testBug13987(): void { $errors = $this->runAnalyse(__DIR__ . '/data/bug-13987.php'); diff --git a/tests/PHPStan/Analyser/data/bug-13987.php b/tests/PHPStan/Analyser/data/bug-13987.php index a131a46a9b..5f5fb9612f 100644 --- a/tests/PHPStan/Analyser/data/bug-13987.php +++ b/tests/PHPStan/Analyser/data/bug-13987.php @@ -1,4 +1,4 @@ -= 8.1 namespace Bug13987; diff --git a/tests/PHPStan/Rules/Variables/DefinedVariableRuleTest.php b/tests/PHPStan/Rules/Variables/DefinedVariableRuleTest.php index 76578a1e36..d45bfd61ae 100644 --- a/tests/PHPStan/Rules/Variables/DefinedVariableRuleTest.php +++ b/tests/PHPStan/Rules/Variables/DefinedVariableRuleTest.php @@ -1180,4 +1180,14 @@ public function testBug13353(): void $this->analyse([__DIR__ . '/data/bug-13353.php'], []); } + public function testBug13694(): void + { + $this->cliArgumentsVariablesRegistered = true; + $this->polluteScopeWithLoopInitialAssignments = true; + $this->checkMaybeUndefinedVariables = true; + $this->polluteScopeWithAlwaysIterableForeach = true; + + $this->analyse([__DIR__ . '/data/bug-13694.php'], []); + } + } diff --git a/tests/PHPStan/Rules/Variables/data/bug-13694.php b/tests/PHPStan/Rules/Variables/data/bug-13694.php new file mode 100644 index 0000000000..02638dc810 --- /dev/null +++ b/tests/PHPStan/Rules/Variables/data/bug-13694.php @@ -0,0 +1,21 @@ + $things + */ +function evaluateThings(array $keys, array $things): void +{ + foreach ($keys as $key) { + if (array_key_exists($key, $things) && $things[$key] === null) { + echo "Value for key $key is null\n"; + continue; + } + + if (isset($things[$key])) { + echo "Key $key is set\n"; + } + } +}