diff --git a/question/tests/random_question_loader_test.php b/question/tests/random_question_loader_test.php index c0ca467f8c3..a34fdc6ca6f 100644 --- a/question/tests/random_question_loader_test.php +++ b/question/tests/random_question_loader_test.php @@ -374,16 +374,10 @@ class random_question_loader_testcase extends advanced_testcase { $loader = new \core_question\local\bank\random_question_loader(new qubaid_list([])); list($category, $questions) = $this->create_category_and_questions($numberofquestions); - // Sort the questions by id to match the ordering of the get_questions - // function. - usort($questions, function($a, $b) { - $aid = $a->id; - $bid = $b->id; - - if ($aid == $bid) { - return 0; - } - return $aid < $bid ? -1 : 1; + // Add questionid as key to find them easily later. + $questionsbyid = []; + array_walk($questions, function (&$value) use (&$questionsbyid) { + $questionsbyid[$value->id] = $value; }); for ($i = 0; $i < $numberofquestions; $i++) { @@ -397,7 +391,7 @@ class random_question_loader_testcase extends advanced_testcase { $this->assertCount($limit, $result); $actual = array_shift($result); - $expected = $questions[$i]; + $expected = $questionsbyid[$actual->id]; $this->assertEquals($expected->id, $actual->id); $offset++; }