Skip to content
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

Merged
merged 1 commit into from
Aug 7, 2023
Merged

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Aug 7, 2023

same motivation as in #1359, but this time for traits:-)

refs rectorphp/rector#8093 (comment)

Comment on lines +1505 to +1527
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();
}
Copy link
Contributor Author

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.

Comment on lines +1536 to +1539
self::assertSame(
[],
$reflector->reflectClass(Fixture\ClassUsesUnknownTrait::class)->getTraitAliases(),
);
Copy link
Contributor Author

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

Comment on lines +1561 to +1565
[
__DIR__ . '/../Fixture/ClassUsesUnknownTrait.php',
Fixture\ClassUsesUnknownTrait::class,
['Roave\BetterReflectionTest\Fixture\UnknownTrait'],
],
Copy link
Contributor Author

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

@Ocramius Ocramius self-assigned this Aug 7, 2023
@Ocramius Ocramius added this to the 6.12.0 milestone Aug 7, 2023
@Ocramius Ocramius merged commit 77c68f6 into Roave:6.12.x Aug 7, 2023
23 checks passed
@staabm staabm deleted the traits branch August 7, 2023 13:54
@Ocramius
Copy link
Member

Ocramius commented Aug 7, 2023

Thanks @staabm!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants