-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement ReflectionClass#getTraitClassNames()
#1362
Conversation
public function testGetTraitNamesWithMissingTraitDefinitions(): void | ||
{ | ||
$reflector = new DefaultReflector(new SingleFileSourceLocator( | ||
__DIR__ . '/../Fixture/ClassUsesUnknownTrait.php', | ||
$this->astLocator, | ||
)); | ||
|
||
$this->expectException(IdentifierNotFound::class); | ||
|
||
$reflector->reflectClass(Fixture\ClassUsesUnknownTrait::class)->getTraitNames(); | ||
} | ||
|
||
public function testGetTraitsWithMissingTraitDefinitions(): void | ||
{ | ||
$reflector = new DefaultReflector(new SingleFileSourceLocator( | ||
__DIR__ . '/../Fixture/ClassUsesUnknownTrait.php', | ||
$this->astLocator, | ||
)); | ||
|
||
$this->expectException(IdentifierNotFound::class); | ||
|
||
$reflector->reflectClass(Fixture\ClassUsesUnknownTrait::class)->getTraits(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these tests show, that the pre-PR existing API always throws and therefore does not allow to get the interface names, when the class-symbols are not autoloadable.
self::assertSame( | ||
[], | ||
$reflector->reflectClass(Fixture\ClassUsesUnknownTrait::class)->getTraitAliases(), | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getTraitAliases()
does not require autoloadable symbols, therefore runs without exceptions
[ | ||
__DIR__ . '/../Fixture/ClassUsesUnknownTrait.php', | ||
Fixture\ClassUsesUnknownTrait::class, | ||
['Roave\BetterReflectionTest\Fixture\UnknownTrait'], | ||
], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this first test-case shows that we are now able to extract the trait names even if not autoloadable.
the remaining cases add coverage for a few more related cases
Thanks @staabm! |
same motivation as in #1359, but this time for traits:-)
refs rectorphp/rector#8093 (comment)