Skip to content

Commit bd148ea

Browse files
committed
Merge pull request #567
2 parents 798d510 + 330161a commit bd148ea

File tree

3 files changed

+38
-14
lines changed

3 files changed

+38
-14
lines changed

tests/Collection/FunctionalTestCase.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace MongoDB\Tests\Collection;
44

55
use MongoDB\Collection;
6-
use MongoDB\Operation\DropCollection;
6+
use MongoDB\Driver\WriteConcern;
77
use MongoDB\Tests\FunctionalTestCase as BaseFunctionalTestCase;
88

99
/**
@@ -18,8 +18,8 @@ public function setUp()
1818
parent::setUp();
1919

2020
$this->collection = new Collection($this->manager, $this->getDatabaseName(), $this->getCollectionName());
21-
$operation = new DropCollection($this->getDatabaseName(), $this->getCollectionName());
22-
$operation->execute($this->getPrimaryServer());
21+
22+
$this->dropCollection();
2323
}
2424

2525
public function tearDown()
@@ -28,7 +28,15 @@ public function tearDown()
2828
return;
2929
}
3030

31-
$operation = new DropCollection($this->getDatabaseName(), $this->getCollectionName());
32-
$operation->execute($this->getPrimaryServer());
31+
$this->dropCollection();
32+
}
33+
34+
private function dropCollection()
35+
{
36+
$options = version_compare($this->getServerVersion(), '3.4.0', '>=')
37+
? ['writeConcern' => new WriteConcern(WriteConcern::MAJORITY)]
38+
: [];
39+
40+
$this->collection->drop($options);
3341
}
3442
}

tests/DocumentationExamplesTest.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
use MongoDB\Database;
77
use MongoDB\Driver\Cursor;
88
use MongoDB\Driver\Server;
9+
use MongoDB\Driver\WriteConcern;
910
use MongoDB\Operation\DropCollection;
10-
use MongoDB\Operation\DropDatabase;
1111

1212
/**
1313
* Documentation examples to be parsed for inclusion in the MongoDB manual.
@@ -20,8 +20,7 @@ public function setUp()
2020
{
2121
parent::setUp();
2222

23-
$operation = new DropCollection($this->getDatabaseName(), $this->getCollectionName());
24-
$operation->execute($this->getPrimaryServer());
23+
$this->dropCollection();
2524
}
2625

2726
public function tearDown()
@@ -30,8 +29,7 @@ public function tearDown()
3029
return;
3130
}
3231

33-
$operation = new DropCollection($this->getDatabaseName(), $this->getCollectionName());
34-
$operation->execute($this->getPrimaryServer());
32+
$this->dropCollection();
3533
}
3634

3735
public function testExample_1_2()
@@ -1429,4 +1427,14 @@ private function assertInventoryCount($count)
14291427
{
14301428
$this->assertCollectionCount($this->getDatabaseName() . '.' . $this->getCollectionName(), $count);
14311429
}
1430+
1431+
private function dropCollection()
1432+
{
1433+
$options = version_compare($this->getServerVersion(), '3.4.0', '>=')
1434+
? ['writeConcern' => new WriteConcern(WriteConcern::MAJORITY)]
1435+
: [];
1436+
1437+
$operation = new DropCollection($this->getDatabaseName(), $this->getCollectionName(), $options);
1438+
$operation->execute($this->getPrimaryServer());
1439+
}
14321440
}

tests/Operation/FunctionalTestCase.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ public function setUp()
1818
{
1919
parent::setUp();
2020

21-
$operation = new DropCollection($this->getDatabaseName(), $this->getCollectionName());
22-
$operation->execute($this->getPrimaryServer());
21+
$this->dropCollection();
2322
}
2423

2524
public function tearDown()
@@ -28,8 +27,7 @@ public function tearDown()
2827
return;
2928
}
3029

31-
$operation = new DropCollection($this->getDatabaseName(), $this->getCollectionName());
32-
$operation->execute($this->getPrimaryServer());
30+
$this->dropCollection();
3331
}
3432

3533
protected function createDefaultReadConcern()
@@ -46,4 +44,14 @@ protected function createSession()
4644
{
4745
return $this->manager->startSession();
4846
}
47+
48+
private function dropCollection()
49+
{
50+
$options = version_compare($this->getServerVersion(), '3.4.0', '>=')
51+
? ['writeConcern' => new WriteConcern(WriteConcern::MAJORITY)]
52+
: [];
53+
54+
$operation = new DropCollection($this->getDatabaseName(), $this->getCollectionName(), $options);
55+
$operation->execute($this->getPrimaryServer());
56+
}
4957
}

0 commit comments

Comments
 (0)