@@ -281,6 +281,19 @@ private function parseDataProviderAttribute(Attribute $attribute, ClassReflectio
281281 */
282282 private function yieldDataProviderAttributes ($ node , ClassReflection $ classReflection ): iterable
283283 {
284+ if ($ node instanceof ReflectionMethod) {
285+ foreach ($ node ->getAttributes ('PHPUnit\Framework\Attributes\DataProvider ' ) as $ attr ) {
286+ $ args = $ attr ->getArguments ();
287+ if (count ($ args ) !== 1 ) {
288+ continue ;
289+ }
290+
291+ yield [$ classReflection , $ args [0 ], $ node ->getStartLine ()];
292+ }
293+
294+ return ;
295+ }
296+
284297 foreach ($ node ->attrGroups as $ attrGroup ) {
285298 foreach ($ attrGroup ->attrs as $ attr ) {
286299 $ dataProviderMethod = null ;
@@ -306,26 +319,28 @@ private function yieldDataProviderAttributes($node, ClassReflection $classReflec
306319 private function yieldDataProviderAnnotations ($ node , Scope $ scope , ClassReflection $ classReflection ): iterable
307320 {
308321 $ docComment = $ node ->getDocComment ();
309- if ($ docComment !== null ) {
310- $ methodPhpDoc = $ this ->fileTypeMapper ->getResolvedPhpDoc (
311- $ scope ->getFile (),
312- $ classReflection ->getName (),
313- $ scope ->isInTrait () ? $ scope ->getTraitReflection ()->getName () : null ,
314- $ node ->name ->toString (),
315- $ docComment ->getText (),
316- );
317- foreach ($ this ->getDataProviderAnnotations ($ methodPhpDoc ) as $ annotation ) {
318- $ dataProviderValue = $ this ->getDataProviderAnnotationValue ($ annotation );
319- if ($ dataProviderValue === null ) {
320- // Missing value is already handled in NoMissingSpaceInMethodAnnotationRule
321- continue ;
322- }
323-
324- $ dataProviderMethod = $ this ->parseDataProviderAnnotationValue ($ scope , $ dataProviderValue );
325- $ dataProviderMethod [] = $ node ->getStartLine ();
322+ if ($ docComment === null || $ docComment === false ) {
323+ return ;
324+ }
326325
327- yield $ dataProviderValue => $ dataProviderMethod ;
326+ $ methodPhpDoc = $ this ->fileTypeMapper ->getResolvedPhpDoc (
327+ $ scope ->getFile (),
328+ $ classReflection ->getName (),
329+ $ scope ->isInTrait () ? $ scope ->getTraitReflection ()->getName () : null ,
330+ $ node instanceof ClassMethod ? $ node ->name ->toString () : $ node ->getName (),
331+ $ node instanceof ClassMethod ? $ docComment ->getText () : $ docComment ,
332+ );
333+ foreach ($ this ->getDataProviderAnnotations ($ methodPhpDoc ) as $ annotation ) {
334+ $ dataProviderValue = $ this ->getDataProviderAnnotationValue ($ annotation );
335+ if ($ dataProviderValue === null ) {
336+ // Missing value is already handled in NoMissingSpaceInMethodAnnotationRule
337+ continue ;
328338 }
339+
340+ $ dataProviderMethod = $ this ->parseDataProviderAnnotationValue ($ scope , $ dataProviderValue );
341+ $ dataProviderMethod [] = $ node ->getStartLine ();
342+
343+ yield $ dataProviderValue => $ dataProviderMethod ;
329344 }
330345 }
331346
0 commit comments