Skip to content

Commit

Permalink
refactor exception checking to be compatible with upcoming Moodle 4.5…
Browse files Browse the repository at this point in the history
… refactorings
  • Loading branch information
Glutamat42 committed Sep 4, 2024
1 parent 7dec1b6 commit 7941d7e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions tests/adler_score_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace local_adler;


use cm_info;
use completion_info;
use grade_item;
use local_adler\lib\adler_testcase;
Expand Down Expand Up @@ -44,6 +45,7 @@ class adler_score_test extends adler_testcase {
private stdClass $course;
private stdClass $module;
private stdClass $user;
private cm_info $url_module_cm_info;

public function setUp(): void {
parent::setUp();
Expand Down Expand Up @@ -167,7 +169,7 @@ public function test_construct($test) {
try {
$result = new adler_score_mock($test['course_module_param'], $test['user_param']);
} catch (Throwable $e) {
$this->assertEquals($test['expect_exception'], get_class($e));
$this->assertStringContainsString($test['expect_exception'], get_class($e));
if ($test['expect_exception_message'] !== null) {
$this->assertStringContainsString($test['expect_exception_message'], $e->getMessage());
}
Expand Down Expand Up @@ -262,7 +264,7 @@ public function test_get_primitive_score(bool $completion_enabled_cm, bool $comp
try {
$result = $adler_score->get_score_by_completion_state();
} catch (Throwable $e) {
$this->assertEquals($expect_exception, get_class($e));
$this->assertStringContainsString($expect_exception, get_class($e));
if ($expect_exception_message !== null) {
$this->assertStringContainsString($expect_exception_message, $e->getMessage());
}
Expand Down
2 changes: 1 addition & 1 deletion tests/external/score_get_element_scores_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public function test_execute_exceptions() {
try {
score_get_element_scores_mock::execute($params[$i]);
} catch (Throwable $e) {
$this->assertEquals($expectExceptions[$i][0], get_class($e), '$i = ' . $i);
$this->assertStringContainsString($expectExceptions[$i][0], get_class($e), '$i = ' . $i);
$this->assertStringContainsString($expectExceptions[$i][1], $e->errorcode, '$i = ' . $i);
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function test_is_primitive_learning_element($data) {

// check result
if ($data['type'] == 'wrong_format') {
$this->assertEquals(moodle_exception::class, get_class($exception));
$this->assertStringContainsString(moodle_exception::class, get_class($exception));
} else if ($exception != null) {
$this->fail('Unexpected exception: ' . $exception->getMessage());
}
Expand Down

0 comments on commit 7941d7e

Please sign in to comment.