Skip to content

Commit

Permalink
MDL-82207 phpunit: fix various @Covers annotations (take#1)
Browse files Browse the repository at this point in the history
This fixes various (not all) wrong @Covers annotations that
are reported as warnings by PHPUnit when it's run with
code-coverage enabled.

When possible, the preferred solution is to change to
@Covers at class level, that is the recommended way.

If multiple classes are involved, then a mix of @coversDefaultClass
and @Covers at method level are used (always trying to use the
minimum needed patch).

This is the first of a series of issues created as sub-tasks
of MDL-82142.
  • Loading branch information
stronk7 committed Jun 24, 2024
1 parent ad7fc69 commit ad5fe71
Show file tree
Hide file tree
Showing 53 changed files with 75 additions and 128 deletions.
2 changes: 1 addition & 1 deletion admin/presets/tests/helper_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* @category test
* @copyright 2021 Sara Arjona ([email protected])
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @coversDefaultClass helper
* @coversDefaultClass \core_adminpresets\helper
*/
class helper_test extends \advanced_testcase {

Expand Down
2 changes: 1 addition & 1 deletion admin/roles/tests/reportbuilder/datasource/roles_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* Unit tests for roles datasource
*
* @package core_role
* @covers \core_role\reportbuilder\datasource\roles;
* @covers \core_role\reportbuilder\datasource\roles
* @copyright 2024 Paul Holden <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
Expand Down
3 changes: 2 additions & 1 deletion backup/moodle2/tests/restore_stepslib_date_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,8 @@ public function test_usercompletion_date_restore(): void {
/**
* Checking that the user completion of an activity relating to the view field does not change
* when doing a course restore.
* @covers ::backup_and_restore
* @covers \backup_userscompletion_structure_step
* @covers \restore_userscompletion_structure_step
*/
public function test_usercompletion_view_restore(): void {
global $DB;
Expand Down
4 changes: 2 additions & 2 deletions cache/tests/cache_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2230,7 +2230,7 @@ public function test_application_locking_before_write(): void {
/**
* Test that locking before write works when writing across multiple layers.
*
* @covers \cache_loader
* @covers \cache_application
* @return void
*/
public function test_application_locking_multiple_layers(): void {
Expand Down Expand Up @@ -2310,7 +2310,7 @@ public function test_application_locking_multiple_layers(): void {
/**
* Tests that locking fails correctly when either layer of a 2-layer cache has a lock already.
*
* @covers \cache_loader
* @covers \cache_application
*/
public function test_application_locking_multiple_layers_failures(): void {

Expand Down
2 changes: 1 addition & 1 deletion calendar/tests/container_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
* @package core_calendar
* @copyright 2017 Cameron Ball <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \core_calendar\local\event\container
*/
class container_test extends \advanced_testcase {

Expand Down Expand Up @@ -370,7 +371,6 @@ public function test_event_factory_with_completion_related_event(): void {

/**
* Checks that completed activities events do not show.
* @covers \core_calendar\local\event::init
*/
public function test_event_factory_with_completed_module_related_event(): void {
global $CFG, $DB;
Expand Down
9 changes: 6 additions & 3 deletions cohort/tests/lib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -693,8 +693,11 @@ public function test_cohort_get_available_cohorts(): void {
/**
* Test that all get functions return custom fields data.
*
* @covers \cohort_get_cohort, \cohort_get_cohorts, \cohort_get_all_cohorts
* @covers \cohort_get_available_cohorts, \cohort_get_user_cohorts
* @covers ::cohort_get_cohort
* @covers ::cohort_get_cohorts
* @covers ::cohort_get_all_cohorts
* @covers ::cohort_get_available_cohorts
* @covers ::cohort_get_user_cohorts
*/
public function test_get_functions_return_custom_fields(): void {
$this->resetAfterTest();
Expand Down Expand Up @@ -912,7 +915,7 @@ public function test_cohort_update_theme_cohort(): void {
/**
* Test that lib function returns custom field data for a cohorts.
*
* @covers \cohort_get_custom_fields_data
* @covers ::cohort_get_custom_fields_data
*/
public function test_cohort_get_custom_fields_data(): void {
$this->resetAfterTest();
Expand Down
11 changes: 0 additions & 11 deletions communication/tests/api_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,6 @@ public function test_delete_room(): void {

/**
* Test the adding and removing of members from room.
*
* @covers ::add_members_to_room
* @covers ::remove_members_from_room
*/
public function test_adding_and_removing_of_room_membership(): void {
$course = $this->get_course();
Expand Down Expand Up @@ -311,8 +308,6 @@ public function test_adding_and_removing_of_room_membership(): void {

/**
* Test the update of room membership with the change user role.
*
* @covers ::update_room_membership
*/
public function test_update_room_membership_on_user_role_change(): void {
global $DB;
Expand Down Expand Up @@ -340,8 +335,6 @@ public function test_update_room_membership_on_user_role_change(): void {

/**
* Test sync_provider method for the sync of available provider.
*
* @covers ::sync_provider
*/
public function test_sync_provider(): void {
// Generate the data.
Expand All @@ -358,8 +351,6 @@ public function test_sync_provider(): void {

/**
* Test the removal of all members from the room.
*
* @covers ::remove_all_members_from_room
*/
public function test_remove_all_members_from_room(): void {
$course = $this->get_course();
Expand All @@ -382,8 +373,6 @@ public function test_remove_all_members_from_room(): void {

/**
* Test the configuration of room changes as well as the membership with the change of provider.
*
* @covers ::configure_room_and_membership_by_provider
*/
public function test_configure_room_and_membership_by_provider(): void {
global $DB;
Expand Down
4 changes: 3 additions & 1 deletion communication/tests/processor_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ public function setUp(): void {
*
* @covers ::create_instance
* @covers ::get_id
* @covers ::get_instance
* @covers ::get_context
* @covers ::get_context_id
* @covers ::get_provider
* @covers ::get_room_name
*/
public function test_create_instance(): void {
Expand Down
2 changes: 1 addition & 1 deletion completion/tests/api_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* @category test
* @copyright 2017 Mark Nelson <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \core_completion\api
*/
class api_test extends \advanced_testcase {

Expand Down Expand Up @@ -292,7 +293,6 @@ public function test_mark_course_completions_activity_criteria(): void {

/**
* Test for mark_course_completions_activity_criteria() with different completionpassgrade settings.
* @covers ::mark_course_completions_activity_criteria
*/
public function test_mark_course_completions_activity_criteria_completion_states(): void {
global $DB, $CFG;
Expand Down
3 changes: 1 addition & 2 deletions completion/tests/progress_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* @category test
* @copyright 2017 Mark Nelson <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \core_completion\progress
*/
class progress_test extends \advanced_testcase {

Expand Down Expand Up @@ -123,8 +124,6 @@ public function test_course_progress_percentage_with_activities_and_course(): vo

/**
* Tests that the course progress percentage is returned correctly for various grade to pass settings
*
* @covers \core_completion\progress::get_course_progress_percentage.
*/
public function test_course_progress_percentage_completion_state(): void {
global $DB, $CFG;
Expand Down
2 changes: 1 addition & 1 deletion contentbank/tests/contenttype_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ public function test_get_download_url(): void {
/**
* Tests pluginfile result.
*
* @covers ::pluginfile
* @covers ::__construct
*/
public function test_pluginfile(): void {
$this->resetAfterTest();
Expand Down
1 change: 0 additions & 1 deletion course/format/tests/base_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public static function setupBeforeClass(): void {
* Tests the save and load functionality.
*
* @author Jason den Dulk
* @covers \core_courseformat
*/
public function test_courseformat_saveandload(): void {
$this->resetAfterTest();
Expand Down
2 changes: 1 addition & 1 deletion course/format/tests/formatactions_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @package core_courseformat
* @copyright 2023 Ferran Recio <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @coversDefaultClass \core_courseformat\base
* @coversDefaultClass \core_courseformat\formatactions
*/
class formatactions_test extends \advanced_testcase {

Expand Down
2 changes: 1 addition & 1 deletion course/format/tests/local/baseactions_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* @package core_courseformat
* @copyright 2023 Ferran Recio <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @coversDefaultClass \core_courseformat\base
* @coversDefaultClass \core_courseformat\local\baseactions
*/
class baseactions_test extends \advanced_testcase {
/**
Expand Down
2 changes: 1 addition & 1 deletion course/format/tests/local/cmactions_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* @package core_courseformat
* @copyright 2024 Ferran Recio <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @coversDefaultClass \core_courseformat\cmactions
* @coversDefaultClass \core_courseformat\local\cmactions
*/
final class cmactions_test extends \advanced_testcase {
/**
Expand Down
2 changes: 1 addition & 1 deletion course/format/tests/local/sectionactions_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* @package core_courseformat
* @copyright 2023 Ferran Recio <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @coversDefaultClass \core_courseformat\sectionactions
* @coversDefaultClass \core_courseformat\local\sectionactions
*/
class sectionactions_test extends \advanced_testcase {
/**
Expand Down
4 changes: 3 additions & 1 deletion course/format/tests/output/local/state/state_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ public static function setupBeforeClass(): void {
* Test the behaviour of state::export_for_template().
*
* @dataProvider state_provider
* @covers \core_courseformat\output\local\state
* @covers \core_courseformat\output\local\state\course
* @covers \core_courseformat\output\local\state\section
* @covers \core_courseformat\output\local\state\cm
*
* @param string $format The course format of the course where the method will be executed.
*/
Expand Down
4 changes: 3 additions & 1 deletion course/tests/backup/restore_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,9 @@ public function test_restore_course_startdate_in_existing_course_without_permiss
* Tests course restore with editor in course format.
*
* @author Matthew Hilton
* @covers \core_courseformat
* @covers \core_courseformat\base
* @covers \backup_course_structure_step
* @covers \restore_course_structure_step
*/
public function test_restore_editor_courseformat(): void {
$this->resetAfterTest();
Expand Down
3 changes: 1 addition & 2 deletions course/tests/course_delete_modules_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* @subpackage course
* @copyright 2021 Tomo Tsuyuki <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \core_course\task\course_delete_modules
*/
namespace core_course;

Expand Down Expand Up @@ -68,8 +69,6 @@ public function test_delete_module_execution(): void {

/**
* Test with failed and successful cms
*
* @covers ::course_delete_modules
*/
public function test_delete_module_exception(): void {
global $DB;
Expand Down
4 changes: 2 additions & 2 deletions enrol/tests/enrollib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -1739,7 +1739,7 @@ public function test_enrol_selfenrol_available(): void {
/**
* Test the behaviour of validate_enrol_plugin_data().
*
* @covers ::validate_enrol_plugin_data
* @covers \enrol_plugin::validate_enrol_plugin_data
*/
public function test_validate_enrol_plugin_data(): void {
$this->resetAfterTest();
Expand All @@ -1761,7 +1761,7 @@ public function test_validate_enrol_plugin_data(): void {
/**
* Test the behaviour of update_enrol_plugin_data().
*
* @covers ::update_enrol_plugin_data
* @covers \enrol_plugin::update_enrol_plugin_data
*/
public function test_update_enrol_plugin_data(): void {
global $DB;
Expand Down
3 changes: 1 addition & 2 deletions grade/tests/external/get_feedback_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@
* @copyright 2023 Kevin Percy <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 4.2
* @covers \core_grades\external\get_feedback
*/
class get_feedback_test extends \externallib_advanced_testcase {

/**
* Test get_feedback.
*
* @covers ::get_feedback
* @dataProvider get_feedback_provider
* @param string|null $feedback The feedback text added for the grade item.
* @param array $expected The expected feedback data.
Expand Down Expand Up @@ -103,7 +103,6 @@ public function get_feedback_provider(): array {
/**
* Test get_feedback with invalid requests.
*
* @covers ::get_feedback
* @dataProvider get_feedback_invalid_request_provider
* @param string $loggeduserrole The role of the logged user.
* @param bool $feedbacknotincourse Whether to request a feedback for a grade item which is not a part of the course.
Expand Down
1 change: 0 additions & 1 deletion grade/tests/external/get_grade_tree_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class get_grade_tree_test extends \externallib_advanced_testcase {
/**
* Test the return value of the external function.
*
* @covers ::execute
* @return void
*/
public function test_execute(): void {
Expand Down
4 changes: 2 additions & 2 deletions group/tests/lib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ public function test_groups_get_members_by_role(): void {
/**
* Tests set_groups_messaging
*
* @covers \core_group::set_groups_messaging
* @covers ::set_groups_messaging
*/
public function test_set_groups_messaging(): void {
$this->resetAfterTest();
Expand Down Expand Up @@ -923,7 +923,7 @@ public function test_set_groups_messaging(): void {
/**
* Tests set group messaging where it doesn't exist
*
* @covers \core_group::set_groups_messaging
* @covers ::set_groups_messaging
*/
public function test_set_groups_messaging_doesnt_exist(): void {
$this->resetAfterTest();
Expand Down
5 changes: 1 addition & 4 deletions h5p/tests/file_storage_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
* @copyright 2019 Victor Deniz <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @runTestsInSeparateProcesses
* @covers \core_h5p\file_storage
*/
class file_storage_test extends \advanced_testcase {

Expand Down Expand Up @@ -847,8 +848,6 @@ public function test_removeContentFile(): void {

/**
* Test H5P custom styles generation.
*
* @covers ::generate_custom_styles
*/
public function test_generate_custom_styles(): void {
\set_config('h5pcustomcss', '.debug { color: #fab; }', 'core_h5p');
Expand Down Expand Up @@ -895,8 +894,6 @@ public function test_generate_custom_styles(): void {

/**
* Test H5P custom styles retrieval.
*
* @covers ::get_custom_styles
*/
public function test_get_custom_styles(): void {
global $CFG;
Expand Down
2 changes: 0 additions & 2 deletions h5p/tests/framework_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -1099,8 +1099,6 @@ public function test_updateContent(): void {

/**
* Test the behaviour of updateContent() with metadata.
*
* @covers ::updateContent
*/
public function test_updateContent_withmetadata(): void {
global $DB;
Expand Down
1 change: 0 additions & 1 deletion h5p/tests/helper_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ public function test_save_h5p_existing_libraries(): void {
* Test the behaviour of save_h5p() when the H5P file contains metadata.
*
* @runInSeparateProcess
* @covers ::save_h5p
*/
public function test_save_h5p_metadata(): void {
global $DB;
Expand Down
Loading

0 comments on commit ad5fe71

Please sign in to comment.