Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Glutamat42 committed Jan 17, 2024
1 parent ba00d3e commit 102c316
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/adler_score_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 102c316

Please sign in to comment.