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

feat: support for php 8 style Test attribute #145

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/Hooks/TestCaseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,18 @@ public static function afterStatementAnalysis(AfterClassLikeAnalysisEvent $event
$specials = self::getSpecials($stmt_method);

$is_test = 0 === strpos($method_name_lc, 'test') || isset($specials['test']);

// New logic to also recognize the #[Test] attribute as a marker for test methods
$attributes = $stmt_method->getAttrGroups();
foreach ($attributes as $attr_group) {
foreach ($attr_group->attrs as $attr) {
Comment on lines +160 to +162
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a $method_storage->attributes property that contains the attributes as Psalm understood them. For example, it (should) include attributes from stub files. Thus it's better to use that rather than low-level PHPParser stuff.

if ($attr->name->toString() === 'Test') {
$is_test = true;
break 2;
}
}
}

if (!$is_test) {
continue; // skip non-test methods
}
Expand Down
Loading