Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Dec 20, 2024
1 parent a2aeea1 commit 631145a
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Analyser/MutatingScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
5 changes: 5 additions & 0 deletions src/Php/PhpVersions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
39 changes: 39 additions & 0 deletions tests/PHPStan/Analyser/ScopePhpVersionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php declare(strict_types = 1);

namespace PHPStan\Analyser;

use PhpParser\Node;
use PhpParser\Node\Expr\Exit_;
use PHPStan\Testing\TypeInferenceTestCase;
use PHPStan\Type\VerbosityLevel;

class ScopePhpVersionTest extends TypeInferenceTestCase
{

public function dataTestPhpVersion(): array
{
return [
[
'int<80000, 80499>',
__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()),
);
});
}

}
9 changes: 9 additions & 0 deletions tests/PHPStan/Analyser/data/global-scope-constants.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

// global namespace required for the test to work

if (PHP_VERSION_ID < 80000) {
return;
}

exit();

0 comments on commit 631145a

Please sign in to comment.