From 892fa580b2a3f2627d7f1ae2a51453d7348aedb2 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Wed, 1 Dec 2021 12:54:32 +0000 Subject: [PATCH] MDL-69700 tests: clarify expected exceptions in unit tests. Resolves some leftovers from MDL-67673, see d95c3787. --- competency/tests/external_test.php | 6 ++---- lib/tests/exporter_test.php | 11 ++++------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/competency/tests/external_test.php b/competency/tests/external_test.php index 9f2abd1c78b..c7755d7f2af 100644 --- a/competency/tests/external_test.php +++ b/competency/tests/external_test.php @@ -826,12 +826,10 @@ class core_competency_external_testcase extends externallib_advanced_testcase { 'competencyframeworkid' => $framework->id, 'sortorder' => 0 ); - // TODO: MDL-69700 - Analyse if the throw exception is happening - // in the correct place and decide what happens with the trailing - // code that is never executed. + $this->expectException(invalid_parameter_exception::class); + $this->expectExceptionMessage('Invalid external api parameter'); $result = external::create_competency($competency); - $result = (object) external_api::clean_returnvalue(external::create_competency_returns(), $result); } /** diff --git a/lib/tests/exporter_test.php b/lib/tests/exporter_test.php index 80b19a2e46a..8949c231831 100644 --- a/lib/tests/exporter_test.php +++ b/lib/tests/exporter_test.php @@ -103,20 +103,17 @@ class core_exporter_testcase extends advanced_testcase { $exporter = new core_testable_exporter($this->invaliddata, $this->validrelated); $output = $PAGE->get_renderer('core'); + // The exception message is a bit misleading, it actually indicates an expected property wasn't found. $this->expectException(coding_exception::class); + $this->expectExceptionMessage('Unexpected property stringAformat'); $result = $exporter->export($output); } public function test_invalid_related() { - global $PAGE; - // TODO: MDL-69700 - Analyse if the throw exception is happening - // in the correct place and decide what happens with the trailing - // code that is never executed. $this->expectException(coding_exception::class); + $this->expectExceptionMessage('Exporter class is missing required related data: (core_testable_exporter) ' . + 'simplestdClass => stdClass'); $exporter = new core_testable_exporter($this->validdata, $this->invalidrelated); - $output = $PAGE->get_renderer('core'); - - $result = $exporter->export($output); } public function test_invalid_related_all_cases() {