Skip to content

Commit

Permalink
MDL-81522 phpunit: Add missing void return type to all tests #2
Browse files Browse the repository at this point in the history
This commit includes more changes, all them also adding the :void
return type to unit tests missing them.

The difference is that all these changes, while also detected
perfectly by the moodle.PHPUnit.TestReturnType sniff, were not
auto-fixed (like the previous commit ones), because all them
do include some "return" statement and, for safety, we don't
fix them.

All the cases have been visually inspected and confirmed that
the existing "return" statements always belong to anon
functions within the test body and not the test own return statement.
  • Loading branch information
stronk7 committed May 30, 2024
1 parent 4929f3b commit fa4de08
Show file tree
Hide file tree
Showing 72 changed files with 153 additions and 153 deletions.
8 changes: 4 additions & 4 deletions admin/tool/dataprivacy/tests/expired_contexts_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ public function test_process_user_context_with_override_unexpired_role(): void {
/**
* Ensure that a module context previously flagged as approved is removed with appropriate unexpiredroles kept.
*/
public function test_process_course_context_with_override_unexpired_role() {
public function test_process_course_context_with_override_unexpired_role(): void {
global $DB;
$this->resetAfterTest();

Expand Down Expand Up @@ -955,7 +955,7 @@ public function test_process_course_context_with_override_unexpired_role() {
/**
* Ensure that a module context previously flagged as approved is removed with appropriate expiredroles kept.
*/
public function test_process_course_context_with_override_expired_role() {
public function test_process_course_context_with_override_expired_role(): void {
global $DB;
$this->resetAfterTest();

Expand Down Expand Up @@ -1043,7 +1043,7 @@ public function test_process_course_context_with_override_expired_role() {
/**
* Ensure that a module context previously flagged as approved is removed with appropriate expiredroles kept.
*/
public function test_process_course_context_with_user_in_both_lists() {
public function test_process_course_context_with_user_in_both_lists(): void {
global $DB;
$this->resetAfterTest();

Expand Down Expand Up @@ -1132,7 +1132,7 @@ public function test_process_course_context_with_user_in_both_lists() {
/**
* Ensure that a module context previously flagged as approved is removed with appropriate expiredroles kept.
*/
public function test_process_course_context_with_user_in_both_lists_expired() {
public function test_process_course_context_with_user_in_both_lists_expired(): void {
global $DB;
$this->resetAfterTest();

Expand Down
2 changes: 1 addition & 1 deletion admin/tool/dataprivacy/tests/manager_observer_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class manager_observer_test extends data_privacy_testcase {
/**
* Ensure that when users are configured as DPO, they are sent an message upon failure.
*/
public function test_handle_component_failure() {
public function test_handle_component_failure(): void {
$this->resetAfterTest();

// Create another user who is not a DPO.
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/generator/tests/maketestcourse_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class maketestcourse_test extends \advanced_testcase {
/**
* Creates a small test course and checks all the components have been put in place.
*/
public function test_make_xs_course() {
public function test_make_xs_course(): void {
global $DB;

$this->resetAfterTest();
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/policy/tests/api_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public function test_policy_sortorder(): void {
/**
* Test that list of policies can be filtered by audience
*/
public function test_list_policies_audience() {
public function test_list_policies_audience(): void {
$this->resetAfterTest();
$this->setAdminUser();

Expand Down
2 changes: 1 addition & 1 deletion cache/tests/administration_helper_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static function tearDownAfterClass(): void {
/**
* Test the numerous summaries the helper can produce.
*/
public function test_get_summaries() {
public function test_get_summaries(): void {
// First the preparation.
$config = cache_config_writer::instance();
$this->assertTrue($config->add_store_instance('summariesstore', 'file'));
Expand Down
10 changes: 5 additions & 5 deletions calendar/tests/event_factory_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function test_create_instance(
/**
* Test invalid callback exception.
*/
public function test_invalid_action_callback() {
public function test_invalid_action_callback(): void {
$this->resetAfterTest(true);
$this->setAdminUser();
$event = $this->create_event();
Expand Down Expand Up @@ -135,7 +135,7 @@ function () {
/**
* Test invalid callback exception.
*/
public function test_invalid_visibility_callback() {
public function test_invalid_visibility_callback(): void {
$this->resetAfterTest(true);
$this->setAdminUser();
$event = $this->create_event();
Expand Down Expand Up @@ -185,7 +185,7 @@ function () {
/**
* Test invalid callback exception.
*/
public function test_invalid_bail_callback() {
public function test_invalid_bail_callback(): void {
$this->resetAfterTest(true);
$this->setAdminUser();
$event = $this->create_event();
Expand Down Expand Up @@ -235,7 +235,7 @@ function () {
/**
* Test the factory's course cache.
*/
public function test_course_cache() {
public function test_course_cache(): void {
$this->resetAfterTest(true);
$this->setAdminUser();
$course = self::getDataGenerator()->create_course();
Expand Down Expand Up @@ -288,7 +288,7 @@ function () {
/**
* Test the factory's module cache.
*/
public function test_module_cache() {
public function test_module_cache(): void {
$this->resetAfterTest(true);
$this->setAdminUser();
$course = self::getDataGenerator()->create_course();
Expand Down
12 changes: 6 additions & 6 deletions calendar/tests/event_vault_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public function test_get_action_events_by_timesort_between_time_after_event(): v
* provided timesort values and the last seen event can be provided to
* get paginated results.
*/
public function test_get_action_events_by_timesort_between_time_skip_even_records() {
public function test_get_action_events_by_timesort_between_time_skip_even_records(): void {
$this->resetAfterTest(true);
$this->setAdminuser();

Expand Down Expand Up @@ -247,7 +247,7 @@ public function test_get_action_events_by_timesort_between_time_skip_even_record
* number of events requested has been satisfied. In this case the first
* five events are rejected so it should require two database requests.
*/
public function test_get_action_events_by_timesort_between_time_skip_first_records() {
public function test_get_action_events_by_timesort_between_time_skip_first_records(): void {
$this->resetAfterTest(true);
$this->setAdminuser();

Expand Down Expand Up @@ -423,7 +423,7 @@ public function test_get_action_events_by_timesort_non_consecutive_ids(): void {
* - A user in group B should see only the B override
* - A user in both A and B should see both
*/
public function test_get_action_events_by_timesort_with_identical_group_override_priorities() {
public function test_get_action_events_by_timesort_with_identical_group_override_priorities(): void {
$this->resetAfterTest();
$this->setAdminuser();

Expand Down Expand Up @@ -804,7 +804,7 @@ public function test_get_action_events_by_course_between_time_after_event(): voi
* provided timesort values and the last seen event can be provided to
* get paginated results.
*/
public function test_get_action_events_by_course_between_time_skip_even_records() {
public function test_get_action_events_by_course_between_time_skip_even_records(): void {
$user = $this->getDataGenerator()->create_user();
$course1 = $this->getDataGenerator()->create_course();
$course2 = $this->getDataGenerator()->create_course();
Expand Down Expand Up @@ -870,7 +870,7 @@ public function test_get_action_events_by_course_between_time_skip_even_records(
* number of events requested has been satisfied. In this case the first
* five events are rejected so it should require two database requests.
*/
public function test_get_action_events_by_course_between_time_skip_first_records() {
public function test_get_action_events_by_course_between_time_skip_first_records(): void {
$user = $this->getDataGenerator()->create_user();
$course1 = $this->getDataGenerator()->create_course();
$course2 = $this->getDataGenerator()->create_course();
Expand Down Expand Up @@ -1080,7 +1080,7 @@ public function test_get_action_events_by_course_non_consecutive_ids(): void {
* - A user in group B should see only the B override
* - A user in both A and B should see both
*/
public function test_get_action_events_by_course_with_identical_group_override_priorities() {
public function test_get_action_events_by_course_with_identical_group_override_priorities(): void {
$this->resetAfterTest();
$this->setAdminuser();

Expand Down
4 changes: 2 additions & 2 deletions calendar/tests/externallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -1425,7 +1425,7 @@ public function test_get_calendar_action_events_by_course_with_search(): void {
* Test that get_action_events_by_courses will return a list of events for each
* course you provided as long as the user is enrolled in the course.
*/
public function test_get_action_events_by_courses() {
public function test_get_action_events_by_courses(): void {
$user = $this->getDataGenerator()->create_user();
$course1 = $this->getDataGenerator()->create_course();
$course2 = $this->getDataGenerator()->create_course();
Expand Down Expand Up @@ -1558,7 +1558,7 @@ public function test_get_action_events_by_courses() {
/**
* Test get_action_events_by_courses with search feature
*/
public function test_get_action_events_by_courses_with_search() {
public function test_get_action_events_by_courses_with_search(): void {
// Generate data.
$user = $this->getDataGenerator()->create_user();
$course1 = $this->getDataGenerator()->create_course();
Expand Down
8 changes: 4 additions & 4 deletions calendar/tests/std_proxy_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function setUp(): void {
* @param string $member Object member to retrieve.
* @param mixed $expected Expected value of member.
*/
public function test_proxy($id, $member, $expected) {
public function test_proxy($id, $member, $expected): void {
$proxy = new std_proxy($id, function($id) {
return $this->objects[$id];
});
Expand All @@ -70,7 +70,7 @@ public function test_proxy($id, $member, $expected) {
* @param string $member Object member to retrieve.
* @param mixed $storedvalue Value as would be stored externally.
*/
public function test_base_values($id, $member, $storedvalue) {
public function test_base_values($id, $member, $storedvalue): void {
$proxy = new std_proxy(
$id,
function($id) {
Expand All @@ -89,7 +89,7 @@ function($id) {
* @dataProvider get_set_testcases
* @param int $id ID of the object being proxied.
*/
public function test_get_invalid_member($id) {
public function test_get_invalid_member($id): void {
$proxy = new std_proxy($id, function($id) {
return $this->objects[$id];
});
Expand All @@ -104,7 +104,7 @@ public function test_get_invalid_member($id) {
* @dataProvider get_set_testcases
* @param int $id Object ID.
*/
public function test_get_proxied_instance($id) {
public function test_get_proxied_instance($id): void {
$proxy = new std_proxy($id, function($id) {
return $this->objects[$id];
});
Expand Down
2 changes: 1 addition & 1 deletion competency/tests/privacy/provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -1999,7 +1999,7 @@ public function test_export_data_for_user_with_related_learning_plans(): void {
$this->assert_exported_comments(['Hi.'], $data->comments);
}

public function test_export_data_for_user_with_related_competencies() {
public function test_export_data_for_user_with_related_competencies(): void {
$path = [
get_string('competencies', 'core_competency'),
get_string('privacy:path:relatedtome', 'core_competency'),
Expand Down
2 changes: 1 addition & 1 deletion course/tests/backup/restore_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ public function test_restore_course_info_in_new_course(): void {
$this->assertEquals($startdate, $c2->startdate);
}

public function test_restore_course_with_users() {
public function test_restore_course_with_users(): void {
global $DB;
$this->resetAfterTest();
$this->setAdminUser();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class caching_content_item_readonly_repository_test extends \advanced_testcase {
/**
* Test verifying that content items are cached and returned from the cache in subsequent same-request calls.
*/
public function test_find_all_for_course() {
public function test_find_all_for_course(): void {
$this->resetAfterTest();
global $DB;

Expand Down
2 changes: 1 addition & 1 deletion course/tests/category_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ public function test_course_contacts(): void {
$CFG->coursecontact = $oldcoursecontact;
}

public function test_course_contacts_with_duplicates() {
public function test_course_contacts_with_duplicates(): void {
global $DB, $CFG;

set_config('coursecontactduplicates', true);
Expand Down
2 changes: 1 addition & 1 deletion course/tests/content_item_readonly_repository_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function test_find_all_for_course_hidden_module(): void {
/**
* Test confirming that all content items can be fetched, even those which require certain caps when in a course.
*/
public function test_find_all() {
public function test_find_all(): void {
$this->resetAfterTest();

global $DB, $CFG;
Expand Down
14 changes: 7 additions & 7 deletions course/tests/courselib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -4582,7 +4582,7 @@ public function get_course_classify_courses_for_timeline_test_cases() {
* @param array $coursesdata Courses to create
* @param array $expected Expected test results.
*/
public function test_course_classify_courses_for_timeline($coursesdata, $expected) {
public function test_course_classify_courses_for_timeline($coursesdata, $expected): void {
$this->resetAfterTest();
$generator = $this->getDataGenerator();

Expand Down Expand Up @@ -4723,7 +4723,7 @@ public function test_course_get_enrolled_courses_for_logged_in_user(
$offset,
$expecteddbqueries,
$expectedresult
) {
): void {
global $DB;

$this->resetAfterTest();
Expand Down Expand Up @@ -4908,7 +4908,7 @@ public function get_course_filter_courses_by_timeline_classification_test_cases(
/**
* Test the course_get_enrolled_courses_for_logged_in_user_from_search function.
*/
public function test_course_get_enrolled_courses_for_logged_in_user_from_search() {
public function test_course_get_enrolled_courses_for_logged_in_user_from_search(): void {
global $DB;

// Set up.
Expand Down Expand Up @@ -5021,7 +5021,7 @@ public function test_course_filter_courses_by_timeline_classification(
$offset,
$expectedcourses,
$expectedprocessedcount
) {
): void {
$this->resetAfterTest();
$generator = $this->getDataGenerator();

Expand Down Expand Up @@ -5242,7 +5242,7 @@ public function test_course_filter_courses_by_customfield(
$offset,
$expectedcourses,
$expectedprocessedcount
) {
): void {
$this->resetAfterTest();
$generator = $this->getDataGenerator();

Expand Down Expand Up @@ -5487,7 +5487,7 @@ public function test_course_filter_courses_by_timeline_classification_with_hidde
$expectedcourses,
$expectedprocessedcount,
$hiddencourse
) {
): void {
$this->resetAfterTest();
$generator = $this->getDataGenerator();
$student = $generator->create_user();
Expand Down Expand Up @@ -6983,7 +6983,7 @@ public function test_course_get_course_dates_for_user_ids(
$enrolmentmethods,
$enrolled,
$expected
) {
): void {
global $DB;
$this->resetAfterTest();

Expand Down
8 changes: 4 additions & 4 deletions course/tests/externallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -3747,7 +3747,7 @@ public function test_get_enrolled_courses_by_timeline_classification(
$expectednextoffset,
$expectedexception = null,
$searchvalue = null
) {
): void {
$this->resetAfterTest();
$generator = $this->getDataGenerator();

Expand Down Expand Up @@ -3979,7 +3979,7 @@ public function test_get_enrolled_users_by_cmid(): void {
/**
* Verify that content items can be added to user favourites.
*/
public function test_add_content_item_to_user_favourites() {
public function test_add_content_item_to_user_favourites(): void {
$this->resetAfterTest();

$course = $this->getDataGenerator()->create_course();
Expand Down Expand Up @@ -4017,7 +4017,7 @@ public function test_add_content_item_to_user_favourites() {
/**
* Verify that content items can be removed from user favourites.
*/
public function test_remove_content_item_from_user_favourites() {
public function test_remove_content_item_from_user_favourites(): void {
$this->resetAfterTest();

$course = $this->getDataGenerator()->create_course();
Expand Down Expand Up @@ -4057,7 +4057,7 @@ public function test_remove_content_item_from_user_favourites() {
/**
* Test the web service returning course content items for inclusion in activity choosers, etc.
*/
public function test_get_course_content_items() {
public function test_get_course_content_items(): void {
$this->resetAfterTest();

$course = self::getDataGenerator()->create_course();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ protected function generate_published_resources() {
*
* @covers ::find_all_for_user
*/
public function test_find_all_for_user() {
public function test_find_all_for_user(): void {
$this->resetAfterTest();
[$user, $user2, $user3, $course, $course2, $mod, $mod2, $mod3, $mod4] = $this->generate_published_resources();

Expand Down Expand Up @@ -131,7 +131,7 @@ public function test_find_all_for_user() {
*
* @covers ::find_all_by_ids_for_user
*/
public function test_find_all_by_ids_for_user() {
public function test_find_all_by_ids_for_user(): void {
$this->resetAfterTest();
[$user, $user2, $user3, $course, $course2, $mod, $mod2, $mod3, $mod4, $coursetool, $tool, $tool2, $tool3, $tool4] =
$this->generate_published_resources();
Expand Down
Loading

0 comments on commit fa4de08

Please sign in to comment.