From a582d06621b70586b691e56ae39caa7a7e8bd393 Mon Sep 17 00:00:00 2001 From: shimon Date: Thu, 11 Sep 2025 16:18:43 +0300 Subject: [PATCH] Refactor MongoTest to ensure collection cleanup with try-finally block This commit modifies the MongoTest class to wrap the collection drop operation in a try-finally block, ensuring that the collection is always dropped after the test execution, even if an exception occurs during the test. This enhances the reliability of the test environment. --- tests/MongoTest.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/MongoTest.php b/tests/MongoTest.php index 60837a4997..61b62210cb 100644 --- a/tests/MongoTest.php +++ b/tests/MongoTest.php @@ -266,7 +266,7 @@ class MongoTest extends TestCase { $collectionName = 'count_test'; $this->getDatabase()->createCollection($collectionName); - + try { $documents = []; for ($i = 1; $i <= 30; $i++) { $documents[] = [ @@ -347,7 +347,8 @@ class MongoTest extends TestCase ]); self::assertEquals(6, $complexOrAggregationResult->cursor->firstBatch[0]->total); - - $this->getDatabase()->dropCollection($collectionName); + } finally { + $this->getDatabase()->dropCollection($collectionName); + } } }