|
12 | 12 | use PHPStan\Type\Constant\ConstantStringType;
|
13 | 13 | use PHPStan\Type\IntegerRangeType;
|
14 | 14 | use PHPStan\Type\ObjectType;
|
| 15 | +use PHPStan\Type\StringType; |
15 | 16 | use PHPStan\Type\Type;
|
16 | 17 | use PHPStan\Type\UnionType;
|
17 | 18 | use PHPStan\Type\VerbosityLevel;
|
18 | 19 |
|
| 20 | +/** |
| 21 | + * @covers \PHPStan\Analyser\MutatingScope |
| 22 | + */ |
19 | 23 | class ScopeTest extends PHPStanTestCase
|
20 | 24 | {
|
21 | 25 |
|
@@ -249,4 +253,26 @@ public function testGetConstantType(): void
|
249 | 253 | $this->assertSame('int<1, max>', $type->describe(VerbosityLevel::precise()));
|
250 | 254 | }
|
251 | 255 |
|
| 256 | + public function testDefinedVariables(): void |
| 257 | + { |
| 258 | + /** @var ScopeFactory $scopeFactory */ |
| 259 | + $scopeFactory = self::getContainer()->getByType(ScopeFactory::class); |
| 260 | + $scope = $scopeFactory->create(ScopeContext::create('file.php')) |
| 261 | + ->assignVariable('a', new ConstantStringType('a'), new StringType(), TrinaryLogic::createYes()) |
| 262 | + ->assignVariable('b', new ConstantStringType('b'), new StringType(), TrinaryLogic::createMaybe()); |
| 263 | + |
| 264 | + $this->assertSame(['a'], $scope->getDefinedVariables()); |
| 265 | + } |
| 266 | + |
| 267 | + public function testMaybeDefinedVariables(): void |
| 268 | + { |
| 269 | + /** @var ScopeFactory $scopeFactory */ |
| 270 | + $scopeFactory = self::getContainer()->getByType(ScopeFactory::class); |
| 271 | + $scope = $scopeFactory->create(ScopeContext::create('file.php')) |
| 272 | + ->assignVariable('a', new ConstantStringType('a'), new StringType(), TrinaryLogic::createYes()) |
| 273 | + ->assignVariable('b', new ConstantStringType('b'), new StringType(), TrinaryLogic::createMaybe()); |
| 274 | + |
| 275 | + $this->assertSame(['b'], $scope->getMaybeDefinedVariables()); |
| 276 | + } |
| 277 | + |
252 | 278 | }
|
0 commit comments