MDL-81522 phpunit: Add missing void return type to all tests

While this change is not 100% required now, it's good habit
and we are checking for it since Moodle 4.4.

All the changes in this commit have been applied automatically
using the moodle.PHPUnit.TestReturnType sniff and are, exclusively
adding the ": void" return types when missing.
This commit is contained in:
Eloy Lafuente (stronk7)
2024-06-11 12:18:04 +02:00
parent db07c09afc
commit 1093256560
1360 changed files with 9928 additions and 9928 deletions
+57 -57
View File
@@ -117,7 +117,7 @@ class questionlib_test extends \advanced_testcase {
$this->assertEquals($numberofquestions, count($questionsid));
}
public function test_question_reorder_qtypes() {
public function test_question_reorder_qtypes(): void {
$this->assertEquals(
array(0 => 't2', 1 => 't1', 2 => 't3'),
question_reorder_qtypes(array('t1' => '', 't2' => '', 't3' => ''), 't1', +1));
@@ -135,7 +135,7 @@ class questionlib_test extends \advanced_testcase {
question_reorder_qtypes(array('t1' => '', 't2' => '', 't3' => ''), 'missing', +1));
}
public function test_match_grade_options() {
public function test_match_grade_options(): void {
$gradeoptions = question_bank::fraction_options_full();
$this->assertEquals(0.3333333, match_grade_options($gradeoptions, 0.3333333, 'error'));
@@ -155,7 +155,7 @@ class questionlib_test extends \advanced_testcase {
* This function tests that the functions responsible for moving questions to
* different contexts also updates the tag instances associated with the questions.
*/
public function test_altering_tag_instance_context() {
public function test_altering_tag_instance_context(): void {
global $CFG, $DB;
// Set to admin user.
@@ -278,7 +278,7 @@ class questionlib_test extends \advanced_testcase {
/**
* Test that deleting a question from the question bank works in the normal case.
*/
public function test_question_delete_question() {
public function test_question_delete_question(): void {
global $DB;
// Setup.
@@ -301,7 +301,7 @@ class questionlib_test extends \advanced_testcase {
/**
* Test that deleting a broken question from the question bank does not cause fatal errors.
*/
public function test_question_delete_question_broken_data() {
public function test_question_delete_question_broken_data(): void {
global $DB;
// Setup.
@@ -329,7 +329,7 @@ class questionlib_test extends \advanced_testcase {
/**
* Test deleting a broken question whose category refers to a missing context
*/
public function test_question_delete_question_missing_context() {
public function test_question_delete_question_missing_context(): void {
global $DB;
$coursecategory = $this->getDataGenerator()->create_category();
@@ -356,7 +356,7 @@ class questionlib_test extends \advanced_testcase {
/**
* This function tests the question_category_delete_safe function.
*/
public function test_question_category_delete_safe() {
public function test_question_category_delete_safe(): void {
global $DB;
$this->resetAfterTest(true);
$this->setAdminUser();
@@ -380,7 +380,7 @@ class questionlib_test extends \advanced_testcase {
/**
* This function tests the question_delete_activity function.
*/
public function test_question_delete_activity() {
public function test_question_delete_activity(): void {
global $DB;
$this->resetAfterTest(true);
$this->setAdminUser();
@@ -403,7 +403,7 @@ class questionlib_test extends \advanced_testcase {
/**
* This function tests the question_delete_context function.
*/
public function test_question_delete_context() {
public function test_question_delete_context(): void {
global $DB;
$this->resetAfterTest(true);
$this->setAdminUser();
@@ -424,7 +424,7 @@ class questionlib_test extends \advanced_testcase {
/**
* This function tests the question_delete_course function.
*/
public function test_question_delete_course() {
public function test_question_delete_course(): void {
global $DB;
$this->resetAfterTest(true);
$this->setAdminUser();
@@ -445,7 +445,7 @@ class questionlib_test extends \advanced_testcase {
/**
* This function tests the question_delete_course_category function.
*/
public function test_question_delete_course_category() {
public function test_question_delete_course_category(): void {
global $DB;
$this->resetAfterTest(true);
$this->setAdminUser();
@@ -466,7 +466,7 @@ class questionlib_test extends \advanced_testcase {
/**
* This function tests the question_delete_course_category function when it is supposed to move question categories.
*/
public function test_question_delete_course_category_move_qcats() {
public function test_question_delete_course_category_move_qcats(): void {
global $DB;
$this->resetAfterTest(true);
$this->setAdminUser();
@@ -507,7 +507,7 @@ class questionlib_test extends \advanced_testcase {
* This function tests the question_save_from_deletion function when it is supposed to make a new category and
* move question categories to that new category.
*/
public function test_question_save_from_deletion() {
public function test_question_save_from_deletion(): void {
global $DB;
$this->resetAfterTest(true);
$this->setAdminUser();
@@ -530,7 +530,7 @@ class questionlib_test extends \advanced_testcase {
* This function tests the question_save_from_deletion function when it is supposed to make a new category and
* move question categories to that new category when quiz name is very long but less than 256 characters.
*/
public function test_question_save_from_deletion_quiz_with_long_name() {
public function test_question_save_from_deletion_quiz_with_long_name(): void {
global $DB;
$this->resetAfterTest(true);
$this->setAdminUser();
@@ -560,7 +560,7 @@ class questionlib_test extends \advanced_testcase {
/**
* get_question_options should add the category object to the given question.
*/
public function test_get_question_options_includes_category_object_single_question() {
public function test_get_question_options_includes_category_object_single_question(): void {
list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
$question = array_shift($questions);
@@ -573,7 +573,7 @@ class questionlib_test extends \advanced_testcase {
* get_question_options should add the category object to all of the questions in
* the given list.
*/
public function test_get_question_options_includes_category_object_multiple_questions() {
public function test_get_question_options_includes_category_object_multiple_questions(): void {
list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
get_question_options($questions);
@@ -586,7 +586,7 @@ class questionlib_test extends \advanced_testcase {
/**
* get_question_options includes the tags for all questions in the list.
*/
public function test_get_question_options_includes_question_tags() {
public function test_get_question_options_includes_question_tags(): void {
list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
$question1 = $questions[0];
$question2 = $questions[1];
@@ -623,7 +623,7 @@ class questionlib_test extends \advanced_testcase {
/**
* get_question_options includes the course tags for all questions in the list.
*/
public function test_get_question_options_includes_course_tags() {
public function test_get_question_options_includes_course_tags(): void {
list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
$question1 = $questions[0];
$question2 = $questions[1];
@@ -662,7 +662,7 @@ class questionlib_test extends \advanced_testcase {
* get_question_options only categorises a tag as a course tag if it is in a
* course context that is different from the question context.
*/
public function test_get_question_options_course_tags_in_course_question_context() {
public function test_get_question_options_course_tags_in_course_question_context(): void {
list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('course');
$question1 = $questions[0];
$question2 = $questions[1];
@@ -747,7 +747,7 @@ class questionlib_test extends \advanced_testcase {
* context id for any non-course context tag that isn't in the question category
* context.
*/
public function test_get_question_options_normalises_question_tags() {
public function test_get_question_options_normalises_question_tags(): void {
list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
$question1 = $questions[0];
$question2 = $questions[1];
@@ -789,7 +789,7 @@ class questionlib_test extends \advanced_testcase {
* get_question_options if the question is a course level question then tags
* in that context should not be consdered course tags, they are question tags.
*/
public function test_get_question_options_includes_course_context_question_tags() {
public function test_get_question_options_includes_course_context_question_tags(): void {
list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('course');
$question1 = $questions[0];
$question2 = $questions[1];
@@ -818,7 +818,7 @@ class questionlib_test extends \advanced_testcase {
/**
* get_question_options should return tags from all course contexts by default.
*/
public function test_get_question_options_includes_multiple_courses_tags() {
public function test_get_question_options_includes_multiple_courses_tags(): void {
list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
$question1 = $questions[0];
$question2 = $questions[1];
@@ -851,7 +851,7 @@ class questionlib_test extends \advanced_testcase {
/**
* get_question_options should filter the course tags by the given list of courses.
*/
public function test_get_question_options_includes_filter_course_tags() {
public function test_get_question_options_includes_filter_course_tags(): void {
list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
$question1 = $questions[0];
$question2 = $questions[1];
@@ -884,7 +884,7 @@ class questionlib_test extends \advanced_testcase {
* question tags contexts when they are moving down (from system to course
* category context).
*/
public function test_question_move_question_tags_to_new_context_system_to_course_cat_qtags() {
public function test_question_move_question_tags_to_new_context_system_to_course_cat_qtags(): void {
list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('system');
$question1 = $questions[0];
$question2 = $questions[1];
@@ -916,7 +916,7 @@ class questionlib_test extends \advanced_testcase {
* contexts when they are moving down (from system to course category context)
* but leave any tags in the course context where they are.
*/
public function test_question_move_question_tags_to_new_context_system_to_course_cat_qtags_and_course_tags() {
public function test_question_move_question_tags_to_new_context_system_to_course_cat_qtags_and_course_tags(): void {
list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('system');
$question1 = $questions[0];
$question2 = $questions[1];
@@ -956,7 +956,7 @@ class questionlib_test extends \advanced_testcase {
* question_move_question_tags_to_new_context should update all of the question
* contexts tags when they are moving up (from course category to system context).
*/
public function test_question_move_question_tags_to_new_context_course_cat_to_system_qtags() {
public function test_question_move_question_tags_to_new_context_course_cat_to_system_qtags(): void {
list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
$question1 = $questions[0];
$question2 = $questions[1];
@@ -988,7 +988,7 @@ class questionlib_test extends \advanced_testcase {
* tags contexts when they are moving up (from course category context to system
* context) but leave any tags in the course context where they are.
*/
public function test_question_move_question_tags_to_new_context_course_cat_to_system_qtags_and_course_tags() {
public function test_question_move_question_tags_to_new_context_course_cat_to_system_qtags_and_course_tags(): void {
list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
$question1 = $questions[0];
$question2 = $questions[1];
@@ -1028,7 +1028,7 @@ class questionlib_test extends \advanced_testcase {
* question_move_question_tags_to_new_context should merge all tags into the course
* context when moving down from course category context into course context.
*/
public function test_question_move_question_tags_to_new_context_course_cat_to_coures_qtags_and_course_tags() {
public function test_question_move_question_tags_to_new_context_course_cat_to_coures_qtags_and_course_tags(): void {
list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
$question1 = $questions[0];
$question2 = $questions[1];
@@ -1067,7 +1067,7 @@ class questionlib_test extends \advanced_testcase {
* from a course category into a course context because the other courses will
* no longer have access to the question.
*/
public function test_question_move_question_tags_to_new_context_remove_other_course_tags() {
public function test_question_move_question_tags_to_new_context_remove_other_course_tags(): void {
list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
// Create a sibling course.
$siblingcourse = $this->getDataGenerator()->create_course(['category' => $course->category]);
@@ -1116,7 +1116,7 @@ class questionlib_test extends \advanced_testcase {
* tags to be the course category context when moving the tags from a course
* context to a course category context.
*/
public function test_question_move_question_tags_to_new_context_course_to_course_cat() {
public function test_question_move_question_tags_to_new_context_course_to_course_cat(): void {
list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('course');
$question1 = $questions[0];
$question2 = $questions[1];
@@ -1149,7 +1149,7 @@ class questionlib_test extends \advanced_testcase {
* question tags contexts when they are moving down (from system to course
* category context).
*/
public function test_question_move_question_tags_to_new_context_orphaned_tag_contexts() {
public function test_question_move_question_tags_to_new_context_orphaned_tag_contexts(): void {
list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('system');
$question1 = $questions[0];
$question2 = $questions[1];
@@ -1191,7 +1191,7 @@ class questionlib_test extends \advanced_testcase {
* all question context tags and course tags (where the course is a parent of
* the activity) should move into the new context.
*/
public function test_question_move_question_tags_to_new_context_course_cat_to_activity_qtags_and_course_tags() {
public function test_question_move_question_tags_to_new_context_course_cat_to_activity_qtags_and_course_tags(): void {
list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
$question1 = $questions[0];
$question2 = $questions[1];
@@ -1230,7 +1230,7 @@ class questionlib_test extends \advanced_testcase {
* the activity) should move into the new context. Tags in course contexts
* that are not a parent of the activity context should be deleted.
*/
public function test_question_move_question_tags_to_new_context_course_cat_to_activity_orphaned_tags() {
public function test_question_move_question_tags_to_new_context_course_cat_to_activity_orphaned_tags(): void {
list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
$question1 = $questions[0];
$question2 = $questions[1];
@@ -1275,7 +1275,7 @@ class questionlib_test extends \advanced_testcase {
* When moving from a course context down into an activity context all of the
* course tags should move into the activity context.
*/
public function test_question_move_question_tags_to_new_context_course_to_activity_qtags() {
public function test_question_move_question_tags_to_new_context_course_to_activity_qtags(): void {
list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('course');
$question1 = $questions[0];
$question2 = $questions[1];
@@ -1305,7 +1305,7 @@ class questionlib_test extends \advanced_testcase {
* When moving from a course context down into an activity context all of the
* course tags should move into the activity context.
*/
public function test_question_move_question_tags_to_new_context_activity_to_course_qtags() {
public function test_question_move_question_tags_to_new_context_activity_to_course_qtags(): void {
list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions();
$question1 = $questions[0];
$question2 = $questions[1];
@@ -1340,7 +1340,7 @@ class questionlib_test extends \advanced_testcase {
* tags in course contexts that can no longer access the question should be
* deleted.
*/
public function test_question_move_question_tags_to_new_context_system_to_course_cat_with_orphaned_tags() {
public function test_question_move_question_tags_to_new_context_system_to_course_cat_with_orphaned_tags(): void {
list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('system');
$question1 = $questions[0];
$question2 = $questions[1];
@@ -1393,7 +1393,7 @@ class questionlib_test extends \advanced_testcase {
/**
* question_sort_tags() includes the tags for all questions in the list.
*/
public function test_question_sort_tags_includes_question_tags() {
public function test_question_sort_tags_includes_question_tags(): void {
list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
$question1 = $questions[0];
@@ -1431,7 +1431,7 @@ class questionlib_test extends \advanced_testcase {
/**
* question_sort_tags() includes course tags for all questions in the list.
*/
public function test_question_sort_tags_includes_question_course_tags() {
public function test_question_sort_tags_includes_question_course_tags(): void {
global $DB;
list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
@@ -1470,7 +1470,7 @@ class questionlib_test extends \advanced_testcase {
/**
* question_sort_tags() should return tags from all course contexts by default.
*/
public function test_question_sort_tags_includes_multiple_courses_tags() {
public function test_question_sort_tags_includes_multiple_courses_tags(): void {
global $DB;
list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
@@ -1505,7 +1505,7 @@ class questionlib_test extends \advanced_testcase {
/**
* question_sort_tags() should filter the course tags by the given list of courses.
*/
public function test_question_sort_tags_includes_filter_course_tags() {
public function test_question_sort_tags_includes_filter_course_tags(): void {
global $DB;
list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions('category');
@@ -1660,7 +1660,7 @@ class questionlib_test extends \advanced_testcase {
/**
* Tests that question_has_capability_on does not throw exception on broken questions.
*/
public function test_question_has_capability_on_broken_question() {
public function test_question_has_capability_on_broken_question(): void {
global $DB;
// Create the test data.
@@ -1698,7 +1698,7 @@ class questionlib_test extends \advanced_testcase {
* @param bool $isowner Whether the user to create the question should be the owner or not.
* @param bool $expect The expected result.
*/
public function test_question_has_capability_on_using_stdClass($capabilities, $capability, $isowner, $expect) {
public function test_question_has_capability_on_using_stdClass($capabilities, $capability, $isowner, $expect): void {
$this->resetAfterTest();
// Create the test data.
@@ -1742,7 +1742,7 @@ class questionlib_test extends \advanced_testcase {
* @param bool $isowner Whether the user to create the question should be the owner or not.
* @param bool $expect The expected result.
*/
public function test_question_has_capability_on_using_question_definition($capabilities, $capability, $isowner, $expect) {
public function test_question_has_capability_on_using_question_definition($capabilities, $capability, $isowner, $expect): void {
$this->resetAfterTest();
// Create the test data.
@@ -1789,7 +1789,7 @@ class questionlib_test extends \advanced_testcase {
* @param bool $isowner Whether the user to create the question should be the owner or not.
* @param bool $expect The expected result.
*/
public function test_question_has_capability_on_using_question_id($capabilities, $capability, $isowner, $expect) {
public function test_question_has_capability_on_using_question_id($capabilities, $capability, $isowner, $expect): void {
$this->resetAfterTest();
// Create the test data.
@@ -1836,7 +1836,7 @@ class questionlib_test extends \advanced_testcase {
* @param bool $isowner Whether the user to create the question should be the owner or not.
* @param bool $expect The expected result.
*/
public function test_question_has_capability_on_using_question_string_id($capabilities, $capability, $isowner, $expect) {
public function test_question_has_capability_on_using_question_string_id($capabilities, $capability, $isowner, $expect): void {
$this->resetAfterTest();
// Create the test data.
@@ -1883,7 +1883,7 @@ class questionlib_test extends \advanced_testcase {
* @param bool $isowner Whether the user to create the question should be the owner or not.
* @param bool $expect The expected result.
*/
public function test_question_has_capability_on_using_moved_question($capabilities, $capability, $isowner, $expect) {
public function test_question_has_capability_on_using_moved_question($capabilities, $capability, $isowner, $expect): void {
$this->resetAfterTest();
// Create the test data.
@@ -1940,7 +1940,7 @@ class questionlib_test extends \advanced_testcase {
* @param bool $isowner Whether the user to create the question should be the owner or not.
* @param bool $expect The expected result.
*/
public function test_question_has_capability_on_using_question($capabilities, $capability, $isowner, $expect) {
public function test_question_has_capability_on_using_question($capabilities, $capability, $isowner, $expect): void {
$this->resetAfterTest();
// Create the test data.
@@ -1979,7 +1979,7 @@ class questionlib_test extends \advanced_testcase {
/**
* Tests that question_has_capability_on throws an exception for wrong parameter types.
*/
public function test_question_has_capability_on_wrong_param_type() {
public function test_question_has_capability_on_wrong_param_type(): void {
// Create the test data.
$generator = $this->getDataGenerator();
/** @var \core_question_generator $questiongenerator */
@@ -2154,11 +2154,11 @@ class questionlib_test extends \advanced_testcase {
* @param string|null $oldidnumber value to pass to core_question_find_next_unused_idnumber.
* @param string|null $expectednewidnumber expected result.
*/
public function test_core_question_find_next_unused_idnumber(?string $oldidnumber, ?string $expectednewidnumber) {
public function test_core_question_find_next_unused_idnumber(?string $oldidnumber, ?string $expectednewidnumber): void {
$this->assertSame($expectednewidnumber, core_question_find_next_unused_idnumber($oldidnumber, 0));
}
public function test_core_question_find_next_unused_idnumber_skips_used() {
public function test_core_question_find_next_unused_idnumber_skips_used(): void {
$this->resetAfterTest();
/** @var core_question_generator $generator */
@@ -2179,7 +2179,7 @@ class questionlib_test extends \advanced_testcase {
*
* @covers ::question_move_questions_to_category
*/
public function test_question_move_questions_to_category() {
public function test_question_move_questions_to_category(): void {
$this->resetAfterTest();
// Create the test data.
@@ -2203,7 +2203,7 @@ class questionlib_test extends \advanced_testcase {
*
* @covers ::idnumber_exist_in_question_category
*/
public function test_idnumber_exist_in_question_category() {
public function test_idnumber_exist_in_question_category(): void {
global $DB;
$this->resetAfterTest();
@@ -2248,7 +2248,7 @@ class questionlib_test extends \advanced_testcase {
* @covers ::is_latest
*
*/
public function test_is_latest() {
public function test_is_latest(): void {
global $DB;
$this->resetAfterTest();
/** @var \core_question_generator $generator */
@@ -2267,7 +2267,7 @@ class questionlib_test extends \advanced_testcase {
*
* @covers ::delete_question_bank_entry
*/
public function test_delete_question_bank_entry() {
public function test_delete_question_bank_entry(): void {
global $DB;
$this->resetAfterTest();
// Setup.
@@ -2304,7 +2304,7 @@ class questionlib_test extends \advanced_testcase {
*
* @covers ::get_question_bank_entry
*/
public function test_get_question_bank_entry() {
public function test_get_question_bank_entry(): void {
global $DB;
$this->resetAfterTest();
// Setup.
@@ -2334,7 +2334,7 @@ class questionlib_test extends \advanced_testcase {
*
* @covers ::get_question_version
*/
public function test_get_question_version() {
public function test_get_question_version(): void {
global $DB;
$this->resetAfterTest();
// Setup.
@@ -2365,7 +2365,7 @@ class questionlib_test extends \advanced_testcase {
*
* @covers ::get_next_version
*/
public function test_get_next_version() {
public function test_get_next_version(): void {
global $DB;
$this->resetAfterTest();
// Setup.