From ccb2484c4b4d6fd04702a4032462340bb1c73615 Mon Sep 17 00:00:00 2001 From: kristian-94 <37063983+kristian-94@users.noreply.github.com> Date: Mon, 2 Nov 2020 10:37:51 +1100 Subject: [PATCH] Issue496 - mod_attendance_generator should return stdClass - fix unit tests in 3.9 (#499) * mod_attendance_generator should return stdClass - fix unit tests #496 * Fix travis by decalaring void return from setUp function --- tests/externallib_test.php | 16 ++++++++++++---- tests/generator/lib.php | 6 +----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/tests/externallib_test.php b/tests/externallib_test.php index 18d23f7..e7262e8 100644 --- a/tests/externallib_test.php +++ b/tests/externallib_test.php @@ -42,7 +42,7 @@ require_once($CFG->dirroot . '/mod/attendance/externallib.php'); * @group mod_attendance */ class mod_attendance_external_testcase extends externallib_advanced_testcase { - /** @var coursecat */ + /** @var core_course_category */ protected $category; /** @var stdClass */ protected $course; @@ -58,10 +58,14 @@ class mod_attendance_external_testcase extends externallib_advanced_testcase { /** * Setup class. */ - public function setUp() { + public function setUp(): void { + global $DB; $this->category = $this->getDataGenerator()->create_category(); $this->course = $this->getDataGenerator()->create_course(array('category' => $this->category->id)); - $this->attendance = $this->getDataGenerator()->create_module('attendance', array('course' => $this->course->id)); + $att = $this->getDataGenerator()->create_module('attendance', array('course' => $this->course->id)); + $cm = $DB->get_record('course_modules', array('id' => $att->cmid), '*', MUST_EXIST); + $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); + $this->attendance = new mod_attendance_structure($att, $cm, $course); $this->create_and_enrol_users(); @@ -114,10 +118,14 @@ class mod_attendance_external_testcase extends externallib_advanced_testcase { } public function test_get_courses_with_today_sessions_multiple_instances() { + global $DB; $this->resetAfterTest(true); // Make another attendance. - $second = $this->getDataGenerator()->create_module('attendance', array('course' => $this->course->id)); + $att = $this->getDataGenerator()->create_module('attendance', array('course' => $this->course->id)); + $cm = $DB->get_record('course_modules', array('id' => $att->cmid), '*', MUST_EXIST); + $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); + $second = new mod_attendance_structure($att, $cm, $course); // Just add the same session. $secondsession = clone $this->sessions[0]; diff --git a/tests/generator/lib.php b/tests/generator/lib.php index 674753d..b69a0a0 100644 --- a/tests/generator/lib.php +++ b/tests/generator/lib.php @@ -62,10 +62,6 @@ class mod_attendance_generator extends testing_module_generator { $record->grade = 100; } - $att = parent::create_instance($record, (array)$options); - $cm = $DB->get_record('course_modules', array('id' => $att->cmid), '*', MUST_EXIST); - $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); - - return new mod_attendance_structure($att, $cm, $course); + return parent::create_instance($record, (array)$options); } }