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

Conversation

lotyp
Copy link

@lotyp lotyp commented May 4, 2024

Adds support for PHPUnit #[Test] attribute

Closes: #144

Comment on lines +160 to +162
$attributes = $stmt_method->getAttrGroups();
foreach ($attributes as $attr_group) {
foreach ($attr_group->attrs as $attr) {
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.

@weirdan
Copy link
Member

weirdan commented May 4, 2024

Also please add the variant with #[Test] into this test case:

Scenario: Test method are never marked as unused
Given I have the following code
"""
class MyTestCase extends TestCase
{
/**
* @return void
*/
public function testSomething(int $int) {
$this->assertEquals(1, $int);
}
/**
* @return void
* @test
*/
public function somethingElse(int $int) {
$this->assertEquals(1, $int);
}
}
"""
When I run Psalm with dead code detection
Then I see no errors

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

Successfully merging this pull request may close these issues.

#[Test] Not Suppressing PossiblyUnusedMethod
2 participants