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 17, 2024
1 parent 2bf886f commit 98c4ca3
Show file tree
Hide file tree
Showing 26 changed files with 39 additions and 76 deletions.
6 changes: 0 additions & 6 deletions lib/dml/tests/dml_read_slave_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,6 @@ public function test_read_excluded_tables(): void {
* so the latency parameter is applied properly.
*
* @return void
* @covers ::can_use_readonly
* @covers ::commit_delegated_transaction
*/
public function test_transaction(): void {
$DB = $this->new_db(true);
Expand Down Expand Up @@ -339,8 +337,6 @@ public function test_transaction(): void {
* so the latency parameter is applied properly.
*
* @return void
* @covers ::can_use_readonly
* @covers ::query_end
*/
public function test_long_update(): void {
$DB = $this->new_db(true);
Expand Down Expand Up @@ -382,8 +378,6 @@ public function test_long_update(): void {
* when the latency parameter is applied properly.
*
* @return void
* @covers ::can_use_readonly
* @covers ::commit_delegated_transaction
*/
public function test_transaction_with_events(): void {
$this->with_global_db(function () {
Expand Down
4 changes: 0 additions & 4 deletions lib/dml/tests/dml_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -530,8 +530,6 @@ public function test_add_sql_debugging(): void {

/**
* Test the database debugging as SQL comment in anon class
*
* @covers ::add_sql_debugging
*/
public function test_sql_debugging_anon_class(): void {
global $CFG;
Expand Down Expand Up @@ -3924,8 +3922,6 @@ public function test_sql_ceil(): void {

/**
* Test DML libraries sql_cast_to_char method
*
* @covers ::sql_cast_to_char
*/
public function test_cast_to_char(): void {
$DB = $this->tdb;
Expand Down
3 changes: 0 additions & 3 deletions lib/dml/tests/pgsql_native_moodle_database_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,6 @@ public function new_connection($ssl) {

/**
* Test SSL connection.
*
* @return void
* @covers ::raw_connect
*/
public function test_ssl_connection(): void {
$pgconnerr = 'pg_connect(): Unable to connect to PostgreSQL server:';
Expand Down
6 changes: 3 additions & 3 deletions lib/external/tests/external_api_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ public function test_get_context_from_params(): void {
/**
* Test \core_external\external_api::get_context()_from_params parameter validation.
*
* @covers \core_external\external_api::get_context
* @covers \core_external\external_api::get_context_from_params
*/
public function test_get_context_params(): void {
global $USER;
Expand All @@ -345,7 +345,7 @@ public function test_get_context_params(): void {
/**
* Test \core_external\external_api::get_context()_from_params parameter validation.
*
* @covers \core_external\external_api::get_context
* @covers \core_external\external_api::get_context_from_params
*/
public function test_get_context_params2(): void {
global $USER;
Expand All @@ -357,7 +357,7 @@ public function test_get_context_params2(): void {

/**
* Test \core_external\external_api::get_context()_from_params parameter validation.
* @covers \core_external\external_api::get_context
* @covers \core_external\external_api::get_context_from_params
*/
public function test_get_context_params3(): void {
global $USER;
Expand Down
2 changes: 1 addition & 1 deletion lib/testing/tests/testing_generator_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* @category phpunit
* @copyright 2012 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \core\testing_data_generator
* @covers \testing_data_generator
*/
class testing_generator_test extends \advanced_testcase {
public function test_get_plugin_generator_good_case(): void {
Expand Down
2 changes: 1 addition & 1 deletion lib/tests/accesslib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -5260,7 +5260,7 @@ public function test_require_all_capabilities(): void {
/**
* Test get_navigation_filter_context.
*
* @covers ::get_navigation_filter_context
* @covers \core\context_helper::get_navigation_filter_context
*/
public function test_get_navigation_filter_context(): void {
$this->resetAfterTest();
Expand Down
3 changes: 1 addition & 2 deletions lib/tests/authlib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* @category test
* @copyright 2012 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \auth_plugin_base
*/
class authlib_test extends \advanced_testcase {
public function test_lockout(): void {
Expand Down Expand Up @@ -507,7 +508,6 @@ public function test_signup_validate_data_same_email(): void {

/**
* Test the find_cli_user method
* @covers ::find_cli_user
*/
public function test_find_cli_user(): void {
global $CFG, $USER;
Expand Down Expand Up @@ -540,7 +540,6 @@ public function test_find_cli_user(): void {

/**
* Test the get_enabled_auth_plugin_classes method
* @covers ::get_enabled_auth_plugin_classes
*/
public function test_get_enabled_auth_plugin_classes(): void {
global $CFG;
Expand Down
2 changes: 1 addition & 1 deletion lib/tests/check_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* @category check
* @copyright 2020 Brendan Heywood <brendan@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \core\check
* @covers \core\check\check
*/
class check_test extends \advanced_testcase {

Expand Down
4 changes: 2 additions & 2 deletions lib/tests/configonlylib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function test_min_get_slash_argument(): void {
/**
* Test the min_get_minimum_version function.
*
* @covers ::min_get_minimum_version
* @covers ::min_get_minimum_revision
*/
public function test_min_get_minimum_version(): void {
// This is fairly hard to write a test for, but we can at least check that it returns a number
Expand All @@ -161,7 +161,7 @@ public function test_min_get_minimum_version(): void {
/**
* Test the min_get_maximum_version function.
*
* @covers ::min_get_maximum_version
* @covers ::min_get_maximum_revision
*/
public function test_min_get_maximum_version(): void {
// The maximum version should be set to a time in the near future.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* @category test
* @copyright 2020 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \core\content\exportable_items\exportable_filearea
* @covers \core\content\export\exportable_items\exportable_filearea
*/
class exportable_filearea_test extends advanced_testcase {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* @category test
* @copyright 2020 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \core\content\exportable_items\exportable_stored_file
* @covers \core\content\export\exportable_items\exportable_stored_file
*/
class exportable_stored_file_test extends advanced_testcase {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* @category test
* @copyright 2020 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \core\content\exportable_items\exportable_textarea
* @covers \core\content\export\exportable_items\exportable_textarea
*/
class exportable_textarea_test extends advanced_testcase {

Expand Down
20 changes: 10 additions & 10 deletions lib/tests/core_renderer_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*/
final class core_renderer_test extends \advanced_testcase {
/**
* @covers \core\hook\before_standard_top_of_body_html_generation
* @covers \core\hook\output\before_standard_top_of_body_html_generation
*/
public function test_standard_top_of_body_html(): void {
$page = new moodle_page();
Expand All @@ -42,7 +42,7 @@ public function test_standard_top_of_body_html(): void {
}

/**
* @covers \core\hook\before_standard_top_of_body_html_generation
* @covers \core\hook\output\before_standard_top_of_body_html_generation
*/
public function test_before_standard_top_of_body_html_generation_hooked(): void {
require_once(__DIR__ . '/fixtures/core_renderer/before_standard_top_of_body_html_generation_callbacks.php');
Expand All @@ -63,7 +63,7 @@ public function test_before_standard_top_of_body_html_generation_hooked(): void
}

/**
* @covers \core\hook\before_footer_html_generation
* @covers \core\hook\output\before_footer_html_generation
*/
public function test_before_footer_html_generation(): void {
$this->resetAfterTest();
Expand All @@ -79,7 +79,7 @@ public function test_before_footer_html_generation(): void {
}

/**
* @covers \core\hook\before_footer_html_generation
* @covers \core\hook\output\before_footer_html_generation
*/
public function test_before_footer_html_generation_hooked(): void {
$this->resetAfterTest();
Expand All @@ -104,7 +104,7 @@ public function test_before_footer_html_generation_hooked(): void {
}

/**
* @covers \core\hook\before_standard_footer_html_generation
* @covers \core\hook\output\before_standard_footer_html_generation
*/
public function before_standard_footer_html_generation(): void {
$page = new moodle_page();
Expand All @@ -116,7 +116,7 @@ public function before_standard_footer_html_generation(): void {
}

/**
* @covers \core\hook\before_standard_footer_html_generation
* @covers \core\hook\output\before_standard_footer_html_generation
*/
public function test_before_standard_footer_html_generation_hooked(): void {
require_once(__DIR__ . '/fixtures/core_renderer/before_standard_footer_html_generation_callbacks.php');
Expand All @@ -137,7 +137,7 @@ public function test_before_standard_footer_html_generation_hooked(): void {
}

/**
* @covers \core\hook\after_standard_main_region_html_generation
* @covers \core\hook\output\after_standard_main_region_html_generation
*/
public function test_after_standard_main_region_html_generation(): void {
$page = new moodle_page();
Expand All @@ -149,7 +149,7 @@ public function test_after_standard_main_region_html_generation(): void {
}

/**
* @covers \core\hook\after_standard_main_region_html_generation
* @covers \core\hook\output\after_standard_main_region_html_generation
*/
public function test_after_standard_main_region_html_generation_hooked(): void {
require_once(__DIR__ . '/fixtures/core_renderer/after_standard_main_region_html_generation_callbacks.php');
Expand All @@ -170,7 +170,7 @@ public function test_after_standard_main_region_html_generation_hooked(): void {
}

/**
* @covers \core\hook\before_html_attributes
* @covers \core\hook\output\before_html_attributes
*/
public function test_htmlattributes(): void {
$page = new moodle_page();
Expand All @@ -182,7 +182,7 @@ public function test_htmlattributes(): void {
}

/**
* @covers \core\hook\before_html_attributes
* @covers \core\hook\output\before_html_attributes
*/
public function test_htmlattributes_hooked(): void {
require_once(__DIR__ . '/fixtures/core_renderer/htmlattributes_callbacks.php');
Expand Down
3 changes: 0 additions & 3 deletions lib/tests/cron_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ public function setUp(): void {

/**
* Test the setup_user function.
*
* @covers ::setup_user
* @covers ::reset_user_cache
*/
public function test_setup_user(): void {
// This function uses the $GLOBALS super global. Disable the VariableNameLowerCase sniff for this function.
Expand Down
10 changes: 4 additions & 6 deletions lib/tests/oauth2_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* @package core
* @copyright 2017 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
* @coversDefaultClass \core\oauth2\api
* @covers \core\oauth2\api
*/
class oauth2_test extends \advanced_testcase {

Expand Down Expand Up @@ -256,8 +256,6 @@ public function test_issuer_alloweddomains(): void {
* Test endpoints creation for issuers.
* @dataProvider create_endpoints_for_standard_issuer_provider
*
* @covers ::create_endpoints_for_standard_issuer
*
* @param string $type Issuer type to create.
* @param string|null $discoveryurl Expected discovery URL or null if this endpoint doesn't exist.
* @param bool $hasmappingfields True if it's expected the issuer to create has mapping fields.
Expand Down Expand Up @@ -495,7 +493,7 @@ public function create_custom_profile_fields(): array {
* Test getting the list of internal fields.
*
* @dataProvider create_custom_profile_fields
* @covers ::get_internalfield_list
* @covers \core\oauth2\user_field_mapping::get_internalfield_list
* @param array $given Categories and profile fields.
* @param array $expected Expected value.
*/
Expand All @@ -522,7 +520,7 @@ public function test_get_internalfield_list(array $given, array $expected): void
* Test getting the list of internal fields with flat array.
*
* @dataProvider create_custom_profile_fields
* @covers ::get_internalfields
* @covers \core\oauth2\user_field_mapping::get_internalfields
* @param array $given Categories and profile fields.
* @param array $expected Expected value.
*/
Expand All @@ -542,7 +540,7 @@ public function test_get_internalfields(array $given, array $expected): void {
/**
* Test getting the list of empty external/custom profile fields.
*
* @covers ::get_internalfields
* @covers \core\oauth2\user_field_mapping::get_internalfields
*/
public function test_get_empty_internalfield_list(): void {

Expand Down
10 changes: 5 additions & 5 deletions lib/tests/output/choicelist_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class choicelist_test extends advanced_testcase {
/**
* Test for a choice without options.
*
* @covers ::_construct
* @covers ::__construct
* @covers ::add_option
* @covers ::export_for_template
*/
Expand All @@ -57,7 +57,7 @@ public function test_empty_export(): void {
/**
* Test for a choice with basic options.
*
* @covers ::_construct
* @covers ::__construct
* @covers ::add_option
* @covers ::export_for_template
*/
Expand All @@ -82,7 +82,7 @@ public function test_basic_export(): void {
/**
* Test for a choice with extras options definition.
*
* @covers ::_construct
* @covers ::__construct
* @covers ::add_option
* @covers ::set_option_extras
* @covers ::export_for_template
Expand Down Expand Up @@ -126,7 +126,7 @@ public function test_option_defintion_export(): void {
/**
* Test for a choice with option selected.
*
* @covers ::_construct
* @covers ::__construct
* @covers ::add_option
* @covers ::set_selected_value
* @covers ::get_selected_value
Expand Down Expand Up @@ -196,7 +196,7 @@ private function validate_option(
/**
* Test for a choice with option selected.
*
* @covers ::_construct
* @covers ::__construct
* @covers ::add_option
* @covers ::set_selected_value
* @covers ::get_selected_value
Expand Down
3 changes: 2 additions & 1 deletion lib/tests/pdflib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* @package core
* @copyright 2021 Brendan Heywood (brendan@catalyst-au.net)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \pdf
*/
class pdflib_test extends \advanced_testcase {

Expand Down Expand Up @@ -70,7 +71,7 @@ public function test_qrcode(): void {
/**
* Test get_export_fontlist function.
*
* @covers ::get_export_fontlist
* @covers \pdf::get_export_fontlist
*
* @return void
*/
Expand Down
Loading

0 comments on commit 98c4ca3

Please sign in to comment.