@@ -954,9 +954,8 @@ public function testChangeStreamExample_1_4(): void
954
954
$ this ->markTestSkipped ('Test does not apply on sharded clusters: need more than a single getMore call on the change stream. ' );
955
955
}
956
956
957
- $ this ->dropCollection ($ this ->getDatabaseName (), 'inventory ' );
957
+ $ this ->createCollection ($ this ->getDatabaseName (), 'inventory ' );
958
958
$ db = new Database ($ this ->manager , $ this ->getDatabaseName ());
959
- $ db ->createCollection ('inventory ' );
960
959
961
960
// Start Changestream Example 1
962
961
$ changeStream = $ db ->inventory ->watch ();
@@ -1190,9 +1189,8 @@ public function testRunCommand_example_1(): void
1190
1189
1191
1190
public function testRunCommand_example_2 (): void
1192
1191
{
1193
- $ this ->dropCollection ($ this ->getDatabaseName (), 'restaurants ' );
1192
+ $ this ->createCollection ($ this ->getDatabaseName (), 'restaurants ' );
1194
1193
$ db = new Database ($ this ->manager , $ this ->getDatabaseName ());
1195
- $ db ->createCollection ('restaurants ' );
1196
1194
1197
1195
// Start runCommand Example 2
1198
1196
$ cursor = $ db ->command (['collStats ' => 'restaurants ' ]);
@@ -1291,9 +1289,6 @@ public function testTransactions_intro_example_1(): void
1291
1289
1292
1290
$ client = static ::createTestClient ();
1293
1291
1294
- $ this ->dropCollection ('hr ' , 'employees ' );
1295
- $ this ->dropCollection ('reporting ' , 'events ' );
1296
-
1297
1292
/* Collections need to be created before a transaction starts */
1298
1293
$ this ->createCollection ('hr ' , 'employees ' );
1299
1294
$ this ->createCollection ('reporting ' , 'events ' );
@@ -1470,9 +1465,6 @@ public function testTransactions_retry_example_3(): void
1470
1465
1471
1466
$ client = static ::createTestClient ();
1472
1467
1473
- $ this ->dropCollection ('hr ' , 'employees ' );
1474
- $ this ->dropCollection ('reporting ' , 'events ' );
1475
-
1476
1468
/* Collections need to be created before a transaction starts */
1477
1469
$ this ->createCollection ('hr ' , 'employees ' );
1478
1470
$ this ->createCollection ('reporting ' , 'events ' );
@@ -1492,12 +1484,8 @@ public function testCausalConsistency(): void
1492
1484
$ this ->assertNotNull ('This test intentionally performs no assertions ' );
1493
1485
1494
1486
// Prep
1495
- $ this ->dropCollection ('test ' , 'items ' );
1496
1487
$ client = static ::createTestClient ();
1497
- $ items = $ client ->selectDatabase (
1498
- 'test ' ,
1499
- ['writeConcern ' => new WriteConcern (WriteConcern::MAJORITY )]
1500
- )->items ;
1488
+ $ items = $ this ->createCollection ('test ' , 'items ' );
1501
1489
$ items ->insertOne (
1502
1490
['sku ' => '111 ' , 'name ' => 'Peanuts ' , 'start ' => new UTCDateTime ()]
1503
1491
);
@@ -1866,17 +1854,16 @@ public function testQueryableEncryption(): void
1866
1854
$ this ->markTestSkipped ('Automatic encryption requires MongoDB Enterprise ' );
1867
1855
}
1868
1856
1857
+ // Ensure the collection is dropped by tearDown()
1869
1858
$ this ->dropCollection ($ this ->getDatabaseName (), $ this ->getCollectionName ());
1870
1859
1871
1860
// Fetch names for the database and collection under test
1872
1861
$ collectionName = $ this ->getCollectionName ();
1873
1862
$ databaseName = $ this ->getDatabaseName ();
1874
1863
$ namespace = $ this ->getNamespace ();
1875
1864
1876
- /* Create a client without auto encryption. Drop existing data in both
1877
- * the keyvault and database under test. The latter is necessary since
1878
- * setUp() only drops the collection under test, which will leave behind
1879
- * internal collections for queryable encryption. */
1865
+ /* Create a client without auto encryption. Drop existing data in both the keyvault and database under test.
1866
+ * The latter is necessary to clean up any internal collections for queryable encryption. */
1880
1867
$ client = static ::createTestClient ();
1881
1868
$ client ->selectDatabase ('keyvault ' )->drop (['writeConcern ' => new WriteConcern (WriteConcern::MAJORITY )]);
1882
1869
$ client ->selectDatabase ($ databaseName )->drop (['writeConcern ' => new WriteConcern (WriteConcern::MAJORITY )]);
0 commit comments