moodlehq / moodle-cs

Moodle Coding Style
https://github.com/moodlehq/moodle-cs
GNU General Public License v3.0
18 stars 16 forks source link

Unit test "final" rule wrongly triggers for abstract classes #180

Closed PhMemmel closed 3 months ago

PhMemmel commented 3 months ago

In a plugin a wrote a bunch of tests which are pretty similar. So I have a abstract class from which my test classes inherit. Unfortunately phpcs currently triggers a warning for this abstract class (moodle.PHPUnit.TestClassesFinal.UnitTestClassesFinal), because it's not final. However, I'm struggeling to declare an abstract class as final. I feel in this case there should be no warning.

andrewnicols commented 3 months ago

Hi @PhMemmel ,

If you are writing a testcase from which you wish to extend your own test classes, you must name it as *_testcase and declare it abstract. All test classes must have names ending *_test and be declared final.

The final and abstract classes are mutually exclusive and do not make sense.

Basically, rename your base class as a testcase and declare it as abstract.

PhMemmel commented 3 months ago

Ah, understood the structure. Thank you very much for the quick response. Your solution works perfectly.