diff --git a/classes/external/score_get_course_scores.php b/classes/external/score_get_course_scores.php index 42d8483..f13fad6 100644 --- a/classes/external/score_get_course_scores.php +++ b/classes/external/score_get_course_scores.php @@ -8,12 +8,11 @@ use core_external\external_value; use invalid_parameter_exception; use local_adler\adler_score_helpers; +use local_adler\moodle_core; use moodle_exception; use restricted_context_exception; class score_get_course_scores extends external_api { - private static string $context_course = context_course::class; - public static function execute_parameters(): external_function_parameters { return new external_function_parameters( array( @@ -37,7 +36,7 @@ public static function execute($course_id): array { $course_id = $params['course_id']; // Permission check - $context = static::$context_course::instance($course_id); + $context = di::get(moodle_core::class)->context_course_instance($course_id); static::validate_context($context); // get cmids of all modules in course diff --git a/tests/external/score_get_course_scores_test.php b/tests/external/score_get_course_scores_test.php index b2b5abb..7aedf07 100644 --- a/tests/external/score_get_course_scores_test.php +++ b/tests/external/score_get_course_scores_test.php @@ -7,6 +7,7 @@ use core\di; use local_adler\adler_score_helpers; use local_adler\lib\adler_externallib_testcase; +use local_adler\moodle_core; use Mockery; use moodle_database; use ReflectionClass; @@ -38,12 +39,8 @@ public function test_execute($element_count) { // mock context $context_mock = Mockery::mock(context_module::class); - $context_mock->shouldReceive('instance')->andReturn($context_mock); - - $reflected_class = new ReflectionClass(score_get_course_scores::class); - $property = $reflected_class->getProperty('context_course'); - $property->setAccessible(true); - $property->setValue(null, $context_mock->mockery_getName()); + $moodle_core_mock = Mockery::mock(moodle_core::class); + $moodle_core_mock->shouldReceive('context_course_instance')->andReturn($context_mock); // mock validate_context $score_get_course_scores_mock = Mockery::mock(score_get_course_scores::class)->makePartial();