From 5b188629c7f001ad8207c374a875bf50d86abd85 Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Tue, 19 May 2020 23:48:13 +0200 Subject: [PATCH] MDL-68780 unit tests: Add missing ->destroy() calls to controllers Every backup and restore controller always need to call to their ->destroy() method in charge of finalizing loggers, closing file handlers and destroy some circular references. This is specially important within unit tests, because open resources cannot be reset between tests, causing problems, specially within Windows that locks all those files. --- backup/util/helper/tests/async_helper_test.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/backup/util/helper/tests/async_helper_test.php b/backup/util/helper/tests/async_helper_test.php index c27ccf2caa9..fffcd168f7d 100644 --- a/backup/util/helper/tests/async_helper_test.php +++ b/backup/util/helper/tests/async_helper_test.php @@ -161,6 +161,7 @@ class core_backup_async_helper_testcase extends \core_privacy\tests\provider_tes $bc = new \backup_controller(\backup::TYPE_1COURSE, $course->id, \backup::FORMAT_MOODLE, \backup::INTERACTIVE_NO, \backup::MODE_COPY, $USER->id, \backup::RELEASESESSION_YES); $backupid = $bc->get_backupid(); + $bc->destroy(); $copyrec = \async_helper::get_backup_record($backupid); $this->assertEquals($backupid, $copyrec->backupid); @@ -185,8 +186,9 @@ class core_backup_async_helper_testcase extends \core_privacy\tests\provider_tes $this->assertFalse($ispending); // Create the initial backupcontoller. - new \backup_controller(\backup::TYPE_1COURSE, $course->id, \backup::FORMAT_MOODLE, + $bc = new \backup_controller(\backup::TYPE_1COURSE, $course->id, \backup::FORMAT_MOODLE, \backup::INTERACTIVE_NO, \backup::MODE_ASYNC, $USER->id, \backup::RELEASESESSION_YES); + $bc->destroy(); $ispending = async_helper::is_async_pending($course->id, 'course', 'backup'); // Should be false as there as async backup is false. @@ -215,8 +217,9 @@ class core_backup_async_helper_testcase extends \core_privacy\tests\provider_tes $this->assertFalse($ispending); // Create the initial backupcontoller. - new \backup_controller(\backup::TYPE_1COURSE, $course->id, \backup::FORMAT_MOODLE, + $bc = new \backup_controller(\backup::TYPE_1COURSE, $course->id, \backup::FORMAT_MOODLE, \backup::INTERACTIVE_NO, \backup::MODE_COPY, $USER->id, \backup::RELEASESESSION_YES); + $bc->destroy(); $ispending = async_helper::is_async_pending($course->id, 'course', 'backup'); // Should be True as this a copy operation. -- 2.43.0