Skip to content
Merged
Show file tree
Hide file tree
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
15 changes: 10 additions & 5 deletions src/Hooks/TestCaseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -566,14 +566,19 @@ private static function attributeValue(ClassMethod $method, Aliases $aliases, st
$aliases,
),
);
$matchingAttributes = array_merge(...array_values(array_map(
$attributesInGroupMatchingRequestedAttributeName,
$method->getAttrGroups(),
)));

foreach ($method->getAttrGroups() as $group) {
foreach ($attributesInGroupMatchingRequestedAttributeName($group) as $attribute) {
return $onlyStringLiteralExpressions($attribute);
}
if ($matchingAttributes === []) {
return null;
}

return null;
return array_merge(...array_values(array_map(
$onlyStringLiteralExpressions,
$matchingAttributes,
)));
}

/** @return array<string, array<int,string>> */
Expand Down
56 changes: 56 additions & 0 deletions tests/acceptance/TestCase.feature
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,62 @@ Feature: TestCase
When I run Psalm
Then I see no errors

Scenario: Multiple valid iterable @dataProvider are allowed, and all are used
Given I have the following code
"""
use PHPUnit\Framework\Attributes;

final class MyTestCase extends TestCase
{
/** @return iterable<int,array<int,int>> */
public function provider1() {
yield [1];
}

/** @return iterable<int,array<int,int>> */
public function provider2() {
yield [1];
}

/**
* @dataProvider provider1
* @dataProvider provider2
*/
public function testSomething(int $int): void {
$this->assertEquals(1, $int);
}
}
"""
When I run Psalm with dead code detection
Then I see no errors

Scenario: Multiple valid iterable #[DataProvider]s are allowed, and all are used
Given I have the following code
"""
use PHPUnit\Framework\Attributes;

final class MyTestCase extends TestCase
{
/** @return iterable<int,array<int,int>> */
public function provider1() {
yield [1];
}

/** @return iterable<int,array<int,int>> */
public function provider2() {
yield [1];
}

#[Attributes\DataProvider('provider1')]
#[Attributes\DataProvider('provider2')]
public function testSomething(int $int): void {
$this->assertEquals(1, $int);
}
}
"""
When I run Psalm with dead code detection
Then I see no errors

Scenario: Invalid generator data provider is reported
Given I have the following code
"""
Expand Down