From d011564222dbfe7347c55957dc67ca47235b6cba Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Thu, 14 Aug 2025 15:28:12 +0100 Subject: [PATCH 1/3] MDL-86311 phpunit: update default configuration to fail on warnings. This restores pre-PHPUnit 10 behaviour, and ensures that warnings emitted by PHP during test execution will cause the test to fail. --- .upgradenotes/MDL-86311-2025081418402045.yml | 13 +++++++++++++ phpunit.xml.dist | 2 ++ 2 files changed, 15 insertions(+) create mode 100644 .upgradenotes/MDL-86311-2025081418402045.yml diff --git a/.upgradenotes/MDL-86311-2025081418402045.yml b/.upgradenotes/MDL-86311-2025081418402045.yml new file mode 100644 index 00000000000..3b86b7cea70 --- /dev/null +++ b/.upgradenotes/MDL-86311-2025081418402045.yml @@ -0,0 +1,13 @@ +issueNumber: MDL-86311 +notes: + core: + - message: >- + The default PHPUnit configuration now enables the following properties, + ensuring PHP warnings will cause test failures (restoring pre-PHPUnit + version 10 behaviour): + + + * `failOnDeprecation` + + * `failOnWarning` + type: changed diff --git a/phpunit.xml.dist b/phpunit.xml.dist index f0ecc67bd16..90b9dea5f03 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -6,6 +6,8 @@ processIsolation="false" backupGlobals="false" cacheResult="false" + failOnDeprecation="true" + failOnWarning="true" stopOnError="false" stopOnFailure="false" stopOnIncomplete="false" From 4c844801bbd3850b120f2b40a7ef9db8ac08f6b7 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Thu, 14 Aug 2025 19:42:51 +0100 Subject: [PATCH 2/3] MDL-86311 question: fixes for PHPUnit related warnings/notices. * Correct component generator name; * Add missing required object properties; * Assert expected debugging messages --- .../type/multianswer/tests/question_type_test.php | 2 ++ public/question/type/multichoice/tests/restore_test.php | 9 ++++++++- public/question/type/numerical/tests/restore_test.php | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/public/question/type/multianswer/tests/question_type_test.php b/public/question/type/multianswer/tests/question_type_test.php index b7e33f99d06..b184fc1e946 100644 --- a/public/question/type/multianswer/tests/question_type_test.php +++ b/public/question/type/multianswer/tests/question_type_test.php @@ -447,6 +447,7 @@ final class question_type_test extends \advanced_testcase { $this->resetAfterTest(true); $this->setAdminUser(); + /** @var \core_question_generator $generator */ $generator = $this->getDataGenerator()->get_plugin_generator('core_question'); $cat = $generator->create_question_category([]); $question = $generator->create_question('multianswer', 'twosubq', ['category' => $cat->id]); @@ -465,6 +466,7 @@ final class question_type_test extends \advanced_testcase { $editedquestion = test_question_maker::get_question_data('multianswer', 'twosubq'); $editedquestion->id = $question->id; $editedquestion->category = $cat->id; + $editedquestion->context = \context_helper::instance_by_id($cat->contextid); $editedsubq1 = test_question_maker::get_question_form_data('multichoice', 'one_of_four'); $editedsubq1->id = $originalsubq1->id; $editedsubq1->qtype = 'multichoice'; diff --git a/public/question/type/multichoice/tests/restore_test.php b/public/question/type/multichoice/tests/restore_test.php index 3092ab1d24e..ae377de8348 100644 --- a/public/question/type/multichoice/tests/restore_test.php +++ b/public/question/type/multichoice/tests/restore_test.php @@ -48,7 +48,7 @@ final class restore_test extends \advanced_testcase { $cat = $questiongenerator->create_question_category(['contextid' => $context->id]); // Create a quiz containing a multichoice question from the qbank. - $quiz = $this->getDataGenerator()->get_plugin_generator('quiz')->create_instance(['course' => $course1->id]); + $quiz = $this->getDataGenerator()->get_plugin_generator('mod_quiz')->create_instance(['course' => $course1->id]); $question = $questiongenerator->create_question('multichoice', 'one_of_four', ['category' => $cat->id]); quiz_add_quiz_question($question->id, $quiz); @@ -72,6 +72,13 @@ final class restore_test extends \advanced_testcase { $rc->execute_plan(); $rc->destroy(); + // Executing the precheck and plan will each emit debugging related to missing options. + $this->assertDebuggingCalledCount( + 2, + array_fill(0, 2, "Question ID {$question->id} was missing an options record. Using default."), + array_fill(0, 2, DEBUG_DEVELOPER), + ); + // Both quizzes should refer to the same original question. $quizzes = get_fast_modinfo($course1->id)->get_instances_of('quiz'); $this->assertCount(2, $quizzes); diff --git a/public/question/type/numerical/tests/restore_test.php b/public/question/type/numerical/tests/restore_test.php index 57aa65fd647..9367c1d3a76 100644 --- a/public/question/type/numerical/tests/restore_test.php +++ b/public/question/type/numerical/tests/restore_test.php @@ -48,7 +48,7 @@ final class restore_test extends \advanced_testcase { $cat = $questiongenerator->create_question_category(['contextid' => $context->id]); // Create a quiz containing a multichoice question from the qbank. - $quiz = $this->getDataGenerator()->get_plugin_generator('quiz')->create_instance(['course' => $course1->id]); + $quiz = $this->getDataGenerator()->get_plugin_generator('mod_quiz')->create_instance(['course' => $course1->id]); $question = $questiongenerator->create_question('numerical', 'pi', ['category' => $cat->id]); quiz_add_quiz_question($question->id, $quiz); From 76e481b9ceb13380b9adba7dd41e6a9356bb28c1 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Thu, 14 Aug 2025 18:17:20 +0100 Subject: [PATCH 3/3] MDL-86311 core: ensure component is normalised prior to comparison. --- public/lib/classes/router/util.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/public/lib/classes/router/util.php b/public/lib/classes/router/util.php index eada7c17d8b..1c2011feeda 100644 --- a/public/lib/classes/router/util.php +++ b/public/lib/classes/router/util.php @@ -293,14 +293,11 @@ class util { public static function normalise_component_path( string $component, ): string { - if ($component === 'core') { - return $component; - } [$type, $subsystem] = \core\component::normalize_component($component); - if ($type === 'core') { + if ($type === 'core' && $subsystem !== null) { return str_replace('core_', '', $subsystem); } - return $component ?? ''; + return $component; } }