MDL-41256 course tests: improve robustness
authorDan Poltawski <dan@moodle.com>
Tue, 3 Sep 2013 02:59:51 +0000 (10:59 +0800)
committerDan Poltawski <dan@moodle.com>
Tue, 3 Sep 2013 03:01:15 +0000 (11:01 +0800)
* Fail if an exception isn't recieved
* Don't allow the possibility of an undefined variable being tested

course/tests/courselib_test.php

index eb1eab1..4c42b9f 100644 (file)
@@ -606,19 +606,19 @@ class core_course_courselib_testcase extends advanced_testcase {
         // Ensure that the shortname isn't duplicated.
         try {
             $created = create_course($course);
+            $this->fail('Exception expected');
         } catch (moodle_exception $e) {
-            $message = $e->getMessage();
+            $this->assertSame(get_string('shortnametaken', 'error', $course->shortname), $e->getMessage());
         }
-        $this->assertEquals($message, get_string('shortnametaken', 'error', $course->shortname));
 
         // Ensure that the idnumber isn't duplicated.
         $course->shortname .= '1';
         try {
             $created = create_course($course);
+            $this->fail('Exception expected');
         } catch (moodle_exception $e) {
-            $message = $e->getMessage();
+            $this->assertSame(get_string('courseidnumbertaken', 'error', $course->idnumber), $e->getMessage());
         }
-        $this->assertEquals($message, get_string('courseidnumbertaken', 'error', $course->idnumber));
     }
 
     public function test_create_course_with_generator() {