Skip to content

Commit b3b6b0b

Browse files
authored
PHPLIB-816: Cleanup collections created when tests are successful (#1075)
- Update FunctionalTestCase::createCollection and FunctionalTestCase::dropCollection to accept a different database and collection name. - Remove automatically the collections created or dropped using this helper methods. - Use this methods when possible.
1 parent 7b463d7 commit b3b6b0b

16 files changed

+116
-168
lines changed

tests/Collection/CollectionFunctionalTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public function testAggregateWithinTransaction(): void
114114
$this->skipIfTransactionsAreNotSupported();
115115

116116
// Collection must be created before the transaction starts
117-
$this->createCollection();
117+
$this->createCollection($this->getDatabaseName(), $this->getCollectionName());
118118

119119
$session = $this->manager->startSession();
120120
$session->startTransaction();
@@ -294,7 +294,7 @@ public function testFindWithinTransaction(): void
294294
$this->skipIfTransactionsAreNotSupported();
295295

296296
// Collection must be created before the transaction starts
297-
$this->createCollection();
297+
$this->createCollection($this->getDatabaseName(), $this->getCollectionName());
298298

299299
$session = $this->manager->startSession();
300300
$session->startTransaction();
@@ -727,7 +727,7 @@ public function testMethodDoesNotInheritReadWriteConcernInTranasaction(Closure $
727727
{
728728
$this->skipIfTransactionsAreNotSupported();
729729

730-
$this->createCollection();
730+
$this->createCollection($this->getDatabaseName(), $this->getCollectionName());
731731

732732
$session = $this->manager->startSession();
733733
$session->startTransaction();
@@ -753,7 +753,7 @@ public function testMethodInTransactionWithWriteConcernOption($method): void
753753
{
754754
$this->skipIfTransactionsAreNotSupported();
755755

756-
$this->createCollection();
756+
$this->createCollection($this->getDatabaseName(), $this->getCollectionName());
757757

758758
$session = $this->manager->startSession();
759759
$session->startTransaction();
@@ -773,7 +773,7 @@ public function testMethodInTransactionWithReadConcernOption($method): void
773773
{
774774
$this->skipIfTransactionsAreNotSupported();
775775

776-
$this->createCollection();
776+
$this->createCollection($this->getDatabaseName(), $this->getCollectionName());
777777

778778
$session = $this->manager->startSession();
779779
$session->startTransaction();

tests/Collection/CrudSpecFunctionalTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ public function setUp(): void
4848
{
4949
parent::setUp();
5050

51-
$this->expectedCollection = new Collection($this->manager, $this->getDatabaseName(), $this->getCollectionName() . '.expected');
52-
$this->expectedCollection->drop();
51+
$this->expectedCollection = $this->dropCollection($this->getDatabaseName(), $this->getCollectionName() . '.expected');
5352
}
5453

5554
/** @dataProvider provideSpecificationTests */

tests/Collection/FunctionalTestCase.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,6 @@ public function setUp(): void
1717
{
1818
parent::setUp();
1919

20-
$this->collection = new Collection($this->manager, $this->getDatabaseName(), $this->getCollectionName());
21-
22-
$this->dropCollection();
23-
}
24-
25-
public function tearDown(): void
26-
{
27-
if (! $this->hasFailed()) {
28-
$this->dropCollection();
29-
}
30-
31-
parent::tearDown();
20+
$this->collection = $this->dropCollection($this->getDatabaseName(), $this->getCollectionName());
3221
}
3322
}

0 commit comments

Comments
 (0)