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.
This commit is contained in:
shimon committed 2025-09-11 16:18:43 +03:00
1 parent eebbd5bef4
commit a582d06621
1 file changed
+4 -3
+4 -3
View File
@@ -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);
}
}
}