diff --git a/src/Hooks/TestCaseHandler.php b/src/Hooks/TestCaseHandler.php index c051d19..12be2c1 100644 --- a/src/Hooks/TestCaseHandler.php +++ b/src/Hooks/TestCaseHandler.php @@ -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> */ diff --git a/tests/acceptance/TestCase.feature b/tests/acceptance/TestCase.feature index fc673c4..f9d5882 100644 --- a/tests/acceptance/TestCase.feature +++ b/tests/acceptance/TestCase.feature @@ -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> */ + public function provider1() { + yield [1]; + } + + /** @return iterable> */ + 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> */ + public function provider1() { + yield [1]; + } + + /** @return iterable> */ + 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 """