phpstan-phpunit icon indicating copy to clipboard operation
phpstan-phpunit copied to clipboard

Validate coverage tags point to real classes

Open neclimdul opened this issue 2 years ago • 4 comments

Its easy to make typos or miss updating a covers tag during a refactor and this helps catch it earlier.

neclimdul avatar Feb 19 '22 05:02 neclimdul

re: 1. Looking steeping back through the code my memory is being refreshed. I wasn't able to do that because FileTypeMapper(and PhpDocNodeResolver) only know about phpdoc tags and the covers tags are only part of PHPUnit. I guess we could create a phpunit specific NodeResolver though. There are quite a few annotations and there might be other things someone wants to assert. It might be kind of a rabbit hole but let me know if you want me to take that approach.

https://phpunit.readthedocs.io/en/9.5/annotations.html

neclimdul avatar Mar 22 '22 20:03 neclimdul

I wasn't able to do that because FileTypeMapper(and PhpDocNodeResolver) only know about phpdoc tags and the covers tags are only part of PHPUnit

This is certainly possible, it's just that the @covers tag will be represented by this node instead of something nicer: https://github.com/phpstan/phpdoc-parser/blob/master/src/Ast/PhpDoc/GenericTagValueNode.php but you can definitely work with that.

ondrejmirtes avatar Mar 23 '22 16:03 ondrejmirtes

@neclimdul is this something you are interested in finishing or should i pick this up?

this was a custom rule we wrote into our previous static analysis tool that we lost since adopting phpstan and would love to see it completed

mad-briller avatar Jul 20 '22 20:07 mad-briller

@mad-briller still interested but might be a while before I can finish it so if you've got some time to bring it home that would be awesome.

neclimdul avatar Jul 20 '22 21:07 neclimdul

Superseded by https://github.com/phpstan/phpstan-phpunit/pull/137

ondrejmirtes avatar Oct 17 '22 13:10 ondrejmirtes