MDL-84967 analytics: close recordset when it's not needed anymore
Signed-off-by: Daniel Ziegenberg <[email protected]>
This commit is contained in:
@@ -53,6 +53,7 @@ abstract class by_course extends base {
|
||||
|
||||
if (!$recordset->valid()) {
|
||||
$this->add_log(get_string('nocourses', 'analytics'));
|
||||
$recordset->close();
|
||||
return new \ArrayIterator([]);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
namespace core;
|
||||
|
||||
use core\context\coursecat;
|
||||
use test_target_course_level_shortname;
|
||||
use test_target_shortname;
|
||||
|
||||
@@ -32,6 +33,8 @@ require_once(__DIR__ . '/../../lib/enrollib.php');
|
||||
* @category test
|
||||
* @copyright 2017 David Monllaó {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*
|
||||
* @covers \core\analytics\analyser\courses
|
||||
*/
|
||||
final class analysers_test extends \advanced_testcase {
|
||||
|
||||
@@ -81,6 +84,24 @@ final class analysers_test extends \advanced_testcase {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test analyser iterator status with invalid course data.
|
||||
*/
|
||||
public function test_no_courses_analyser(): void {
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
$target = new test_target_shortname();
|
||||
$analyser = new \core\analytics\analyser\courses(1, $target, [], [], []);
|
||||
|
||||
$category = $this->getDataGenerator()->create_category();
|
||||
$categorycontext = coursecat::instance($category->id);
|
||||
|
||||
// No courses.
|
||||
$this->assertCount(0, $analyser->get_analysables_iterator(null, [$categorycontext]));
|
||||
$this->assertCount(1, $analyser->get_logs());
|
||||
$this->assertEquals(get_string('nocourses', 'analytics'), $analyser->get_logs()[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* test_site_courses_analyser
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user