MDL-81456 core: Use DI for all hook access

Using DI for all hook access means that it becomes significantly easier
to mock hooks and callbacks for unit testing without fundamentally
altering the structure of the code purely for the purposes of unit
testing.
This commit is contained in:
Andrew Nicols
2024-04-08 09:35:41 +08:00
parent 26649f5750
commit 2b49ad42f5
17 changed files with 89 additions and 42 deletions
+6 -1
View File
@@ -23,6 +23,11 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use core\{
di,
hook,
};
require_once(__DIR__.'/../../testing/classes/util.php');
require_once(__DIR__ . "/coverage_info.php");
@@ -105,7 +110,7 @@ class phpunit_util extends testing_util {
global $DB, $CFG, $USER, $SITE, $COURSE, $PAGE, $OUTPUT, $SESSION, $FULLME, $FILTERLIB_PRIVATE;
// Stop all hook redirections.
\core\hook\manager::get_instance()->phpunit_stop_redirections();
di::get(hook\manager::class)->phpunit_stop_redirections();
// Reset the hook manager instance.
\core\hook\manager::phpunit_reset_instance();