Skip to content

Commit 5f210b9

Browse files
committed
Apply writeconcern only on create/drop operations
1 parent 55d2aa9 commit 5f210b9

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

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->dropCollection($this->getDatabaseName(), $this->getCollectionName() . '.expected');
52-
$this->expectedCollection = new Collection($this->manager, $this->getDatabaseName(), $this->getCollectionName() . '.expected');
51+
$this->expectedCollection = $this->dropCollection($this->getDatabaseName(), $this->getCollectionName() . '.expected');
5352
}
5453

5554
/** @dataProvider provideSpecificationTests */

tests/FunctionalTestCase.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,12 +269,13 @@ public static function getModuleInfo(string $row): ?string
269269
*/
270270
protected function createCollection(string $databaseName, string $collectionName, array $options = []): Collection
271271
{
272-
$collection = $this->dropCollection($databaseName, $collectionName, $options);
273-
274272
if (isset($options['encryptedFields'])) {
275273
throw new InvalidArgumentException('The "encryptedFields" option is not supported by createCollection(). Time to refactor!');
276274
}
277275

276+
$collection = $this->dropCollection($databaseName, $collectionName, $options);
277+
278+
$options += ['writeConcern' => new WriteConcern(WriteConcern::MAJORITY)];
278279
$operation = new CreateCollection($databaseName, $collectionName, $options);
279280
$operation->execute($this->getPrimaryServer());
280281

@@ -290,18 +291,19 @@ protected function createCollection(string $databaseName, string $collectionName
290291
*/
291292
protected function dropCollection(string $databaseName, string $collectionName, array $options = []): Collection
292293
{
293-
$options += ['writeConcern' => new WriteConcern(WriteConcern::MAJORITY)];
294294
$collection = new Collection($this->manager, $databaseName, $collectionName, $options);
295-
$collection->drop();
296-
297295
$this->collectionsToCleanup[] = [$collection, $options];
298296

297+
$options += ['writeConcern' => new WriteConcern(WriteConcern::MAJORITY)];
298+
$collection->drop($options);
299+
299300
return $collection;
300301
}
301302

302303
private function cleanupCollections(): void
303304
{
304305
foreach ($this->collectionsToCleanup as [$collection, $options]) {
306+
$options += ['writeConcern' => new WriteConcern(WriteConcern::MAJORITY)];
305307
$collection->drop($options);
306308
}
307309

0 commit comments

Comments
 (0)