From 631145a326530c3d689fc7762650d750a66cd807 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Mon, 25 Nov 2024 19:50:19 +0100 Subject: [PATCH] test --- src/Analyser/MutatingScope.php | 2 +- src/Php/PhpVersions.php | 5 +++ .../PHPStan/Analyser/ScopePhpVersionTest.php | 39 +++++++++++++++++++ .../Analyser/data/global-scope-constants.php | 9 +++++ 4 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 tests/PHPStan/Analyser/ScopePhpVersionTest.php create mode 100644 tests/PHPStan/Analyser/data/global-scope-constants.php diff --git a/src/Analyser/MutatingScope.php b/src/Analyser/MutatingScope.php index cadd4761f4..f883c95578 100644 --- a/src/Analyser/MutatingScope.php +++ b/src/Analyser/MutatingScope.php @@ -5691,7 +5691,7 @@ private function getGlobalConstantType(Name $name): ?Type $fetches[] = new ConstFetch(new FullyQualified($name->toString())); $fetches[] = new ConstFetch($name); - foreach($fetches as $constFetch) { + foreach ($fetches as $constFetch) { if ($this->hasExpressionType($constFetch)->yes()) { return $this->getType($constFetch); } diff --git a/src/Php/PhpVersions.php b/src/Php/PhpVersions.php index 74474b28b0..229dccb72d 100644 --- a/src/Php/PhpVersions.php +++ b/src/Php/PhpVersions.php @@ -18,6 +18,11 @@ public function __construct( { } + public function getType(): Type + { + return $this->phpVersions; + } + public function supportsNoncapturingCatches(): TrinaryLogic { return IntegerRangeType::fromInterval(80000, null)->isSuperTypeOf($this->phpVersions)->result; diff --git a/tests/PHPStan/Analyser/ScopePhpVersionTest.php b/tests/PHPStan/Analyser/ScopePhpVersionTest.php new file mode 100644 index 0000000000..8f4fc492b2 --- /dev/null +++ b/tests/PHPStan/Analyser/ScopePhpVersionTest.php @@ -0,0 +1,39 @@ +', + __DIR__ . '/data/global-scope-constants.php', + ], + ]; + } + + /** + * @dataProvider dataTestPhpVersion + */ + public function testPhpVersion(string $expected, string $file): void + { + self::processFile($file, function (Node $node, Scope $scope) use ($expected): void { + if (!($node instanceof Exit_)) { + return; + } + $this->assertSame( + $expected, + $scope->getPhpVersion()->getType()->describe(VerbosityLevel::precise()), + ); + }); + } + +} diff --git a/tests/PHPStan/Analyser/data/global-scope-constants.php b/tests/PHPStan/Analyser/data/global-scope-constants.php new file mode 100644 index 0000000000..56eba41c9a --- /dev/null +++ b/tests/PHPStan/Analyser/data/global-scope-constants.php @@ -0,0 +1,9 @@ +