phpunit icon indicating copy to clipboard operation
phpunit copied to clipboard

More generic matching for at covers annotation

Open designermonkey opened this issue 3 years ago • 1 comments

From my learnings of unit testing, the importance is placed on testing the unit of functionality, not individual classes.

With that in mind, I declare an interface and create a testable implementation of that interface. According to PHPUnit, I am to declare the @covers annotation set to that class, and for every class covered. Good so far.

In testing, implementing, and then refactoring my code, I break my implementation class out into smaller 'private' classes (like in Java) that will never be instantiated outside the scope of the covered class. PHPUnit currently requires that I add another @covers annotation for every class I refactor out.

Would it be simpler to declare wildcard patterns like:

@covers \My\Space\MyClass
@covers \My\Space\MyClass\*

The first is the class implementing the interface, the second is the namespace for those pseudo 'private' classes.


In an ideal world, I would love to be able to declare @covers \My\Space\MyClass and it be treated as a class and/or namespace to cover.

designermonkey avatar Mar 23 '22 17:03 designermonkey

No new annotations will be added, no existing annotations will be changed, see #4502 for details. That being said, I am open to the idea of adding metadata support for declaring that a class covers a namespace.

sebastianbergmann avatar Mar 23 '22 17:03 sebastianbergmann