-
Bug
-
Resolution: Fixed
-
Minor
-
3.11.10, 4.0.4, 4.1
-
MOODLE_311_STABLE, MOODLE_400_STABLE, MOODLE_401_STABLE
-
MOODLE_311_STABLE, MOODLE_39_STABLE, MOODLE_400_STABLE
-
While it may sound rare, @coversDefaultClass xxxx does not indicate any coverage at all.
It's only an alias / shortcut to avoid having to write xxxx in all the individual @covers in a file (that can be really useful when the class is really long.
Source: https://phpunit.readthedocs.io/en/9.5/annotations.html#coversdefaultclass
So, using @coversDefaultClass xxxx is not enough to tell PHPUnit about coverage. The only annotation that does that is @covers (and @coversNothing, but it doesn't matter here.
In core, we have a bunch of "alone / orphaned" @coversDefaultClass cases, not having any @covers annotation specified. This is the current list in master:
$ ag '@coversDefaultClass' -l | xargs ag -vl '@covers |@coversNothing '
|
course/format/tests/output/local/state/state_test.php
|
admin/tool/admin_presets/tests/event/preset_reverted_test.php
|
admin/tool/admin_presets/tests/event/preset_deleted_test.php
|
admin/tool/admin_presets/tests/event/preset_previewed_test.php
|
admin/tool/admin_presets/tests/event/preset_downloaded_test.php
|
admin/tool/admin_presets/tests/event/preset_loaded_test.php
|
admin/tool/admin_presets/tests/event/preset_exported_test.php
|
admin/tool/admin_presets/tests/event/preset_imported_test.php
|
admin/tool/admin_presets/tests/event/presets_listed_test.php
|
lib/tests/content/export/exporters/course_exporter_test.php
|
lib/tests/content/export/zipwriter_test.php
|
lib/tests/content/export/exportable_items/exportable_stored_file_test.php
|
lib/tests/content/export/exportable_items/exportable_textarea_test.php
|
lib/tests/content/export/exportable_items/exportable_filearea_test.php
|
lib/table/tests/local/filter/filter_test.php
|
files/tests/local/archive_writer/zip_writer_test.php
|
files/tests/archive_writer_test.php
|
This issue is about to fix them by:
1) When it's in a method (incorrect), change it to @covers.
2) When it's in a class, consider if it really helps and add specific @covers ::method to every unit test, or just replace it by a simple @covers at class level.
3) Ideally, add this to some checker, so it doesn't happen again. Note that moodle-cs is already checking for methods without any (class or method) coverage information, so it will cry for new cases. Maybe that's enough.
Ciao