MDL-68780 unit tests: Add missing ->destroy() calls to controllers
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Tue, 19 May 2020 21:48:13 +0000 (23:48 +0200)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Wed, 20 May 2020 09:02:00 +0000 (11:02 +0200)
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

index c27ccf2..fffcd16 100644 (file)
@@ -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.