@@ -186,16 +186,20 @@ private function resolveClassAttributes(Class_ $class): array
186186 $ coversGroups = [];
187187 $ methodGroups = [];
188188 $ hasCoversDefault = false ;
189+ $ coversDefaultClass = '' ;
189190 $ phpDocInfo = $ this ->phpDocInfoFactory ->createFromNode ($ class );
190191 if ($ phpDocInfo instanceof PhpDocInfo) {
191192 $ coversDefaultGroups = $ this ->handleCoversDefaultClass ($ phpDocInfo );
192193 // If there is a ::coversDefaultClass, @covers ::function will refer to class methods, otherwise it will refer to global functions.
193194 $ hasCoversDefault = $ coversDefaultGroups !== [];
195+ $ coversDefaultClass = $ hasCoversDefault ? $ this ->getName (
196+ $ coversDefaultGroups [0 ]->attrs [0 ]->args [0 ]->value
197+ ) : null ;
194198 $ coversGroups = $ this ->handleCovers ($ phpDocInfo , $ hasCoversDefault );
195199 }
196200
197201 foreach ($ class ->getMethods () as $ classMethod ) {
198- $ methodGroups = [...$ methodGroups , ...$ this ->resolveMethodAttributes ($ classMethod , $ hasCoversDefault )];
202+ $ methodGroups = [...$ methodGroups , ...$ this ->resolveMethodAttributes ($ classMethod , $ coversDefaultClass )];
199203 }
200204
201205 return [...$ coversDefaultGroups , ...$ coversGroups , ...$ methodGroups ];
@@ -260,8 +264,9 @@ private function handleCovers(PhpDocInfo $phpDocInfo, bool $hasCoversDefault): a
260264 /**
261265 * @return array<string, AttributeGroup>
262266 */
263- private function resolveMethodAttributes (ClassMethod $ classMethod , bool $ hasCoversDefault ): array
267+ private function resolveMethodAttributes (ClassMethod $ classMethod , ? string $ coversDefaultClass ): array
264268 {
269+ $ hasCoversDefault = $ coversDefaultClass !== null ;
265270 $ phpDocInfo = $ this ->phpDocInfoFactory ->createFromNode ($ classMethod );
266271 if (! $ phpDocInfo instanceof PhpDocInfo) {
267272 return [];
@@ -275,16 +280,20 @@ private function resolveMethodAttributes(ClassMethod $classMethod, bool $hasCove
275280 }
276281
277282 $ covers = $ desiredTagValueNode ->value ->value ;
278- if (str_starts_with ($ covers , '\\' ) || (! $ hasCoversDefault && str_starts_with ($ covers , ':: ' ))) {
279- $ attributeGroup = $ this ->createAttributeGroup ($ covers );
283+ if (! str_starts_with ($ covers , '\\' ) && ! str_starts_with ($ covers , ':: ' )) {
284+ continue ;
285+ }
280286
281- // phpunit 10 may not fully support attribute
282- if (! $ attributeGroup instanceof AttributeGroup) {
283- continue ;
284- }
287+ if ($ hasCoversDefault && str_starts_with ($ covers , ':: ' )) {
288+ $ covers = $ coversDefaultClass . $ covers ;
289+ }
285290
286- $ attributeGroups [$ covers ] = $ attributeGroup ;
291+ $ attributeGroup = $ this ->createAttributeGroup ($ covers );
292+ if (! $ attributeGroup instanceof AttributeGroup) {
293+ continue ;
287294 }
295+
296+ $ attributeGroups [$ covers ] = $ attributeGroup ;
288297 }
289298
290299 return $ attributeGroups ;
0 commit comments