From 102c3166be06d0e8257e0f0e87cec2deb51d2599 Mon Sep 17 00:00:00 2001 From: Markus Heck Date: Thu, 18 Jan 2024 00:38:09 +0100 Subject: [PATCH] fix tests --- tests/adler_score_test.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/adler_score_test.php b/tests/adler_score_test.php index 37385f0..84d499d 100644 --- a/tests/adler_score_test.php +++ b/tests/adler_score_test.php @@ -8,6 +8,8 @@ use local_adler\lib\local_adler_testcase; use local_adler\lib\static_mock_utilities_trait; use local_adler\local\exceptions\user_not_enrolled_exception; +use local_logging\logger; +use Mockery; use mod_h5pactivity\local\grader; use moodle_exception; use ReflectionClass; @@ -265,6 +267,14 @@ public function test_get_primitive_score($data) { completion_info_mock::set_returns('is_enabled', [$data['completion_enabled']]); completion_info_mock::set_returns('get_data', [(object)['completionstate' => $data['completion_state']]]); + // mock logger as it does not exist because constructor is not executed + $logger_mock = Mockery::mock(Logger::class); + // ignore all method calls on mock + $logger_mock->shouldIgnoreMissing(); + // set logger mock to $logger variable in class under test + $property = $reflection->getProperty('logger'); + $property->setAccessible(true); + $property->setValue($adler_score, $logger_mock); // call method try { @@ -338,6 +348,14 @@ public function test_get_score_for_h5p_learning_element() { $property->setAccessible(true); $property->setValue($adler_score, $this->user->id); + // mock logger as it does not exist because constructor is not executed + $logger_mock = Mockery::mock(Logger::class); + // ignore all method calls on mock + $logger_mock->shouldIgnoreMissing(); + // set logger mock to $logger variable in class under test + $property = $reflection->getProperty('logger'); + $property->setAccessible(true); + $property->setValue($adler_score, $logger_mock); // test no attempt // call method