From 48d0230a96f57995cab4724fb63d6105df7109a8 Mon Sep 17 00:00:00 2001 From: Magdalena Holczik Date: Thu, 5 Dec 2024 15:43:40 +0100 Subject: [PATCH] Bugfix: Correct tear down for complete instance --- classes/singleton_service.php | 10 ++++++++++ tests/bo_availability/condition_all_test.php | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/classes/singleton_service.php b/classes/singleton_service.php index c957a9579..f4b34c670 100644 --- a/classes/singleton_service.php +++ b/classes/singleton_service.php @@ -808,4 +808,14 @@ public static function get_all_booking_instances() { return $instance->allbookinginstances; } + + /** + * Destroys the singleton entirely. + * + * @return bool + */ + public static function destroy_instance() { + self::$instance = null; + return true; + } } diff --git a/tests/bo_availability/condition_all_test.php b/tests/bo_availability/condition_all_test.php index e828a42ac..548bf2f5b 100644 --- a/tests/bo_availability/condition_all_test.php +++ b/tests/bo_availability/condition_all_test.php @@ -1496,6 +1496,7 @@ public function test_booking_bookit_overlapping(array $bdata): void { */ public function test_booking_bookit_overlapping_sessions(array $bdata): void { global $DB, $CFG; + $this->tearDown(); // Setup test data. $course = $this->getDataGenerator()->create_course(['enablecompletion' => 1]); @@ -1624,4 +1625,13 @@ public static function booking_common_settings_provider(): array { ]; return ['bdata' => [$bdata]]; } + + /** + * Mandatory clean-up after each test. + */ + public function tearDown(): void { + parent::tearDown(); + // Mandatory clean-up. + singleton_service::destroy_instance(); + } }