Skip to content

Commit 1f2c176

Browse files
author
moellekenl
committed
[+]: Add handling for private and protected constants in reflection and parsing v3
1 parent 17c9c2e commit 1f2c176

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

tests/ParserTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3081,22 +3081,23 @@ public function testReflectionRecoversFromPrivateAndProtectedConstantVisibilityE
30813081
// (readObjectFromReflection) rather than the AST path, since the two
30823082
// code paths hit different PHP engine APIs (constant() vs
30833083
// ReflectionClassConstant::getValue() / ReflectionParameter).
3084+
$parserContainer = new \voku\SimplePhpParser\Parsers\Helper\ParserContainer();
30843085
$reflectionClass = new \ReflectionClass(DummyPrivateConstOwner::class);
30853086

3086-
$privateConstant = (new \voku\SimplePhpParser\Model\PHPConst())
3087+
$privateConstant = (new \voku\SimplePhpParser\Model\PHPConst($parserContainer))
30873088
->readObjectFromReflection($reflectionClass->getReflectionConstant('SECRET'));
30883089
static::assertSame('private', $privateConstant->visibility);
30893090
static::assertNull($privateConstant->value);
30903091
static::assertSame('null', $privateConstant->type);
30913092

3092-
$protectedConstant = (new \voku\SimplePhpParser\Model\PHPConst())
3093+
$protectedConstant = (new \voku\SimplePhpParser\Model\PHPConst($parserContainer))
30933094
->readObjectFromReflection($reflectionClass->getReflectionConstant('GUARDED'));
30943095
static::assertSame('protected', $protectedConstant->visibility);
30953096
static::assertNull($protectedConstant->value);
30963097
static::assertSame('null', $protectedConstant->type);
30973098

30983099
// A publicly visible constant must still resolve normally.
3099-
$publicConstant = (new \voku\SimplePhpParser\Model\PHPConst())
3100+
$publicConstant = (new \voku\SimplePhpParser\Model\PHPConst($parserContainer))
31003101
->readObjectFromReflection($reflectionClass->getReflectionConstant('OPEN'));
31013102
static::assertSame('public', $publicConstant->visibility);
31023103
static::assertSame('open-value', $publicConstant->value);
@@ -3105,7 +3106,7 @@ public function testReflectionRecoversFromPrivateAndProtectedConstantVisibilityE
31053106
$reflectionParameter = (new \ReflectionMethod(DummyPrivateConstConsumer::class, 'withPrivateConstDefault'))
31063107
->getParameters()[0];
31073108

3108-
$param = (new \voku\SimplePhpParser\Model\PHPParameter())->readObjectFromReflection($reflectionParameter);
3109+
$param = (new \voku\SimplePhpParser\Model\PHPParameter($parserContainer))->readObjectFromReflection($reflectionParameter);
31093110
static::assertNull($param->defaultValue);
31103111
static::assertSame('string', $param->type);
31113112
}

0 commit comments

Comments
 (0)